Build a Tic Tac Toe game using Amazon Q
Use prompts to work with AI programming tools to iterate on the game requirements
Abhishek Gupta
Amazon Employee
Published Nov 5, 2024
In a previous blog post, I had demonstrated how to get started with AWS Lambda and Go with the help of Amazon Q. That was a while back (given how time flies when it comes to advancements in generative AI!). This time, I tried building a simple game only using Amazon Q. Here is how it went....
I started with something really simple - no detailed instructions, or specifications. I wanted to see what Amazon Q comes up with:
Create a two-player, interactive tic-tac-toe game in Python
The result was reasonable and I got the code for a working game.
The game exited awkwardly as soon as it ended - win or tie. Like I said, I did not provide any specifications to begin with. So I asked Amazon Q to update the code based on my feedback:
Before the game begins, allow players to enter their names and associate X or O with each of them. When a game ends, announce the result (who won, or was it a tie) and provide the option to exit the game or play another round.
The code did what I asked it to. But the interactions (asking for player names, etc.) were on the CLI, not the GUI.
I should have been clearer! Never mind, I asked Amazon Q to improve it:
Use the GUI to accept player names, announce results and exit options.
When I ran the resulting code, I got this error:
I Amazon Q to "fix" the code. It identified the issue in the
__init__
method and provided a corrected version:This new version fixed the issue, but there were a few other issues, particularly the window size.
I asked Amazon Q to take care of it:
The window is too small. Also, I don't see which player was assigned what - X or O. The option at the end of the game is not visible as well.
After all the improvements, the game worked as expected.
Here is the final version of the code that Amazon Q provided:
There is always scope for improvement, but I stopped here. This reinforced the idea of being clear with specifications and requirements - with or without AI. To make sure I don't offend anyone, I won't add memes to support this statement ;)
If you're ready to build your own game, AWS is running a hackathon through the month of November. From a simple tic tac toe game built with HTML/CSS/JS to a complex Unity game -- all skill levels and tech stacks are welcome. Join now on DevPost: https://awsdevchallenge.devpost.com!
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.