Project 2: Connect Four: Part B Details

General information

Because Part B uses a cut-off depth and heuristics, the computer player may not win all the time even when it can. For instance, in the full version of Connect Four, with 6 rows and 7 columns, the first player has a guaranteed win. Your program does not need to win all the time when asked to play on this size board, particularly if the cut-off depth d is small. That being said, for a reasonably good heuristic, I find that my computer player can beat me most of the time if I let it look ahead even five moves. It will certainly prevent me from winning, though we may tie sometimes.

My heuristic in Parts B and C is 10 points for each 3-in-a-row found in the game board, and 3 points for each 2-in-a-row. Points are positive for MAX and negative for MIN. A win for MAX is +100000 and a win for MIN is -100000. Note that this heuristic doesn't even look for open spaces on the ends of the 3-in-a-rows or 2-in-a-rows, so it will make dumb moves every so often.

Output

Here is an example of how the program for Part B might look. I include a lot of diagnostic messages (such as the minimax value and best moves) which you do not have to report, but are useful for testing.

Enter rows: 6
Enter columns: 7
Enter n-in-a-row: 4
Enter cutoff depth: 5
Playing game with rows=6, cols=7, and n-in-a-row=4

Beginning game.

It is the computer's turn (MAX).
.......
.......
.......
.......
.......
.......

Minimax calculation completed in 19.19 ms
Transposition table has 885 states.
The minimax value for this state is 13
The best column to move in is 0
The computer picks 0

It is the user's turn (MIN).
.......
.......
.......
.......
.......
X......

Minimax calculation completed in 1.612 ms
Transposition table has 237 states.
The minimax value for this state is 0
The best column to move in is 0
What column to move in? 3

It is the computer's turn (MAX).
.......
.......
.......
.......
.......
X..O...

Minimax calculation completed in 8.102 ms
Transposition table has 769 states.
The minimax value for this state is 16
The best column to move in is 0
The computer picks 0

It is the user's turn (MIN).
.......
.......
.......
.......
X......
X..O...

Minimax calculation completed in 1.144 ms
Transposition table has 284 states.
The minimax value for this state is 3
The best column to move in is 0
What column to move in? 4

It is the computer's turn (MAX).
.......
.......
.......
.......
X......
X..OO..

Minimax calculation completed in 1.804 ms
Transposition table has 233 states.
The minimax value for this state is 43
The best column to move in is 0
The computer picks 0

It is the user's turn (MIN).
.......
.......
.......
X......
X......
X..OO..

Minimax calculation completed in 3.170 ms
Transposition table has 567 states.
The minimax value for this state is -3
The best column to move in is 0
What column to move in? 0

It is the computer's turn (MAX).
.......
.......
O......
X......
X......
X..OO..

Minimax calculation completed in 9.704 ms
Transposition table has 1250 states.
The minimax value for this state is 23
The best column to move in is 5
The computer picks 5

It is the user's turn (MIN).
.......
.......
O......
X......
X......
X..OOX.

Minimax calculation completed in 5.822 ms
Transposition table has 1303 states.
The minimax value for this state is -26
The best column to move in is 3
What column to move in? 4

It is the computer's turn (MAX).
.......
.......
O......
X......
X...O..
X..OOX.

Minimax calculation completed in 9.795 ms
Transposition table has 1659 states.
The minimax value for this state is 0
The best column to move in is 1
The computer picks 1

It is the user's turn (MIN).
.......
.......
O......
X......
X...O..
XX.OOX.

Minimax calculation completed in 5.155 ms
Transposition table has 1547 states.
The minimax value for this state is -33
The best column to move in is 3
What column to move in? 5

It is the computer's turn (MAX).
.......
.......
O......
X......
X...OO.
XX.OOX.

Minimax calculation completed in 9.189 ms
Transposition table has 1273 states.
The minimax value for this state is 7
The best column to move in is 4
The computer picks 4

It is the user's turn (MIN).
.......
.......
O......
X...X..
X...OO.
XX.OOX.

Minimax calculation completed in 3.521 ms
Transposition table has 1181 states.
The minimax value for this state is -43
The best column to move in is 3
What column to move in? 5

It is the computer's turn (MAX).
.......
.......
O......
X...XO.
X...OO.
XX.OOX.

Minimax calculation completed in 6.589 ms
Transposition table has 1509 states.
The minimax value for this state is -10
The best column to move in is 1
The computer picks 1

It is the user's turn (MIN).
.......
.......
O......
X...XO.
XX..OO.
XX.OOX.

Minimax calculation completed in 8.372 ms
Transposition table has 1288 states.
The minimax value for this state is -40
The best column to move in is 5
What column to move in? 6

It is the computer's turn (MAX).
.......
.......
O......
X...XO.
XX..OO.
XX.OOXO

Minimax calculation completed in 4.684 ms
Transposition table has 930 states.
The minimax value for this state is 73
The best column to move in is 1
The computer picks 1

It is the user's turn (MIN).
.......
.......
O......
XX..XO.
XX..OO.
XX.OOXO

Minimax calculation completed in 2.217 ms
Transposition table has 594 states.
The minimax value for this state is 0
The best column to move in is 1
What column to move in? 1

It is the computer's turn (MAX).
.......
.......
OO.....
XX..XO.
XX..OO.
XX.OOXO

Minimax calculation completed in 5.288 ms
Transposition table has 1357 states.
The minimax value for this state is 43
The best column to move in is 3
The computer picks 3

It is the user's turn (MIN).
.......
.......
OO.....
XX..XO.
XX.XOO.
XX.OOXO

Minimax calculation completed in 3.744 ms
Transposition table has 1146 states.
The minimax value for this state is 20
The best column to move in is 5
What column to move in? 6

It is the computer's turn (MAX).
.......
.......
OO.....
XX..XO.
XX.XOOO
XX.OOXO

Minimax calculation completed in 9.218 ms
Transposition table has 760 states.
The minimax value for this state is 47619
The best column to move in is 2
The computer picks 2

It is the user's turn (MIN).
.......
.......
OO.....
XX..XO.
XX.XOOO
XXXOOXO

Minimax calculation completed in 2.083 ms
Transposition table has 632 states.
The minimax value for this state is 47619
The best column to move in is 0
What column to move in? 5

It is the computer's turn (MAX).
.......
.......
OO...O.
XX..XO.
XX.XOOO
XXXOOXO

Minimax calculation completed in 2.159 ms
Transposition table has 450 states.
The minimax value for this state is 47619
The best column to move in is 2
The computer picks 2
Winner is MAX:
.......
.......
OO...O.
XX..XO.
XXXXOOO
XXXOOXO