Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the basis of the game is already given. we just have to fill out player.java, humanplayer.java, computerrandomplayer.java, and tictactoe.java. heres the template of tictactoe.java. where

image text in transcribed
image text in transcribed
image text in transcribed
the basis of the game is already given. we just have to fill out player.java, humanplayer.java, computerrandomplayer.java, and tictactoe.java. heres the template of tictactoe.java. where it says your code here is where the code should be written. but as for the player.java and etc, you have to do it from scratch
image text in transcribed
image text in transcribed
Player Player is an interface. It defines only one method, the method play. Play is void and has one input parameter, a reference to a Tic Tac ToeGame. HumanPlayer Human Player is a class which implements the interface Player. In its implementation of the method play, it first checks that the game is indeed playable (and prints out an error message is that is not the case), and then queries the user for a valid input, reusing the code that was in the main of the class Tic Tac Toe of assignment 1. Once such an input has been provided, it plays in on the game and returns. ComputerRandom Player Computer Random Player is a class which also implements the interface Player. In its implementation of the method play, it first checks that the game is indeed playable (and prints out an error message is that is not the case), and then chose randomly the next move and plays it on the game and returns. All the possible next moves have an equal chance of being played. Tic Tac Toe This class implements playing the game. You are provided with the initial part very similar to the one from as signment 1. The entire game is played in the main method. A local variable players, a reference to an array of two players, is used to store the human and the computer player. You must use that array to store your Player references You need to finish the implementation of the main to obtain the specified behaviour. You need to ensure that the first player is initially chosen randomly, and that the first move alternate between both players in subsequent games. Below is another sample run, this time on a 4x4 grid with a win length of 2. The human players makes a series of input mistakes along the way. X to play: 2 Player 2's turn Player l's turn TXT 1 101 X to play: 2 This cell has already been played 1 X 1 1 101 X to play: -1 The value should be between 1 and 16 IX II X to play: 3 Game over | XX1 101 Result: XWIN Play again (Y)?:y Player 2's turn. Player l's turn. L XL O to play: 11 This cell has already been played XL O to play: 12 Player 2's turn. Player 1's turn. TIX TIX0 TIL Tictactoe. Notepad Edit Format View File Help public class Tic Tac Toer - mains/b> of the application. Creates the instance of Game Controller - and starts the game. If two parameters line and column are passed, they are used. - Otherwise, a default value is used. Defaults values are also - used if the paramters are too small (less than 2). para args command line parameters public static void main(String[] args) { Student Info.display(); Tic Tac ToeGame game int lines 3; int columns 3; int win - 3; try if (args.length > 2) lines - Integer.parseInt(args[]); if(lines 3){ win - Integer.parseInt(args[2]); if(win(2) System.out.println("Invalid argument, using default...); win = 3; Unix (LF) O Type here to search Tic Tac Toe - Notepad Tile Edit Format View Help int lines - int columns - 3; int win - 3 tryl if (args.length > 2) lines - Integer.parseInt(args[]); if(lines(2) System.out.println("Invalid argument, using default..."); lines - 3; columns - Integer.parseInt(args[1]); if(columns= 3) win - Integer.parseInt(args[2]); if(win ) System.out.println("Invalid argument, using default..."); win = 3; if (args.length > 3){ System.out.println("Too many arguments. Only the first 3 are used."); } catch (Number FormatException e) { System.out.println("Invalid argument, using default..."); lines - 3; columns 3; win = 3; playerl players; // YOUR CODE HERE - Type here to search

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions

Question

Explain the difference between a banks loans and its borrowings.

Answered: 1 week ago