This is a sumo bot game using Pygame. The game is played by two players. The objective of the game is to push the opponent out of the ring. The player who pushes the opponent out of the ring wins the round.
Each player should write a code to move their bots in the ring. The codes should be written in the files player1.py and player2.py using the function move_bot(...).
If you already have Python installed on your computer, you can skip this step.
If you are using Windows, you can install Python from here, and make sure you select the option to add Python to the path during the installation. In the next steps, you will need to use Windows Powershell.
An alternative option to install Python is by installing miniconda (Recommended). In this case, you will need to use the newly installed Anaconda Powershell Prompt instead of the Windows Powershell.
If you are using Linux or Mac, Python is already installed on your computer. Miniconda can be installed too (Recommended). In the next steps, you will need to use Terminal (Linux) or iTerm (Mac).
Creating a virtual environment is optional but recommended. Open Anaconda Powershell Prompt (Windows), Terminal (Linux), or iTem (Mac) and type the following commands.
conda create -n sumo_bot python=3.10 -y
conda activate sumo_bot
Once you have Python installed on your computer, install Pygame using pip (a package manager pip to install Pygame).
pip install pygame==2.5.2
git clone https://github.com/leocjj/sumo_bot.git
cd sumo_bot
To run the game use the following command inside the sumo_bot directory:
python main.py
Each player should put its own code in the corresponding file: player1.py or player2.py. The codes should be written in the function move_bot().
This function will receive each frame, the coordinates (x, y), and the actual (positive) rotation angle (rot) of its own bot and the opponent bot (x_opp, y_opp, rot_opp).
The angles are zero in the horizontal axis to the left, positive if it goes counterclockwise from zero or negative if it goes clockwise from zero (e.g. 270° and -90° are the same rotation angle).
At the end, it should return two values (a tuple of integers):
- The first value is for the next movement: 1 to move forward, 0 to stop, and -1 to move backward.
- The second value is for the next rotation: 1 to rotate counterclockwise, 0 to stop, and -1 to rotate clockwise.
def move_bot(x: int, y: int, rot: int, x_opp: int, y_opp: int, rot_opp: int) -> tuple[int, int]:
# Write your code here
# Return the movement and rotation, for example: rotate counterclockwise all the time.
return 0, 1
Change this variable in the file main.py to move the bots automatically, semi-automatically, or manually.
# 0: Automatic mode for both bots. No keyboard inputs.
DEBUG_MODE = 0
# 1: Automatic mode for player 1 bot only. The player 2 can be moved with the keyboard.
DEBUG_MODE = 1
# 2: Automatic mode for player 2 bot only. The player 1 can be moved with the keyboard.
DEBUG_MODE = 2
# 3: Automatic mode for both player bots and both players can use the keyboard too.
DEBUG_MODE = 3
# 4: Manual mode for both player players with the keyboard.
DEBUG_MODE = 4
The players can use the following keys to move:
- Player 1: W (forward), A (rotate CCW), S (backward), D(rotate CW)
- Player 2: Up (forward), Left (rotate CCW), Down (backward), Right(rotate CW)
- The game is played by two players.
- The objective of the game is to push the opponent out of the ring.
- The player who pushes the opponent out of the ring wins the round.
- The player who wins the most rounds wins the game.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
- Leo CJJ - Initial work - leocjj
AI that helped me to write the code, comments, and documentation:
Game framework:
- Beta version
- Add more features: obstacles, different ring shapes, etc.
- Add more comments and help.
- Add more documentation.
- Add more examples and tests.
- 2023-11-16: Beta version completed