Creating a Space Invaders game with Autogen Studio 2.0

One of the Generative AI platforms I’ve been following closely and extremely excited about over the past few months is Microsoft’s Autogen Studio that allows us to design and use multi-agent solutions. Using this type of workflow framework truly opens up a multitude of opportunities to solve real world problems. There are plenty of material out on the internet about agentic workflows so I’ll paste the YouTube video I enjoyed most here:

What’s next for AI agentic workflows ft. Andrew Ng of AI Fund
https://www.youtube.com/watch?v=sal78ACtGTc&t=2s

Installing Autogen Studio is fairly easy and the instructions can be found here: https://autogen-studio.com/autogen-studio-ui

I’ll likely follow up with another post walking through the process in the future.

Now without further ado, let’s have a look at Autogen Studio and the interaction between two agents while developing a Space Invaders game with python.

Developing Space Invaders with Autogen Studio UI

Those who may remember Space Invaders will know that it’s a simple game where you have a space ship that moves around the x axis where the objective is to dodge enemies above while you try to shoot them.

Space Invaders from Wikipedia

The game isn’t overly complicated and using a simple two agent workflow allowed Autogen Studio to code it in Python in 3 minutes and 31 seconds.

The following is the flow of the workflow of the two agents working together to develop and debug the code.

1. I begin by asking the userproxy agent to perform the following: create an outline for space invaders game and then code it in python and the userproxy proceeds to make the request to the primary_assistant agent. This kicks off the joint effort between the agents and the primary_assistant provides an outline of the steps to be done:

userproxy ( to primary_assistant )

create an outline for space invaders game and then code it in python

primary_assistant ( to userproxy )

Sure, let’s start by creating an outline for the Space Invaders game.

Outline:

  1. Game Setup: Initialize the game window and game variables.
  2. Player Character: Create a player character that can move left and right at the bottom of the screen.
  3. Invaders: Create multiple rows of invaders that move left and right, and down the screen.
  4. Player Bullets: Allow the player to shoot bullets upwards at the invaders.
  5. Invader Bullets: Occasionally, invaders shoot bullets downwards at the player.
  6. Collision Detection: Check for collisions between bullets and invaders, and between bullets and the player.
  7. Scoring: Keep track of the player’s score, which increases when an invader is hit.
  8. Game Over: The game ends when an invader reaches the bottom of the screen or the player is hit by an invader’s bullet.
  9. Restart Game: Allow the player to restart the game after it ends.

2. The primary_assistant indicates that the pygame library is required, provides the pip install instructions to install, then writes the code for the game:

3. The python code is returned to the userproxy agent with instructions that the 3 images are required. The userproxy attempts to run the python game without the required images and receives an error indicating the image files are not found. The error is sent back to the primary_assistant:

4. The primary_assistant reads the error and explains (again) that the python app is expecting images in the working directory and given we don’t have it the images, it will change the image requirements to shapes instead:

I apologize for the confusion. The error occurred because the images ‘player.png’, ‘bullet.png’, and ‘invader.png’ were not found in your working directory. These images are placeholders and need to be replaced with the actual paths to your game assets.

Since I can’t provide the images for you, let’s modify the code to use simple shapes instead of images. The player will be a rectangle, the bullets will be lines, and the invaders will be circles.

Here’s the modified code:

5. The code is returned by the primary_assistant but the userproxy agent encounters another error:

exitcode: 1 (execution failed)
Code output:
Traceback (most recent call last):
File “space_invaders.py”, line 61, in <module>
if pygame.rand() < INVADER_SHOOT_CHANCE and len(invader_bullets) < INVADER_BULLET_LIMIT:
^^^^^^^^^^^
AttributeError: module ‘pygame’ has no attribute ‘rand’

6. The primary_assistant realizes that we are missing the random module that the app uses and proceeds to update the code:

7. The userproxy agent attempts to execute the code and the python app is now executing successfully with an exitcode: 0. This workflow is now considered to be completed and the primary_assistant provides more information about the game before terminating.

8. Opening space_invaders.py will display the full code:

9. Let’s go and test this now (make sure you pip install pygame if it isn’t already installed):

The Python code for this game is available at my GitHub repo: https://github.com/terenceluk/Autogen-Studio/blob/main/Games/space_invaders.py

This is certainly not the most sophisticated game but the workflow and interaction between 2 agents demonstrates what an agentic workflow can achieve.


Developing a Tetris game

To avoid misleading everyone that these workflow durations take very little time, I want to include the workflow for developing a Tetris game where it took 17 minutes and 34 seconds (much longer than the Space Invaders game). The interaction between the two agents is quite remarkable as they debugged the 411 lines of code through many iterations.

Here are a few of the exchanges:

Here is a screenshot of the game:

The Python code for this game is available at my GitHub repo: https://github.com/terenceluk/Autogen-Studio/blob/main/Games/tetris.py

I would encourage anyone to give Autogen Studio a try!