Guess The Password is a fun single player game where the player is shown a 7 digit number and is told that one digit has been changed to a random digit. The user can ask 5 an yes or no questions. These questions are answered by OpenAI’s gpt-4 model. The questions and the responses are stored so that if the user has to look back at a response from before, they can.
One digit at a random index is changed and then the new and the previous are number are fed into the prompt that is submitted to the gpt-4 model. The gpt-4 model is also told what the different number is and is located at which index. This is done before sending the prompt using a function designed specifically for this. This is done as the gpt-4 model is not perfect and relying on the model for the most important information might lead to completely wrong answers and a bad user experience. Once the user guesses the correct answer, a confetti animation appears which was built using the react-confetti library.
The way the project works is that first a random 7 digit number is generated, and then it is converted to an array. Then a random index is chosen and is replaced by a random 1 digit. Then the new array is combined back into a number which now is the number to be guessed. Then a post request is made to the backend, which makes an api request to the OpenAI api that gives either a yes or a no response or “Please ask a yes or a no question” response. If the answer is a yes or no, then a info react-toastify appears, otherwise an error react-toastify appears. If the response was a yes or no, then the number of questions left decreases and the response is also stored in the table along with the question, otherwise nothing happens. Once the user clicks submit, the inputted number is checked with the number to be guessed. If the inputted number and the number to be guessed matched, then a react-confetti component is displayed and a popup with a button to start a new game is shown, otherwise an error react-toastify is shown to inform the user that the guess was incorrect.
This project was built using React for frontend, Node and Express for backend, and OpenAI’s api for answering the questions.