Building a 20 Questions Game in One Day with Amazon Q
A small game for AWS Game Builder Challenge 2024
Published Nov 18, 2024
I've always been drawn to the idea of using games to test AI, as they offer a compelling way to observe how it interacts in real-world scenarios. Recently, I decided to put this concept to the test by creating a modern twist on the classic 20 Questions game—where either the AI guesses what you're thinking or you try to guess what it's thinking.The challenge was to see if I could bring this game to life in a single Sunday using Amazon Q, with Amazon Bedrock as the backend model. This approach allowed me to explore AI's capabilities in two distinct ways simultaneously.
The result was a straightforward yet entertaining project powered by Llama 3.2 90B through AWS Bedrock, featuring a clean and engaging terminal interface that made the experience both simple and fun.
20 Questions is a timeless guessing game. The concept is simple: think of an object, and the other player asks yes-or-no questions to figure out what it is. I wanted to see if an AI model like Llama 3.2 90B could handle the challenge of asking smart questions or answering them with consistent logic.
But I didn’t want just any game. I wanted something sleek and easy to use—no complicated setups, just you and your terminal. The goal was to keep things simple, accessible, and fun.
But I didn’t want just any game. I wanted something sleek and easy to use—no complicated setups, just you and your terminal. The goal was to keep things simple, accessible, and fun.
I picked this game to use GenAI because this required that AI be able to communicate and use logic at the same time. The way you phrase questions , when you choose to guess al matters.
I wanted to build a terminal game. There is beauty in the simplicity of the terminal, no login, passwords, just start and play.
I used Rich, a Python library that lets you spice up terminal apps with colorful text, structured layouts, and animations. With Rich, the game felt alive. Questions popped up in bold, colorful panels. User prompts were clear and intuitive. Even the game’s flow felt smoother with Rich’s formatting tools.
The terminal seemed perfect for text based games like this .Although personally i like a clean black and white format of the terminal i can see the appeal of formatting that this library provides.
I used Rich, a Python library that lets you spice up terminal apps with colorful text, structured layouts, and animations. With Rich, the game felt alive. Questions popped up in bold, colorful panels. User prompts were clear and intuitive. Even the game’s flow felt smoother with Rich’s formatting tools.
The terminal seemed perfect for text based games like this .Although personally i like a clean black and white format of the terminal i can see the appeal of formatting that this library provides.
I like Llama models—they are powerful and open-source, so I wanted to test this with this game. Here you can see how AI is crafting the questions and also see how it’s thinking to guess better. You can see its NLP capability and its logic. So while its beautifully crafted questions might hide the fact, there’s still a long way to go with its logic. It would guess too fast and make the same errors multiple times. It’s kind of like our subconscious mind shouting out the first thing that comes to mind.
Here’s what it did well:
- Smart Questioning: When the AI guessed your object, it asked questions that felt logical and systematic.
- Creative Guessing: When it was its turn to pick an object, it came up with interesting choices.
- Context Awareness: It remembered previous answers and adjusted its questions accordingly.
AWS Bedrock made it easy to plug the model into the game. I didn’t have to deal with messy infrastructure—Bedrock handled all the heavy lifting, from scaling to API management. I could focus on making the game work, not on deployment headaches.
Building the game wasn’t all smooth sailing. Here’s what I ran into:
- Prompting: The AI had to keep track of answers during the game. For example, if you said “no” to “Is it a living thing?”, it had to avoid asking questions about animals later. Getting this right meant crafting careful prompts and managing the game state. I used a system prompt and enhanced user questions with wrapper prompts to make the model think; otherwise, it would guess super early.
- AI Bias: Llama 3.2 90B is amazing, but it sometimes struggled with less common or culturally specific objects. It’s great with everyday things, but throw in something unusual, and it might stumble.
- Making the Terminal Look Good: Balancing aesthetics and usability in the terminal took some experimentation. Rich helped, but I still had to figure out the best way to present questions and answers without overwhelming the user.
This project was a crash course in AI, user interface design, and creativity. Here are the big takeaways:
- AI Is a Great Partner, Not a Perfect One: I used Amazon Q for this, had the VS extension installed. It was very helpful, especially having it at the side. The implementation of the extension is also very useful. I would recommend everyone try it. But there’s still a way to go. It handles logic poorly; when code becomes, say, more than 500 lines, it kind of messes up somewhere, and you have to review the entire code to find it. But still, overall, without it, I couldn’t have built it in a day.
- The Terminal Can Be Beautiful: With the right tools, even a basic command-line interface can feel polished and engaging.
- Keep It Simple: A straightforward game design with clear instructions and minimal setup makes the whole experience more enjoyable.
This wasn’t a coding exercise—it was a fun way to explore AI’s potential in a simple, interactive setting. The combination of a classic game, modern AI, and a slick terminal experience proved that you don’t need flashy graphics to build something interesting.
Whether you’re into AI, love tinkering with Python, or just want to play around with something unique, this project is a great starting point. Plus, you’ll get a better sense of what today’s AI models can (and can’t) do.
Building this game was a blast. I used AI to build a game that uses AI.
Sometimes it can be frustrating—generative AI being indeterministic and all. I think we have to learn how to code with AI as a coding partner. But it was a very helpful exercise nonetheless.
If you’re curious, give it a shot! All you need is a bit of Python, access to AWS Bedrock, and a willingness to see how far you can push AI in a guessing game. This is fun way to test the models, do try with various models, see how they interact.
Sometimes it can be frustrating—generative AI being indeterministic and all. I think we have to learn how to code with AI as a coding partner. But it was a very helpful exercise nonetheless.
If you’re curious, give it a shot! All you need is a bit of Python, access to AWS Bedrock, and a willingness to see how far you can push AI in a guessing game. This is fun way to test the models, do try with various models, see how they interact.
Github : https://github.com/samueljohnsiby/twenty_questions.git