CONNECT
FOUR
TOPIC 03v2 – CONNECT FOUR AI

LESSON WORK

TASK
- You will create an AI agent that will play Connect
Four (Version 2.X).
SOFTWARE
- You will be given the implementation of a text-based
Connect Four game.
- The software will support the running of a single game with all moves
displayed in the console. This
single game can be between two humans, two AIAgents
or a human versus an AIAgent.
- The software will also support the running of a series of games. A series of games is ran efficiently by turning off the move-by-move
display. This way, a large number
of games (such as 1000) can be ran and results could be seen without any
delays. A series is between two AIAgents, each getting their turn as the first
player and the second player.
- The software will also support the running of a tournament. A tournament is a round-robin
tournament between all specified AIAgents. Each AIAgent
plays a series against each other AIAgent and
the software will output results for each series and at the end will
show the total records of all AIAgents to
determine the top three winners.
- Along with the software for the game, you will also
receive a few basic implementations of different AIAgents.
OUR COMPETITION
- Each student will create an AIAgent
that will play Connect Four.
- Using the tournament option in the software, all
student AIAgents will face off against all
other agents to see which work best.
The result of our tournament will determine our top three AI
Champions.
- All student AIAgents will
play a series (probably 1000 games) against each other AIAgents.
They will play of the games as the first player and half as the
second player.
- The point system used will be:
Win: 1 point
Tie: 0 points
Loss: 0 points
So, the AIAgent with the most wins will be
crowned this year’s champion.
- Mr. Campeau will provide an AI agent as well to
participate in the competition.
- A random AIAgent will also
participate. (Easy wins…)
ABOUT CONNECT FOUR
- The game board consists of six rows and seven
columns of slots. There are two
players in the game. Turn by
turn, a player drops a chip into one of the columns and it falls to the
bottommost empty slot.

- The player that first
makes a straight line of four consecutive chips with their colour wins the game. The winning line could be vertical,
horizontal or diagonal. If there
is no winning line and the board is full, then the game is a tie.
TWIST TO OUR GAME
- For the
tournament, the first move for each player will be done randomly. This is done to ensure that we don’t
have the exact same game being repeated over and over between 2 AI
agents.
IMPLEMENTATION FILES
- Here are the files:
- Tester.java – Contains the main function. Allows you to run a single game, a
series of games or a tournament.
- Game.java – The code needed to run a single game.
- Series.java – The code needed to run a series of
games.
- Tournament.java – The code needed to run a
tournament between any number of AIAgents.
- Slot.java – A class that represents a single slot
on the board.
- AIAgent.java – An interface that specifies all of
the methods that your AI bots need to have to be functional with this
software.
- You will also receive a few implemented AIAgents.
GAMEBOARD IMPLEMENTATION
DETAILS
- Each possible placement on the board is a slot. The board consists of 6 rows and 7
columns of slots for a total of 42 slots.
- The bottom row is row 0 and the top row is row
5. The leftmost column is column
0 and the rightmost column is column 6.
See the diagram below.

Note: This diagram was updated for Version
2.X of the software.
- Each slot is open or contains a chip owned by player
1 or player 2.
PROVIDED AI AGENTS
- You will be provided with a few implemented AIAgents.
- RandomAI01 – An AIAgent
that randomly picks one of the columns to drop a chip into.
- RandomAI02 – A small improvement over a
RandomAI01. This AIAgent picks a random column that is not already
full (avoiding losing a game for an illegal move).
- CampeauAI01 – A simple AIAgent
that associates a value to each spot on the board. It then considers the 7 spots that it
can select and chooses the one with the best value.
- CampeauAI02 – A simple AIAgent
that checks if it can win this move.
If it can, it does that selection. Otherwise, it uses the basic RandomAI strategy of returning a random column
number.
ABOUT THE AIAGENT
INTERFACE
- Your AI program needs to be in a class called
YourNameAI.java. So as student
named BillyBob will code inside a class called
BillyBobAI.java.
- Your AI program needs to be in a class that
implements the AIAgent interface. This interface contains 7
methods. The playMove
method is the most important part of your program while other methods
are less important.
- The int
playMove(Game g, int playerNumber) method is automatically called
when it is your AI’s turn to choose a column in which to drop a
chip. It receives a clone of the
game object (not the original object) so that it could decide what move
to make.
- You will learn about how to access the Game object
during your teacher’s demo.
TIPS
Be organized!
Your program will potentially grow considerably.
Use functions when possible so that you can easily
reused them in later AI programs.
Once you have a functioning AI program, save it
somewhere. Either duplicate the class
or dump the code in another file. If
you just alter it, you have a difficult time coming back to it later. Plus, having two different versions of your
AI will allow you to test one versus the other.
Start small.
Create a few simple AI programs and test them. It is a lot of fun watching your “babies”
(I mean AI programs) play the game.
Avoid making AI programs that are only for player 1. Try to make your programs work for both
player 1 and player 2.

|