CONNECT
FOUR FAQ Q1 - What
happens if your AI chooses a column that is already full?
Q2 - Can
we submit multiple files for our AI program? 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.
Option 1 Use
g.getSlotOwner(0, 0)
to get the owner of the slot. If the
slot is RED, the owner is player 1. If
BLU, the owner is 2. If the slot is
empty, the owner is 0. String value = gboard[0][0].value; int owner = gboard[0][0].owner(); |
||||||||||||||||||||||||||||||
Q4 – How do I know what player number
I am currently playing as? Your player
number (1 or 2) is passed to you as a parameter to the playMove
method. Q5 – Is there an easy way to know my
opponent’s player number? //Now, you can use
oppPlayerNumber wherever you need it. Q6 – How do I run code once before my
AI starts a game? To run a
segment of code once at the start of each game, then you could simply check
the turnCount.
The variable turnCount variable keeps track
of how many moves have already occurred in the game. Because of
the two random moves, player 1’s first move occurs when two moves have
already be done, or when turnCount
is 2. Similarly, when player 2’s first
move occurs, three moves have already been done, so turnCount
is 3. The following
code would work: { //code to run once }
So you could do something like this: if (g.getTurnCount() == 2 || g.getTurnCount() == 3)
//1st turn { //code to run on first turn } else if (g.getTurnCount() == 4 || g.getTurnCount() == 5)
//2nd turn { //code to run on second turn } else if (g.getTurnCount() == 5 || g.getTurnCount() == 6)
//3rd turn { //code to run on third turn } //and so on… |