Cols → Rows ↓ | 3 | 4 | 5 | 6 |
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 ↓ | 3 | 4 | 5 |
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 |
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 22222 First player (MAX) has a guaranteed win. Beginning game. Computer's turn (MAX). ..... ..... ..... ..... The minimax value for this state is: 22222 The best column to move in is: 1 The computers picks: 1 User's turn (MIN). ..... ..... ..... .X... The minimax value for this state is: 22222 The best column to move in is: 0 What column to do you want? 2 Computer's turn (MAX). ..... ..... ..... .XO.. The minimax value for this state is: 22222 The best column to move in is: 1 The computers picks: 1 User's turn (MIN). ..... ..... .X... .XO.. The minimax value for this state is: 22222 The best column to move in is: 1 What column to do you want? 1 Computer's turn (MAX). ..... .O... .X... .XO.. The minimax value for this state is: 22222 The best column to move in is: 2 The computers picks: 2 User's turn (MIN). ..... .O... .XX.. .XO.. The minimax value for this state is: 22222 The best column to move in is: 1 What column to do you want? 4 Computer's turn (MAX). ..... .O... .XX.. .XO.O The minimax value for this state is: 22222 The best column to move in is: 3 The computers picks: 3 User's turn (MIN). ..... .O... .XX.. .XOXO The minimax value for this state is: 22222 The best column to move in is: 0 What column to do you want? 3 Computer's turn (MAX). ..... .O... .XXO. .XOXO The minimax value for this state is: 22222 The best column to move in is: 3 The computers 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. Computer's turn (MAX). .... .... .... .... The minimax value for this state is: 0 The best column to move in is: 0 The computers picks: 0 User's turn (MIN). .... .... .... X... The minimax value for this state is: 0 The best column to move in is: 0 What column to do you want? 3 Computer's turn (MAX). .... .... .... X..O The minimax value for this state is: 0 The best column to move in is: 0 The computers picks: 0 User's turn (MIN). .... .... X... X..O The minimax value for this state is: 0 The best column to move in is: 0 What column to do you want? 0 Computer's turn (MAX). .... O... X... X..O The minimax value for this state is: 0 The best column to move in is: 0 The computers picks: 0 User's turn (MIN). X... O... X... X..O The minimax value for this state is: 0 The best column to move in is: 1 What column to do you want? 3 Computer's turn (MAX). X... O... X..O X..O The minimax value for this state is: 0 The best column to move in is: 1 The computers picks: 1 User's turn (MIN). X... O... X..O XX.O The minimax value for this state is: 0 The best column to move in is: 1 What column to do you want? 3 Computer's turn (MAX). X... O..O X..O XX.O The minimax value for this state is: 0 The best column to move in is: 3 The computers picks: 3 User's turn (MIN). X..X O..O X..O XX.O The minimax value for this state is: 0 The best column to move in is: 1 What column to do you want? 2 Computer's turn (MAX). X..X O..O X..O XXOO The minimax value for this state is: 10666 The best column to move in is: 1 The computers picks: 1 User's turn (MIN). X..X O..O XX.O XXOO The minimax value for this state is: 10666 The best column to move in is: 1 What column to do you want? 2 Computer's turn (MAX). X..X O..O XXOO XXOO The minimax value for this state is: 12307 The best column to move in is: 2 The computers picks: 2 Winner is MAX: X..X O.XO XXOO XXOO