5 Gordle: Play a word game in your terminal

 

This chapter covers

  • Building a game that runs in a terminal
  • Retrieving runes from the standard input
  • Getting a random number in a slice
  • Propagating errors
  • Reading the contents of a text file
CLAUDIO–One word, good friend. Lucio, a word with you.
LUCIO–A hundred, if they’ll do you any good. Measure for Measure, William Shakespeare

This chapter is about a love story. During the 2020 pandemic, Mr. Wardle, a passionate software developer, created a new game named Wordle for his partner Ms. Shah, a word-game addict. After introducing the game to his relatives and seeing how welcomed it was, he decided to publish it. This is how the famous Wordle game began its journey before going public and rising like a rocket. Now, a new word is released daily, which most people across the world call “today’s Wordle.” There are many variations, based on geography, math, Shakespeare terms, Tolkien, or Taylor Swift, along with even more adaptations in different languages throughout the world (beyond time and space, ancient Greek, Quenya, and Klingon are offered).

The game is pretty basic: you must guess a word of five characters in six attempts. After each attempt, the game tells you, for every character, whether it belongs to the solution and whether it has the correct position.

5.1 Basic main version

5.1.1 Mini main

5.1.2 Read player’s input

5.1.3 Isolate the check

5.1.4 Check for victory

5.2 Providing feedback

5.2.1 Define character status

5.2.2 Checking a guess against the solution

5.3 Corpus

5.3.1 Create a list of words

5.3.2 Read the corpus

5.3.3 Pick a word

5.3.4 Let’s play!

Summary