iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🎮

I Built an Akinator-style Game with Amazon Q CLI!

に公開

I Made a Game with Amazon Q CLI! An Akinator-style Food Guessing Game

I found a campaign called "Build Games with Amazon Q CLI and Score a T-shirt Campaign" on the official AWS blog! Apparently, you can get a T-shirt by creating a game with Amazon Q CLI and posting a blog about it!

Do you ever have those moments where you want to eat something, but you're not quite sure what? I certainly do. So, I decided to create an Akinator-style game that guesses what you want to eat right now by answering a few questions!

I actually built the game using Amazon Q CLI, so here is a report on that experience.

🛠️ Environment Setup: Setting up Amazon Q CLI on WSL

First, I'll install Amazon Q CLI on WSL (Ubuntu) in a Windows environment.
I referred to the article "The essential guide to installing Amazon Q Developer CLI on Windows".

Install necessary tools

sudo apt update
sudo apt install unzip

Download & Install Amazon Q CLI

curl --proto '=https' --tlsv1.2 -sSf https://desktop-release.codewhisperer.us-east-1.amazonaws.com/latest/q-x86_64-linux-musl.zip -o q.zip
unzip q.zip
cd q
chmod +x install.sh
./install.sh

During installation, you'll be asked something like "Do you want to automatically modify your shell configuration?". Answer "Yes". This will set up your PATH.

To apply the settings, restart the shell:

bash

🐍 PyGame Preparation

WSL Ubuntu came with Python pre-installed, but pip was missing. I handled it this time without using pip:

sudo apt update
sudo apt install python3-pygame

🔑 Logging in to Amazon Q CLI

q login

By selecting "Use for Free with Builder ID," you can use it with an AWS Builder ID even if you don't have an AWS account!

🎯 Time to Develop the Game!

I launched Amazon Q CLI and immediately requested it to build a game:

> Using PyGame, create an Akinator-style "guess what I want to eat right now (even if I don't necessarily have it clearly in mind)" game.

😅 Initial Challenges

At first, I was told "pip is required," but once I mentioned that "it's already installed via apt," it was able to proceed.

And here is the very first game screen that was displayed:

All the text was garbled, appearing as question marks.

I requested, "The text is garbled, so please make it support Japanese fonts." It fixed the issue by having WSL reference Windows fonts, and the Japanese text began to display correctly.

🎨 UI Improvement and Character Addition

Since the screen was a bit too simple, I decided to add an image. I borrowed a bear illustration from Irasutoya.
https://www.irasutoya.com/2018/03/blog-post_768.html

I placed the image in the same directory as the Python file and asked Amazon Q CLI to include it. It added the image to the game screen and automatically adjusted the button positions to match the layout.

🎮 Here is the Completed Game Screen!

Title Screen

A cute bear chef has appeared. Wearing a chef's hat and holding a frying pan, he's the perfect character for a food-themed game.

🎮 Gameplay Video

This is how the actual gameplay looks. As you answer the questions, the bear guesses what you want to eat.
It seems I wanted to eat minestrone.

An animation of the bear celebrating with a "Yay!" is displayed.

🤖 Self-learning Feature for Incorrect Guesses

What surprised me here was that it implemented a self-learning feature even though I didn't ask for it.

A feature was spontaneously added where, if the guess is wrong, the user is asked what they actually wanted to eat, and that information is saved to a JSON file. This mechanism is used to improve question accuracy in future attempts.

💭 Impressions After Development

✅ 560 Lines of Code Created on Its Own

What surprised me most about building a game with Amazon Q CLI was that I could create something that actually works with just a few interactions.

The entire exchange took less than an hour, but it resulted in a Python script of about 560 lines. It included UI construction, image loading and placement, button adjustments, game logic, and even self-learning—and I didn't write a single line of code myself.

🍜 It Even Created a Database Automatically

Another thing that impressed me was that these features were implemented naturally, even though I didn't explicitly say "create a database" or "include self-learning."

The food data used in the game was automatically generated as a JSON file summarizing names and characteristics. It was structured to narrow down candidates based on attributes such as "hot," "noodles," and "Japanese food."

For example, here is the kind of data it contains:

{
  "name": "ラーメン",
  "attributes": {
    "hot": true,
    "savory": true,
    "japanese": true,
    "noodle": true,
    "soup": true,
    "quick": true
  }
}

Furthermore, a self-learning feature was automatically incorporated to record what the user "actually wanted to eat" when a guess was wrong, reflecting that information in future attempts.

Even though I didn't provide detailed specifications, I felt the high level of completeness of the tool in the way it successfully supplemented the necessary mechanisms.

💡 Could Be Useful for Script Creation

While I made an Akinator-style game this time, I felt that this "build through conversation" experience could also be applied to creating small scripts and tools.

For instance, tasks like "reading a CSV and generating a graph" or simple GUI applications feel like they could be built with Amazon Q CLI through natural conversation alone.

📝 Summary

  • Approximately 560 lines of Python code were completed using only natural language instructions.
  • A database and self-learning functionality were automatically integrated before I even suggested them.
  • It offers enough flexibility to be applied to a wide range of use cases.

Amazon Q CLI felt like a reliable partner that takes your "I wonder if I could make this" ideas and brings them to life. It's a tool I'll definitely want to reach for whenever a new idea strikes.

I encourage everyone to try developing a game with Amazon Q CLI! 🎮✨

Discussion