Answered step by step
Verified Expert Solution
Question
1 Approved Answer
IN JAVA, Starter code: Program Description Your little brother achieved some amazing results thanks to your program. So you decide to reward him by making
IN JAVA,
Starter code:
Program Description Your little brother achieved some amazing results thanks to your program. So you decide to reward him by making a game for him. In particular, he loves to play tictac-toe with you so you decide to build that. Furthermore, you want him to be able to compete against the computer as well as you. Hence, your game is going to have two modes: (i) single player mode (against the computer) and (ii) two player mode. In two player mode, your program should first ask the players their names and toss a coin to decide who goes first. Then the program should ask the users to take turns playing the game. Ensure that each move is legitimate and print the game result when someone wins or when the game ends in a draw. In one player mode, your program should first ask for the player's name. You will be playing with the computer. Then it should toss a coin to decide who gets to go first. Player one and player two refer to the order in which the players enter their names. Player one gets the ' X ' character while player two gets the ' O ' character. Player one does NOT refer to the player who takes the first turn, since it's based on a coin-flip. When playing one-player mode, the Al will always be player two. Lastly, the menu should repeat unless the user selects the quit option. Menu contains four options that user can select: I. 1. Single player > user will play with computer II. 2. Two player > user will play with another human player III. D. Display last match > displays the last played match IV. Q. Quit -> user wish to quit the game, when selected you should display proper message. Refer to sample output for expected functionality. Hints, edge-cases, and design considerations This is a challenging assignment with many moving parts! It would be a great idea to start early to leave ample time to visit office hours and get help when you're stuck. To get you started, this week we provide starter code in the form of an IntelliJ project folder, which has all the headers of the methods you'd must implement to create the program as well as more specific hints for doing so. You are required to use this starter code and you may modify it by adding additional methods, but do not change the existing methods provided. You can unzip the starter code file to get a project folder. Then, open this in IntelliJ and work with it as you would any other project. Make extensive use of methods to organize your code and break the problem down into manageable pieces. The starter code contains all the method headers you would need for this - the solution we wrote has all these methods and no more than these methods. Start with the two-player game since that'll be most similar to what you're familiar with and makes testing easier. After you have that, the only challenge with the one-player game will be implementing the Al algorithms, as the rest of the game logic will carry over and can be reused. You must use an ArrayList to store the game history, and you must use a 2D char array to store a game state. The starter code has three static variables in the TicTacToe class, which are used to centrally store what symbols in the game represent the empty space, the player one symbol, and the player two symbol. Throughout your code, you must refer to these static variables rather than hard coding the game to rely on ' ', ' X ', and 'O'. You may not add additional static variables to the class. These are effectively used as configuration options for the game. Certain methods in the starter code are marked as private. Since we're only using one class, there is no functional difference. Later in the course you'll see why some have their access from other classes restricted in this way. All methods are static. You'll also see why when we cover what it means for methods and variables to be static in detail. Your program should conform to these edge-case expectations regarding user input: In every menu, check whether the user's choice of menu option is valid and inform them if their choice isn't valid. When inputting positions on the board, you do not need to handle non-numerical or non-integer inputs. Assume they will only input integers. However, you should check that the integers they inputted are valid. This means their input should both be within the 33 grid and should be an unoccupied space. Inform the user if their input was invalid and which of these two rules it broke. // Given a game state, return an ArrayList of [row, column] positions that are unclaimed on the board no usages private static ArrayList getValidMoves(char[][] gameState) \{ // TODO return null; // Given player names and the game history, display the past game as in the PDF sample code output no usages private static void rungameHistory(String[] playerNames, ArrayList gameHistory) \{ // TOD0 // We have the names of the players in the format [playeroneName, playerTwoName] // Player one always gets 'X' while player two always gets '0' // However, we do not know yet which player went first, but we'll need to know... // Hint for the above: which symbol appears after one turn is taken? // Hint: iterate over gameHistory using a loop \}Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started