CONNECT
FOUR LESSON WORK TASK
THE GAME 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 not winning line and the board is full, then the game is a tie. TWIST TO THE 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
KEY FILES You
will need the following files: Game.java
– The actual game with the main function. Slot.java
– A class to create objects that represent the slots in the game. OTHER FILES CampeauAI01.java
– A simple AI agent 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.java
– A simple AI agent 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. TournamentAI.java
– A file that allows you to setup a tournament between different AI agents. You do not need to worry about this file
while creating your AI. ZIP FILE Click
here for a
zip file that contains all of the required files to test your AI. You will have to drag each one individually
into your IDE. Run Game.java. TOURNAMENT ZIP FILE
WHERE TO START (WE WILL
DO THIS TOGETHER) You first need to know how to play the game. You then need to know how to run the
software. Setting player1 to “human”
and player2 to “randomAI” is a good start.
Play a few games. Try the other
settings. You then need to create your own class called
YourNameAI.java. You should start by
copying RandomAI.java into it. Then
you can start making your own code. Note: The RandomAI provided with these files has a
fatal flaw. It returns a random column
number. If that column happens to be
full, that AI loses its turn.
Therefore, you would be better off improving that RandomAI so that it
doesn’t return a column number that is full (very easy to do). Doing so would give you a better testing
opponent for your own AI. API Click here. 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. 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. Q
& A Q: Reasoning: Imagine the scenario where there are two spots
left one above the other and if RED gets to go last, it will win the game on
the final move. However, it is
actually RED’s turn now so RED won’t get that spot. Unless red skips a turn. This would be a brilliant move, but if BLU
also realizes this, we can end up in an infinite loop situation with both
players continuously skipping their turn. Q: A: Yes, you can submit a few files. Since most students will have only one
file, you can just reserve a filename (that we can share with others in
class). Of course, if this proves to be too difficult to
manage, we will come up with another system. |
|