Skip to content

Instantly share code, notes, and snippets.

@ChrisOwen101
Last active May 9, 2023 15:37
Show Gist options
  • Save ChrisOwen101/6d6d6800d49ac1d04885afc09d830ef6 to your computer and use it in GitHub Desktop.
Save ChrisOwen101/6d6d6800d49ac1d04885afc09d830ef6 to your computer and use it in GitHub Desktop.

Wordle

Create a command line version of the game "Wordle", paying attention to the following stipulations:

  • Code which handles user input must be kept in a separate file to code which handles checking words and awarding wins or losses
  • All functions must be labelled descriptively and comprise of no more than 5 lines of code each
  • All game logic should be stored in a directory named "wordle_game"; outside of this directory, there should be another named "wordle_data"
  • Your Wordle implementation should select each game's target word from a list of valid words within wordle_data named "wordle_words.txt"

The rules of Wordle are as follows:

  • A five letter word is selected as the target word
  • A player will an opportunity to guess the target word
    • If the guess is not a valid word, the player may guess again
    • If it is then revealed for each letter in the guess whether it is:
      • present in the target word and in its right place
      • present in the target word but in the wrong place
      • not present in the target word
  • In order to display this to the player, you should display their guess and then on the next line five symbols
    • "+" for correct letter and place
    • "~" for correct letter and incorrect place
    • "-" for an incorrect letter
  • The player has five total guesses; if they cannot guess the target word in five attempts, they lose the game
  • When asking for the player's input, you should display the number of remaining guesses the player has.
  • Upon a victory, the player should be shown a congratulatory message
  • Upon a loss, the player should be shown a commiseration message
  • In both of these events, the message should display the target word

Upon completing a game of Wordle, the user's game statistics should be stored in a text file named "results.txt"

This file results.txt must be formatted like:

Date: DD/MM/YYYY, Guesses: 4, Win/Lose: Win, Wins to date: 1, Losses to date: 0

Date: DD/MM/YYYY, Guesses: 5, Win/Lose: Loss, Wins to date: 1, Losses to date: 1

Date: DD/MM/YYYY, Guesses: 2, Win/Lose: Win, Wins to date: 2, Losses to date: 1

and so on, with the data from the most recent game being written to the next line of results.txt each time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment