Board The computer will simulate a rectangular 6 x 7 (height 6, width 7) grid for the board. You are required to use a 2
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Board The computer will simulate a rectangular 6 x 7 (height 6, width 7) grid for the board. You are required to use a 2
Opponent Al Allowing the user make their moves is only half the battle. You are required to write a method to make the opponent's moves. In its most basic form, this AI would randomly choose a valid cocedinate. However, you are required to make some non-trivial extension to this hasic framework. Some options are listed below: The Al always moves to block a chain of four pieces if the user currently has 3 in a row (or 4 in expert mode). • The Al is more likely to move near where the user made their last move. The AI is able to recognize when they have 3 pieces in a row, and will win the game whenever they have the opportunity to do so. If you would like to pursue a different ides, feel free to do so. Any extension the Al should require enough extra code to be non-trivial. What counts as "non-trivial" is left to the discretion of the ggraclers. Debug Mode In normal gameplay, the game board is only printed when the user asks for it. However, for grading purposes, you are required to add a debug mode. The game should ask the user whether to run in debug mode and set a flag internally. If the game is in debug mode, print the game board on the screen before every move (twice per turn). This means printing the entire grid, as well as 'X' and 'O' depending on whether a space is taken up by the user or the Al opponent. A space that neither player has moved in yet should be represented by This should be formatted as a grid. If the game is not in debug mode, you should only print the board if the user asks for it.
Getting Started We recommend starting by making the Board class that contains your 2D Array or board. You should first set up the functionality to correctly size the array depending on if the user selects a standard or expert game mode. Implement the print command to help you see the board and make sure that you are able to accurately place a piece by dropping it down as far as it can go before hitting another piece or the bottom of the board in any given column. Board Class • Contains a 2D Array with type of your choosing • Contains int variable to keep tracks of total turns • Constructor takes two int variables as arguments and correctly sizes the array upon construc- tion • Has drop(int col, char player) function to handle either player dropping their piece in a column • Has display() function to print out the board if a player types in the print command (or every turn if in debug mode) • Has connects Four() method to determine whether a given board state contains any rows, columns, or diagonals of four consecutive pieces of the same type. There should be a similar method called connectsFive() for expert mode Game Class The main function should be in here. Should create and initialize a Board object. Should use Scanner to take in user input until game end . Can also contain any helper functions that you may find helpful. It will be very important to have a method to determine the AI opponent's move