Course:CPSC312-2023/Wordle with Multiple Words

From UBC Wiki

Authors: Aaron, Bernie

What is the problem?

We will be implementing the game Wordle in Haskell with a command line interface. The rules of Wordle are as follows:

  • The goal of the game is to correctly guess a randomly chosen word.
  • The player will have 6 guesses. Each time the player guesses a word, each letter of the word will be compared with the answer, marking the letter with the colors grey, yellow or green.
    • Grey: The answer does not contain the letter.
    • Yellow: The answer does contain the letter but it is not in the correct position.
    • Green: The answer contain the letter and it is in the correct position.

What is something extra?

We would like to allow some elements of customizability for the player, taking advantage of the benefits of functional programming.

  • Allowing the player to choose between categories.
  • Allowing the player to choose how many words they would like to guess at once.

In addition, we will utilize different colors of Unicode characters in the terminal to help represent the state of the game for the player.

What did we learn from doing this?

All in all, functional programming can definitely be used to implement Wordle as a simple terminal based program.

There are many aspects of functional programming that we learned are very beneficial for creating a game. One benefit of functional programming is the immutability of objects. This made it easy to determine the state of an object at any given time, and understand what is going on in certain lines, knowing that these objects cannot be modified. As such, immutability was especially useful for abstraction and debugging purposes. Functional programming languages also allow for the usage of higher-order functions which allowed us to write code much more concisely. For example, for a function that requires the need to convert the first letter of a string to a lowercase letter we can pass the function itself as a lambda expression, instead of needing to create a new helper function altogether. What is probably the most appreciated feature of functional programming is the ease of which one can test individual functions using ghci, which can be difficult to do for object-orientated programming. Another unexpected advantage we found is the strongly typed nature of functional programming which actually made it easy to identify any type errors and prevent run-time errors.

Although we initially explained that immutability was a benefit throughout our coding process, we also learnt that it can be a major headache for required features of our game, mainly for having to update the state by passing in the state of the game through functions.

Links to Code

https://github.students.cs.ubc.ca/linky98/Wordle-Game

To run the code, in the terminal type:

  • chcp 65001
  • ghci
  • :load Main
  • main