- Chan Yan Tak (UID: 3035927635)
- Tam Pai Lok (UID: 3035926447)
As the Wordle game has become a world phenomenon on the Internet recently, similar games started to pop up. One of them is Nerdle, a math-based world-puzzle game created by Richard Mann. We aim to recreate that game but included some twists to add a touch of uniqueness to our ruleset. The name "Algeble", is a combination of "Algebra" and "Wordle", which instead of deducing a hidden word, players need to deduce a hidden algebraic expression.
The machine will randomly generate an algebraic expression with an integral result from 100 to 999. Your goal is to deduce the algebraic expression and obtain the result of the expression with the minimum amount of clues, which you get every turn. The game starts at the cluephase, during a turn, you are required to type an algebraic expression that must result in a number randomly generated by the machine, different from its. The machine then compares your expression with its and gives you a “Wordle format” clue (See below for details). You then use the clues to help deduce the machine’s original algebraic expression. Unlike Wordle or Nerdle, your goal is not to type out the deduced algebraic expression out as doing so is impossible given that both expressions yield different results. Rather, you need to deduce the expression in your head. Once you are confident enough in deducing the expression (as well as its result), you will enter the guessphase and have 1 chance to enter the result of the expression and you win if you get it correct, else you lose. Additionally, extra logic (see Custom Game settings for details) is applied to give more clues to the player.
Wordle format clue:
The clue consists of symbols "O", "X" and "#" with the same length of the algebraic expression, each corresponding to the existence and correctness of the position of the character at that position. "O" represents that the character exists and is in the right position with respect to the hidden expression. "#" represents that the character exists in the hidden expression but in a different position. "X" represents that the character does not exist in the hidden expression. There may be repeated characters within the same expression. In that case, any character(s) in the correct position will first be represented with an "O", when there are additional examples of the character in both the guess and the answer (but not in the right place), characters will be represented by "#" from left to right in the guess expression until the amount of "#" and "O" of that expression matches the total number of that character in the hidden expression (or until all the characters are represented by "#"s). The remaining extra digits in the guess expression are represented by "X".
The variant gamemode is similar to the standard gamemode, but players will only get 5 maximum rounds but 99 guesses. Players are expected to use all rounds but a minimum of guesses to obtain the result of the expression.
When creating a custom game, a variety of custom settings can be selected by the user:
-
Length of algebraic expression
Players can choose 8-10 as the length of the algebraic expression
-
Equation generation method (Random in standard and variant games)
Players can add a set of custom equations in the files in the custom equations directory, the computer will then pick a valid expression from the file as the hidden expression. The computer may also generate a random valid expression on its own.
-
Maximum round count (35 in standard games and 5 in variant games)
Players can set the maximum round and clue counts from 1 to 35. Once the maximum round is reached, the game will automatically enter the guessing phase.
-
Guess count (1 in standard games and 99 in variant games)
Players can set the guess count from 1 to 99. The game wins when the player guesses the result of the hidden expression before all guesses are used, and vice versa.
-
Extra logic (Enabled in both standard and variant games)
When enabled, the results required to be equal by the player's guess expression will never share 2 same digits with the result of the hidden expression, which helps eliminate some possibilities and provide more hints for the player when guessing the expression.
-
Generated expression redundancy (Disabled in both standard and variant games)
When enabled, expression redundancy such as 0+, 0*, 0/, +0, -0, *0, 1*, 1/, *1, /1 are allowed in the hidden expression generated by the computer, and vice versa.
-
Guess expression redundancy (Disabled in both standard and variant games)
When enabled, expression redundancy such as 0+, 0*, 0/, +0, -0, *0, 1*, 1/, *1, /1 are allowed in the expressions typed by players, and vice versa.
-
Clue analysis (Enabled in both standard and variant games)
When enabled, analysis of previous clues will be shown when displaying previous clues. Analysis include the hidden expression with all correct guesses (Os) filled in, and also the state of each character. The state of the characters are "O" if there is at least 1 "O" for the character, "#" if there is at least 1 "#" but no "O"s for the character, "X" if it is known that the character does not exist in the hidden expression and "?" if the character has not been used in the clues.
-
Repeated guesses (Disabled in both standard and variant games)
When enabled, the same guess made during the guessphase (which is a waste of a guess), is allowed.
-
Random expression generation
Our random expression generation is programed to hope that each digit, each operator and each possible combination of operator's position can appear at the closest distribution. To do so, we tested the program to generate 1,000,000 expressions (valid or not) at equal disturbution of digit, operator and possible combination of operator's position. We then compared the data to the proportion of digits, operators and possible combination of operator's position of those in valid expressions and finally set up a bias proportion that digits, operators and possible combination of operator's position appear to compensate for the difference in proportion of digits, operators and possible combinations of operation that appeared in valid expressions. For example when generating a random operator, a "/" is more likely to be generated than a "+" since equations containing "/" are less likely to be valid compared with those with a "+". When generating an expression, the program chooses a random combination of operator's position as an template with the bias distribution. The positions are filled such that no numbers in the expression have more than 4 digits. Then, it fills the digits and operators in 1 by 1 using the bias distribution. Lastly, it checks if the expression is valid and if the result of the expression is a 3-digit integer. If not, the computer will repeat the generation process until a valid expression is generated. It is tested that the probability of the computer to generate a valid expression using the bias disturbution in around 1.5%.
-
Custom equations
9 files named 1.txt to 9.txt in the custom_equations folder can be editted by the user for them to set custom equations for the game. Players simply open a file and paste in their custom set equations and select the corresponding file when creating a custom game. The program will then choose a random expression from all the valid expressions in the corresponding file. A random equation will be generated if there is an error when opening the file, or when there is no valid expressions in the file.
-
Game structure
A user-friendly game menu, game mode selection menu and in-game menu is created to facilitate user inputs.
-
Different display modes
A detailed display mode can be selected by new players to adapt to the input requirements, while a simple display mode can be selected to minimize display length.
-
Continue game
A function to load a previously ongoing game saved in a .txt file. An ongoing game will constantly "update its status" on the cgame.txt file in the current_game folder and the file will be validated and loaded to where the game was last left off if the validation passes. A gamefile with the wrong format will be ignored and cleared when a new game has started.
-
Load gameseed
A gameseed is a 13-digit string that uniquely identifies all custom settings of a game. 2 games with the same gameseed have the same settings and random variables (when using the same OS & platform) but can be played differently. Players can share the gameseed once they encounter an interesting game.
-
Leaderboards
6 leaderboards are set for standard and variant games of different expression lengths. A reset function is provided to reset all leaderboards. A leaderboard will only be updated and resorted accordingly when a player enters their name after their score entered the top 5 of the corresponding game category in a non-custom and non-loaded game. Game scores are sorted by the number of guesses, followed by the number of rounds taken and the time taken. Time will only be kept for continuous games (games without exiting/crashing in the middle) and N.A. will be displayed for games that use the "Continue Game" function. Leaderboards can be viewed from the game menu.
-
Show all clues
This function during the cluephase will display all clues typed by the user before in 2 different formats, which helps players view and use the clues more conveniently.
-
Show previous guesses
Similar to the prior feature, this function will display all previous guesses by the user during the guessphase in ascending order.
-
Surrender function
A surrender option is set during the guessphase, after surrendering, the game will reveal the hidden expression and its result.
-
Error handling
Our program can fully respond to any invalid inputs, sometimes providing the reason for the invalid input, and ask users to reinput again.
-
Trimspace
Spaces before and after the input text will be automatically removed.
-
Generation of random game sets or events
Please refer to "Random expression generation" and "Custom equations" in the implemented features.
-
Data structures for storing game status
An integer and a string array are used to store the user's guesses and clues during the game respectively. Several variables are used to store game settings. A .txt file is used to store game status so the game can be loaded back after a game crash and a struct is used to store high scores on the leaderboard. Several .txt files are also used to store the high scores on each leaderboard.
-
Dynamic memory management
There is dynamic memory allocation when players choose to use custom equations in the genCE function. A 0-sized dynamic array is first created before reading through a chosen .txt file to get valid expressions. Every time a valid expression is detected, the size of the array will be expanded and that expression will be added to the dynamic array. After closing the .txt file, an expression of specified length will be randomly drawn from the dynamic array as the hidden answer.
-
File input/output
There is file input when players choose to use custom equations. Players can prepare a set of equations for the game and the function genCE() will choose a random valid equation from the corresponding .txt file in the custom_equation directory. There is also file input when players choose to view the leaderboard, the program will read and output the data in the corresponding .txt file in the leaderboard directory to the screen. There is file modification when a player enters the leaderboard in a standard or variant game, the corresponding .txt file in the leaderboard directory will be updated accordingly.
-
Program codes in multiple files
Our main program, consisting of 39 self-defined functions is separated into 10 categories, each with a .h and a .cpp file. The main.cpp will be compiled with the help of the makefile and executed to start the game.
Here is a youtube video demonstrating the gameplay: https://youtu.be/chR2b6m2poU
To start the game, the first type "make main" in the terminal and it will create or update 10 .o files and the main program, then type "./main" to start the game in the terminal. Typing "make clean" will remove all .o files and the main program. Our code can be successfully compiled in the Computer Science department's academy11 server.