Project Description & Template : https://www.overleaf.com/read/gcpfjdpqpytp
To setup the game, clone this repository and install the dependencies:
pip install -r requirements.txt
To start playing a game, we need to implement agents. For example, to play the game using two random agents (agents which take a random action), run the following:
python simulator.py --player_1 random_agent --player_2 random_agent
This will spawn a random game board of size NxN, and run the two agents of class RandomAgent. You will be able to see their moves in the console.
To visualize the moves within a game, use the --display
flag. You can set the delay (in seconds) using --display_delay
argument to better visualize the steps the agents take to win a game.
python simulator.py --player_1 random_agent --player_2 random_agent --display
To play the game on your own, use a human_agent
to play the game.
python simulator.py --player_1 human_agent --player_2 random_agent --display
Since boards are drawn randomly (between a MIN_BOARD_SIZE
and MAX_BOARD_SIZE
) you can compute an aggregate win % over your agents. Use the --autoplay
flag to run --autoplay_runs
.
python simulator.py --player_1 random_agent --player_2 random_agent --autoplay
During autoplay, boards are drawn randomly between size --board_size_min
and --board_size_max
for each iteration.
Notes
- Not all agents supports autoplay. The variable
self.autoplay
in Agent can be set toTrue
to allow the agent to be autoplayed. Typically this flag is set to false for ahuman_agent
. - UI display will be disabled in an autoplay.
You need to write your own agent and submit it for the class project. To do so:
-
Modify the
student_agent.py
file inagents/
directory, which extends theagents.Agent
class. -
Implement the
step
function with your game logic -
Register your agent using the decorator
register_agent
. TheStudentAgent
class is already decorated withstudent_agent
name, feel free to change it or keep it the same. -
[This step is already done for
StudentAgent
] Import your agent in the__init__.py
file inagents/
directory -
Run and test your agent using the information above
python simulator.py --player_1 random_agent --player_2 student_agent --display
-
Check autoplay with your agent and
random_agent
is workingpython simulator.py --player_1 random_agent --player_2 student_agent --autoplay
python simulator.py -h
usage: simulator.py [-h] [--player_1 PLAYER_1] [--player_2 PLAYER_2]
[--board_size BOARD_SIZE] [--display]
[--display_delay DISPLAY_DELAY]
optional arguments:
-h, --help show this help message and exit
--player_1 PLAYER_1
--player_2 PLAYER_2
--board_size BOARD_SIZE
--display
--display_delay DISPLAY_DELAY
--autoplay
--autoplay_runs AUTOPLAY_RUNS
On an M x M chess board, 2 players are randomly distributed on the board with one player occupying one block.
In each turn, one player moves at most K
steps (between 0
and K
), where each step can be in either horizontal or vertical direction, and must put a barrier around him or her in one of the 4 directions except the boarders of the chess board. The players move in a round-robin way.
- Each player cannot go into other player's place or put barriers in areas that already have barriers.
- Currently the maximal number of steps is set to
K = (M + 1) // 2
.
The game ends when each player is separated in a closed zone by the barriers and boundaries. The final score for each player will be the number of blocks in that zone.
Each player should maximize the final score of itself, i.e., the number of blocks in its zone in the endgame.
Here we show a gameplay describing a
The final score is
Feel free to open an issue in this repository, or contact us in Ed thread.
This is a class project for COMP 424, McGill University, Winter 2022.