Question: public class Player { private boolean human; private String name; private Player ( boolean human, String name ) { this.human = human; this.name = name;
public class Player
private boolean human;
private String name;
private Playerboolean human, String name
this.human human;
this.name name;
public static Player createHumanString name
return new Playertrue name;
public static Player createComputer
return new PlayerfalseAI;
public boolean isHuman
return human;
public String getName
return name;
public class TestGames
public static void mainString args
TwoPlayerBoardGame game;
game new TicTacToePlayercreateHumanStudent Player.createComputer;
game.play;
game new TicTacToePlayercreateHumanRoy Player.createHumanMoss;
game.play;
game new ConnectFourPlayercreateHumanStudent Player.createComputer;
game.play;
game new ConnectFourPlayercreateHumanJen Player.createHumanMoss;
game.play;
public final class TicTacToe extends TwoPlayerBoardGame
private char XO X;
private int row;
private int col;
public TicTacToePlayer p Player p
supernull p p;
public String toString
return ;
protected void askForMove
protected void receiveMove
row console.nextInt;
col console.nextInt;
protected void generateMove
row Math.absrandomnextInt;
col Math.absrandomnextInt;
protected boolean validMove
return true;
protected void applyMove
protected boolean someoneWon
return false;
protected void celebrateMove
protected void prepareForNextMove
import java.util.Scanner;
import java.util.Random;
public abstract class TwoPlayerBoardGame
protected static final Scanner console new ScannerSystemin;
protected static final Random random new Random;
protected final char board;
private final int MAXMOVES;
protected Player current;
private Player other;
protected TwoPlayerBoardGamechar board, int MAXMOVES, Player p Player p
this.board board;
this.MAXMOVES MAXMOVES;
this.current p;
this.other p;
public final void play
for int i ; i MAXMOVES; i
System.out.printlnthis;
do
if currentisHuman
askForMove;
receiveMove;
else
generateMove;
while validMove;
applyMove;
if someoneWon
System.out.printlnthis;
celebrateMove;
return;
else
prepareForNextMove;
System.out.printlnthis;
System.out.printlnIts a draw.";
protected abstract void askForMove;
protected abstract void receiveMove;
protected abstract void generateMove;
protected abstract boolean validMove;
protected abstract void applyMove;
protected abstract boolean someoneWon;
protected abstract void celebrateMove;
protected void prepareForNextMove
Player tmp current;
current other;
other tmp;
public final class ConnectFour extends TwoPlayerBoardGame
private char RY R;
private int col;
private static final int ROWS ;
private static final int COLS ;
public ConnectFourPlayer p Player p
supernull p p;
public String toString
return ;
protected void askForMove
protected void receiveMove
protected void generateMove
protected boolean validMove
return true;
protected void applyMove
protected boolean someoneWon
return false;
protected void celebrateMove
protected void prepareForNextMove
Open TestGames.java. Understand what it accomplishes.
a Once you have edited TicTacToe.java and ConnectFour.java, this file will allow you to
play TicTacToe and Connect Four against unimpressive AI
b It'll also let two humans play the games against one another.
This will help you to test your games for bugs.
Confirm that you can compile TestGames.java which forces the compilation of Player.java,
TwoPlayerBoardGame.java, TicTacToe.java, and ConnectFour.java As you edit TicTacToe.
java and ConnectFour.java, you should frequently recompile and run Test
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
