Course:CPSC312-2023/Wordle

From UBC Wiki

What is the problem?

We want to emulate the Wordle game (https://www.nytimes.com/games/wordle/index.html) using Haskell.

The Wordle game will be played in the terminal. Similar to the official game, the player will attempt to guess a 5-letter word six times.


After each guess, our game will print something like below:

player> crane

crane | x✓✓xo


A `✓` indicates that a letter is in the correct place, an `o` indicates that a letter exists in the word but is in the wrong place, and an `x` indicates that a letter is not found in the word.

The game continues until the player successfully guesses the word, or runs out of guesses. Once the game finishes, the player can choose to restart the game with a different word.

What is the something extra?

Unlike the official NYTimes Wordle game, we will offer hints to the player.

Our game is initialized with a file of 5-letter words from which the game chooses a random word for the player to guess. If the player requests a hint, the game will list a list of all words from the word bank which satisfies the player's previous guesses.

What did we learn from doing this?

Kate:

I felt that using Haskell to code a game in Wordle was interesting. Due to Haskell's functional nature, I found that I had to use many work-arounds to evaluate the player's guess word to the actual word, work-arounds that I could've avoided with imperative programming. In particular, Haskell's guarantee of having no side effects is useful for debugging and reasoning, but because we have to randomly choose a word from the word bank at the start, we were required to work with and write IO functions.

I do find Haskell's data types to be useful, as trying to implement Wordle in an object-oriented language would require creating a lot of classes (e.g. CharacterMatch (indicating if a letter is in the correct position in the guess word or not), Guess, State, etc).

We had to use Haskell libraries such as System.Random and Data.Map. We used cabal as our package manager which kept our project maintainable and organized. Reading documentation for using the libraries also reinforced our understanding of Haskell types and data definitions.

James:

Haskell programming requires a very different mindset from the imperative programming languages we are used to. Although Haskell is very powerful, it seems that making games is much easier with an imperative language. As another group have pointed out in their page, making a Wordle game with Python cost roughly 6.67% of the time spent with Haskell, and I found myself frequently conceiving a feature in C++ and then converting the result to Haskell.

Links to code etc

https://github.students.cs.ubc.ca/khuang04/cpsc312-haskell