My Projects > Wordle on Mbed

Wordle on Mbed

Technologies Used: C, Mbed Microcontroller, Breadboard Circuitry, I/O Components

Project Summary:

This project was an individual project for ECE 2035 - Programming for Hardware and Software Systems. We were tasked with implementing the famous game of Wordle on an Mbed microcontroller and utilizing different breadboard components for user inputs. So far, I've completed one iteration with some basic functionality, and I'm currently working on another iteration to build off my first one.

Iteration #1:

In this version of the game, I had a start screen, instructions, and a game screen. During the game, the user is met with two lightning bolts as they try to guess a randomly generated 5-letter word in 6 tries. For each guess, correct letters in the right place are highlighted in green, and correct letters in the wrong place are highlighted in red. Letters that aren't in the word disappear from the keyboard and the user cannot select them again. To select a letter, the user tilts the microcontroller to scroll through letters on the bottom of the screen, utilizing an accelerometer that connects to the Mbed. To select a letter or check their guess, the user presses buttons that are also connected to the Mbed. If the user wins, the lightning bolts change to flowers as they overcome the challenge. If they lose, the lightning bolts remain in place and the user is met with a GAME OVER message.

This was all implemented in C. Mbed uses C++, however, we used C and compiled it using Mbed's C++ compiler. The components used in this project such as the LCD screen, accelerometer, and pushbuttons all have specific API for Mbed which I had to research and properly implement in my code.

There are many parts to this code, and it boils down to a few main files: main.cpp, keyboard.cpp, graphics.cpp, hardware.cpp, and a Doubly Linked List we wrote, doubly_linked_list.cpp.

Main.cpp: This file has all of the game initializations, which initializes the keyboard, seeds the random number generator needed to produce a random word, calls functions to display sprites and screens, and, most importantly, hosts the game loop. This game loop constantly runs, and checks on inputs to the microcontroller and calls functions to change the game state based on those inputs.

Graphics.cpp: This file has all of the data for the sprites used in the game. The sprites are designed on piskelapp.com, which allows me to draw a sprite and export that data in a C array. That data is in this file and is called by main to display on the screen.

doubly_linked_list.cpp: This file contains a doubly linked list data structure that we had to implement ourselves. This has the ability to create a list, create a node, add a node in front of a specified node, add a node behind a specified node, add to the head of a list, add to the tail of a list, destroy a node, destroy a list, reverse a list, and get data from a node. It can also return the head of a list, tail of a list, size of a list, and next/previous pointers for a node.

keyboard.cpp: Using my doubly linked list, this file creates a keyboard where each letter is a node in the list. This file also has functions to scroll left and right on the list and display it on the screen, and functions to check a word to see if it's right and to delete a letter a user places in their guess.

hardware.cpp: This file contains definitions for the I/O devices used: LCD screen, accelerometer, and pushbuttons. It has a function, read_inputs() which returns the status of these devices in a struct called GameInputs.

All of these functions were programmed by me and integrated together to produce my first iteration of the game. The entire code cannot be distributed as per the Georgia Tech academic honesty policy, so below I have a sample of some of the code I wrote in the main game loop.

From here, there was a lot more improvement that could be added to the game. For example, once the game was over, there was no way to restart the game. The game's art was also pretty basic, with only a few sprites. I also saw ways to make the game more creative by adding different difficulty modes.

Iteration #2:

For my second iteration, I included additional functionalities to enhance the game. I created a more interactive start screen, where users can select one of three modes: normal, hard, and expert. Normal mode is the traditional wordle game, where players have 6 guesses to guess a 5 letter word. I also included a timer on the top so players can see how fast they solve the wordle. Hard mode is like the normal mode, but this time players have 5 guesses for a 6 letter word. A timer is included here as well. Expert mode is like hard mode with 5 guesses for a 6 letter word, only now there is a 3 minute time constraint. If the user cannot guess the word by then, they lose. After the player wins or loses, they can now also restart the game and play with a new word. For each mode, their fastest time is also displayed on the top of the screen as a high score.

I also put more time into making the game look better. I included more sprites: one for every guess, as well as a game over losing sprite. I also added sprites on the game selection screen for each mode.

For the programming implementation of this, I had to add more functions and variables. To conserve as much code as possible, I used the same logic I did for my basic functionality, only I also added a "hard" variable, which is set to 1 when the mode is hard or expert, and 0 for normal mode. With this variable, I changed the variable I had to store the number of guesses from '6' to '6 - hard' and the variable for the number of letters from '5' to '5 + hard'. This optimization allowed me to not need to rewrite several lines of code, but simply add a parameter to my game functions. I also added a playagain() function which is called when the game is over, which resets the keyboard, saves high score data, displays the high score on the screen, and waits for an input to send the user back to the start screen.

This project allowed me to apply what I've learned in C to a fun application on an Mbed microcontroller. I learned a lot about programming games, operating microcontrollers, reading documentation, and iterating on existing designs.

Here is the final demo of my game working: