Crafting CLIrdle — Wordle in your CLI

Yash Bhatnagar
2 min readApr 18, 2022

--

Recently I worked on a project called CLIrdle. It’s a remake of Wordle but with a developer twist: the game runs in your console. I first started working on this project as a programming exercise, but it later evolved into a fully functioning game. In this post, I’ll be guiding you through how I crafted CLIrdle. I worked on this project with my father, as we share the mutual interest of programming!

To get started, we first decided to use NodeJS as our programming language. This was due to Node’s amazing package manager, npm. Npm gave us access to millions of useful packages which we would be using in our project. We used prompt-sync for terminal input and colors for colourful console prints.

We first decided to work on picking a random word. We copied a dictionary of 5 letter words into our code and picked a random word every time the game was initiated. We then wrote a function called ReturnHints(), which took the word the player tried to guess, and the first word the player used. The function looped through the words and tried to match them against each other to find similarities. Every time it found a Yellow(a letter that is there in both words but not at the same position), it would add a “Y” to an array called codeString. The same was done for the Greens(a letter that is there in both words at the correct position) and the Blacks(a letter that is not there in the Wordle). After a few hours of testing and debugging, we were ready to move on. Here’s an example of how the code works: If the Wordle is “watch” and the player tries “catch”, the codeString looks like this: [“B”, “G”, “G‘, “G”, “G”]. This was our algorithm.

To finish off, we wrote a code reader which read this string and then printed out a colourful input in the terminal based on the hints. Since this entire game was inside a function called clirdleGame(), we could call this function inside itself(recursion) to allow a play again loop. Please share CLIrdle with your friends and family and like this post if you enjoyed going through the code! You can find CLIrdle on:

GitHub: https://github.com/superzackx/CLIrdle

ProductHunt: https://www.producthunt.com/posts/clirdle

--

--