Requirement
In this project you will help determine the best moves for an abbreviated game of Connect4. The program will analyze the best starting position to make a move. Due to processing times our Connect4 board will be 4 x 4, versus the actual 7x7 board of the game.
The program will explore making its first move in each of the four columns. The first action will be to make a move in one of the four columns. The program will then pass the Board, and the next player to a Play method. The Play method will analyze the board and call itself up to 4 times, representing the possible number of next moves. At times the Play method may call itself less than four times due to the condition that a column is full. The Play method will return a 1 if the game is won by the first player, -1 if won by the second player, and zero, if that moves leads to a tie. Hence Play (board, clr) gives you the Net wins for first player, given the board position represented by board, and the next move is to be taken by clr.
A game is won if 4 discs of the same color appear in a column, row or diagonal.
Helpful code
Code is provided to do the same type of logic as this problem, except with a Tic Tac Toe Board. In the Tic Tac Toe game, after the first move, there are 8 possible moves by the second player. In Connect4, with our abridged board, there are always a maximum of 4 next moves. Also in the Tic Tac Toe game the next move can be anywhere on the Board, while in Connect4, only the bottom of an open column can be chosen for the next move.
Tic Tac Toe Program Logic
The logic of the program provided prints out information for X making the first move in one of the three spaces of a diagonal. In the Main method, within a loop iterating through the 3 diagonal spaces, the program makes a first move and then calls Play , passing the current board state, and next player.
Within Play, the method first checks to see if the current board has a winning position for either player. If so, 1(X) or -1(O) is returned. Also a non-winning full board is checked. If the board is full, with no winner, then zero is returned. The CheckBoard method does this analysis of the board.
If the board is not a complete game, CheckBoard returns 3. This result prompts Play to recursively call itself with all possible moves for the current player. The current board array is copied to another array. to ensure future executions of the method do not alter the current board.
Expected Results
It is advised to make your Connect4 program also work on a 3 by 3 matrix. This is easier to test with, since the 4x4 does take more processing. If you run a 3x3 Connect4 game , these are the results you should achieve:1
2
3
4
5
6
7
8
9
10
11
12NetWins for column 0: 112
Number of recursion calls: 1087
Red Wins:224 Blue Wins: 112
******************
NetWins for column 1: 6
Number of recursion calls: 1103
Red Wins:168 Blue Wins: 162
******************
NetWins for column 2: 112
Number of recursion calls: 1087
Red Wins:224 Blue Wins: 112
******************
Running the program
The zipped java project file, which contains all your source code, input files and Eclipse related projects, is to be submitted You may include more than one test file to indicate your program is working.
Working on This request
You should modularize your design so that you can test it regularly. Make sure that at all times you have a working program. You can implement methods that perform one task at a time. This way, if you run out of time, at least parts of your program will be functioning properly.
Final step (optional)
When considering the next possible moves, if the player can win, have that player only make that move. For example, if all four columns have an opening, but moving in column 3 wins the game, only recursively call moving in column 3.