AWS Logo
Menu
Creating an NYT Connections-Inspired Game for the AWS Game Builder Hackathon

Creating an NYT Connections-Inspired Game for the AWS Game Builder Hackathon

Sharing my learnings from my submission for AWS Game Builder Challenge Hackathon

Published Dec 11, 2024
TLDR: Sharing my learnings from my submission for AWS Game Builder Challenge Hackathon, which runs till Jan 15, 2025. You can read more about the hackathon [here](https://awsdevchallenge.devpost.com/)

Getting Clear at the Get-Go

As a fan of NYT's _Connections_ game, my goal for this hackathon was to create a beginner-friendly and minimalist Python version of it.
As a product manager turned builder, for the past two years, LLMs have been my trusted companion in navigating the nuances of the coding landscape. Q Developer was my coding companion for this project. Much like IRL communication, clarity is key when interacting with LLMs.
My strategic vision for building this Python game**
Start Small and build iteratively
Milestones to Achieve My Vision:
Level 1 - A (very) simple Python script that gets the job done
Level 2 - A smarter Python script (with S3 integration)
Level 3 - An interactive Streamlit interface to enhance user experience
Level 4 - Cloud deployment

Setting the Stage for Success

Connections is a game that tests your ability to group words (of 4) into categories. You can play the real NYT game here https://www.nytimes.com/games/connections
In this project we use:
  • Python: Core programming language for building functionality
  • Streamlit: For creating an interactive user interface
  • Q Developer: VS Code extension for seamless coding assistance
  • AWS Services (S3): Data storage and integration
You can find link to my GitHub repo in the Resources section.

Level 1: Starting Small and Simple

>The goal for level 1 is to build a simple and functional Python script (with hardcoded categories)
Start with the right setup for success. Create a new directory with an empty `game_l1.py` file (i.e. l1 for level 1 game). In my setup, I have my IDE open and Amazon Q chat open on one side of the editor.
IDE
In the Amazon Q chat, I ask my question to build a very simple connections game. Q suggests a version with hardcoded categories.
At this point, you may have to go back and forth to achieve the level of simplicity that desire in your project. In my case, I kept prompting Q to give me a simple enough version that achieves the following:
Setup
  • Hardcode categories and words in a dictionary.
  • Flatten the dictionary values into a single list and shuffle them.
Gameplay Loop
  • Display the shuffled words to the player.
  • Take in and validate their input
  • Check if the input matches any category using set operations
Track Progress
Remove correctly guessed categories from the remaining ones.
End the Game
Congratulate the player when all categories are grouped.
💡The code for this level 1 game is stored as game_l1.py in my Github repo.
To run the Level 1 file in your terminal:
```bash
python game_l1.py
```
Here is the output from Level 1:

Level 2: Integrating Amazon S3

>The goal for level 2 is to build a dynamic Python script that loads categories from the cloud
Static games are fun - for a while. Enter **AWS S3**, cloud’s Swiss army knife for storage. I created a `categories.json` file with 50 categories and uploaded it to an S3 bucket.
This enhanced game includes the following capabilities:
Fetching Categories
  • Connect to S3 using Boto3.
  • Retrieve the JSON file containing the categories.
  • Parse the file and load categories into the game.
Randomized Game Setup
  • Randomly select four categories from the loaded data.
  • Shuffle the words.
Scalable Design
The best part - no need to redeploy the app—just update the JSON file in S3!
I used Q in this part of the project for a smooth set up with S3.
💡The code for this level 2 game is stored as game_l2.py in my GitHub repo. It builds off of level 1 code.
💡💡Since this part involves sensitive information, such as the IAM access key and AWS service names, store them in a `.env` file and use `.gitignore` to exclude the file when pushing to GitHub
To run Level 2 file:
```bash
python game_l2.py
```
Here is the output from Level 2 - categories are being fetched from S3:

Level 3: Enhancing Interactivity with Streamlit

>The goal for level 3 is to build an interactive user interface for our game
Now comes the fun part, turning our humble Python script into an interactive app. **Streamlit** makes this easy. I was particularly impressed with Q's answer to transforming my level Python 2 script into a fully functional Streamlit interface.
The celebratory balloon effect when winning the game is a delightful touch from Streamlit, and it's incredibly satisfying, I must say! ;)
Here are the key highlights:
  • Fetch Data: Game data is fetched from a JSON file on AWS S3 for scalability.
  • Randomized Gameplay: Four random categories are selected, and words are shuffled into a 4x4 grid.
  • Interactive Selection: Players choose words they believe belong together.
  • Feedback & Progress: Correct groups are marked, incorrect ones prompt retry, and progress is tracked.
  • Win Condition: The game ends when all categories are identified, followed by a celebratory balloon effect.
  • Reset: Players can restart for a fresh round.
💡The code for this level 3 game is stored as game_l3.py in my Github repo. It builds off of level 2 code.
💡💡To test Streamlit locally, store the variable names in a `.streamlit/secrets.toml` file instead of a `.env` file, ensuring they are accessible to Streamlit and use `.gitignore` to exclude the file when pushing to GitHub
To run level 3 file:
```bash
streamlit run game_l3.py
```
Here is the output from Level 3 - locally running the Streamlit interface

Level 4: Deploying in the ☁️

>The goal for level 4 is to deploy the game on Streamlit Cloud
Ease of Deployment is where Streamlit truly shines.
Here are the key steps:
  1. Push the code to GitHub.
  2. Deploy the app to Streamlit Cloud.
  3. Access the app via the provided URL.
💡The code for this level 4 game is stored as app.py in my GitHub repo. It builds off of level 3 code.
💡💡When deploying to Streamlit Cloud, update the secrets in the console via the `st.secrets` method to ensure they are securely accessed
No screenshots - the game is live, try it for yourself [here](https://awsconnectionsgame.streamlit.app/)

Final Thoughts and Resources

Starting simple and building iteratively is the key. With Q Developer and a clear idea, you can go from idea to deployment in no time and this minimalist Word Connection Game is a testament to this.
Try out the game for yourself and relish your win with the celebratory balloon effect 🎈🎈🎈🎈 🎉
Resources :
* AWS Game Builder Challenge: https://awsdevchallenge.devpost.com/

Comments