Hello AI club members, we're so excited to kick off the tron project!
Welcome to the AI Tron AI project, we're so glad you've decided to join us! This week, we're setting up everything you need to start building an AI that plays Tron. Don't worry if you're new to programming, we'll be going through each step together for this first week.
Before we dive into coding, let's understand the game we're working with.
Task: Play Tron online to familiarize yourself with the game mechanics.
1. Go to https://www.crazygames.com/game/fl-tron
2. Play a few rounds against the computer or a friend
3. Pay attention to:
How the light trails work
How collisions are handled
The strategies you use to avoid collisions and trap opponents
Now, let's set up your computer for Python development. We will be using Pygame, OpenAI Gym, and Stable-Baselines3. Again don't worry if you don't know what these are, for today we'll only be using the Pygame library.
Download Python 3.8 or later for your operating system
Run the installer
On Windows, make sure to check "Add Python to PATH"
Verify the installation:
Open a command prompt or terminal
Type python --version and press enter
You should see the Python version number
Virtual environments help keep your projects organized. It allows you to install libraries and packages specific to this project without affecting your system's Python installation.
Open a command prompt or terminal in the folder where your repo is cloned.
Create a virtual environment:
On Windows:
python -m venv venv
On MacOS / Linux:
python3 -m venv venv
Activate the virtual environment:
On Windows:
venv/Scripts/activate
On MacOS / Linux:
source venv/bin/activate
Now that your virtual environment is active, let's install the necessary libraries.
Ensure you're in your project directory with the virtual environment activated
Install the libraries using pip: pip install pygame gym stable-baselines3
Verify the installations: pip list
You should see pygame, gym, and stable-baselines3 in the list
Let's write some code to create a basic Pygame window.
In the week1 folder of your project directory, create a file named tron_game.py
Copy and paste from the code below this list.
Save the file
Run the script:
Make sure you're in the week1 folder in your terminal:
cd week1
In the terminal (with your virtual environment activated):
python tron_game.py
You should see a window with a black background and a red rectangle
Let's break down what each part of the code does:
pygame.init(): This initializes all pygame modules.
pygame.display.set_mode((WIDTH, HEIGHT)): This creates the game window.
The main game loop:
Checks for the quit event (closing the window)
Fills the screen with black
Draws a red rectangle
Updates the display
pygame.quit(): This closes pygame when we exit the loop
Let's make sure you environment is set up correctly to ensure the coming weeks go smoothly
Make sure you're in the week1 folder in your terminalcd week1
In the week1 folder of your project directory, make a new file called test.py
Copy and paste from the following filetest.py
Run the command python test.py
You should see the following output
pygame 2.5.2 (SDL 2.28.3, Python 3.11.4)
Hello from the pygame community. https://www.pygame.org/contribute.
Test 1 passed: Pygame is installed and initialized successfully.
Test 2 passed: Pygame window created successfully.
Test 3 passed: OpenAI Gym and Stable-Baselines3 are installed.
Tests passed: 3/3
All tests passed! Your environment is set up correctly.
Common Troubleshooting Tips
Make sure you've activated your virtual environment before running the script.
Make sure you're in the week1 folder in your terminal.
Make sure you've installed the libraries correctly, you can test this by running pip list in your terminal.
Please reach out in the MSU AI Club Tron project Discord channel if you're having further trouble!
By the end of this week, you should have:
Played Tron and understood it's basic mechanics
Set up a Python development environment with a virtual environment
Installed Pygame, OpenAI Gym, and Stable-Baselines3
Created and run a basic Pygame window with a simple shape
Try modifying the Pygame window code to:
Change the window size
Change the background color
Draw a different shape or multiple shapes
Make a shape move across the screen
Next week, we'll start building the actual Tron game board and implementing game logic. Great job on getting everything set up!
I have done all the Bonuses but do not know why on adding multiple shapes the output screen goes black and cannot be closed.
Hey there, Aidan here, send a message in the discord and I can help out!