Project 2: Connect Four: Part A Details

Guaranteed Wins

Here are the details of guaranteed wins for Connect-Three for various board sizes, along with the total number of possible states of the game, and roughly how long it took my computer to run minimax on the state space. My code is in C++ on a relatively modern laptop; your code, especially if in Python, may run slower.
Cols →
Rows ↓
3456
3 Tie
< 1 sec
694 states
1st player wins
< 1 sec
7157 states
1st player wins
< 1 sec
70914 states
1st player wins
~12 sec
692970 states
4 Tie
< 1 sec
2715 states
1st player wins
< 1 sec
41750 states
1st player wins
~10 sec
613459 states
5 Tie
< 1 sec
8789 states
1st player wins
~2 sec
195472 states
6 Tie
< 1 sec
25753 states
1st player wins
~17 sec
844488 states

Here are the details of guaranteed wins for Connect-Four for various board sizes.
Cols →
Rows ↓
345
3 Tie
< 1 sec
12031 states
Tie
~2 sec
158911 states
4 Tie
< 1 sec
6000 states
Tie
~2 sec
161029 states
5 Tie
< 1 sec
38310 states
6 Tie
~3 sec
235781 states

Output

Here is an example of how the program for Part A 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.

Example where MAX (the computer) will win no matter what:

Enter rows: 4
Enter columns: 5
Enter n-in-a-row: 3
Playing game with rows=4, cols=5, and n-in-a-row=3
Calculating minimax for entire game tree.

Minimax calculation completed in 7.224 s
Transposition table has 613459 states.
Minimax value of start state is 1111
First player (MAX) has a guaranteed win.

Beginning game.

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

The minimax value for this state is 1111
The best column to move in is 1
The computer picks 1

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

The minimax value for this state is 1111
The best column to move in is 3
What column to move in? 2

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

The minimax value for this state is 1111
The best column to move in is 1
The computer picks 1

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

The minimax value for this state is 1111
The best column to move in is 1
What column to move in? 1

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

The minimax value for this state is 1111
The best column to move in is 2
The computer picks 2

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

The minimax value for this state is 1111
The best column to move in is 1
What column to move in? 4

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

The minimax value for this state is 1111
The best column to move in is 3
The computer picks 3

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

The minimax value for this state is 1111
The best column to move in is 1
What column to move in? 3

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

The minimax value for this state is 1111
The best column to move in is 3
The computer picks 3
Winner is MAX:
.....
.O.X.
.XXO.
.XOXO

Example where MAX (the computer) will normally tie if MIN (the user) plays optimally, but the user makes lots of mistakes here and the computer eventually wins:

Enter rows: 4
Enter columns: 4
Enter n-in-a-row: 4
Playing game with rows=4, cols=4, and n-in-a-row=4
Calculating minimax for entire game tree.
Minimax calculation completed in 1.464 s
Transposition table has 161029 states.
Minimax value of start state is 0
Neither player has a guaranteed win; game will end in tie with perfect play on both sides.

Beginning game.

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

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).
....
....
....
.X..

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).
....
....
.O..
.X..

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).
....
.X..
.O..
.X..

The minimax value for this state is 0
The best column to move in is 1
What column to move in? 2

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

The minimax value for this state is 0
The best column to move in is 3
The computer picks 3

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

The minimax value for this state is 0
The best column to move in is 1
What column to move in? 3

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

The minimax value for this state is 0
The best column to move in is 2
The computer picks 2

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

The minimax value for this state is 0
The best column to move in is 1
What column to move in? 0

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

The minimax value for this state is 0
The best column to move in is 3
The computer picks 3

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

The minimax value for this state is 0
The best column to move in is 2
What column to move in? 0

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

The minimax value for this state is 769
The best column to move in is 2
The computer picks 2

It is the user's turn (MIN).
....
.XXX
OOXO
OXOX

The minimax value for this state is 769
The best column to move in is 1
What column to move in? 0

It is the computer's turn (MAX).
....
OXXX
OOXO
OXOX

The minimax value for this state is 769
The best column to move in is 0
The computer picks 0
Winner is MAX:
X...
OXXX
OOXO
OXOX