This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you.
public class Cell
{
// Displays 'B' for the black disk player.
public static final char BLACK = 'B';
// Displays 'W' for the white disk player.
public static final char WHITE = 'W';
// Displays '*' for the possible moves available.
public static final char CANSELECT = '*';
// If the cell is empty or not.
public boolean empty;
// If the cell can be selected or not.
public boolean canselect;
// empty = -1 , white = 0 , black = 1
public int value;
/**
* Class constructor. Cell is empty by default.
*/
public Cell()
{
this.empty = true;
this.value = -1;
}
/**
* Checks if cell is empty or not.
*/
public boolean isEmpty()
{
return this.empty;
}
/**
* Returns player's number.
*/
public int getPlayer()
{
return this.value;
}
/**
* Places a chip in the cell.
*/
public void placeChip(int player)
{
this.empty = false;
this.value = player;
}
/**
* Changes the colour value of chip (0,1).
*/
public void changeChip()
{
placeChip((value + 1) % 2);
}
/**
* Makes cell possible to select/choose.
*/
public void setSelect()
{
this.canselect = true;
}
/**
* Makes the cell selectable.
*/
public boolean canSelect()
{
return this.canselect;
}
/**
* Makes the cell not selectable.
*/
public void unselect()
{
this.canselect = false;
}
/**
* Displays the cell so that valid moves are *, black is B, and white is W.
*/
public void display()
{
// If the cell is empty.
if (this.isEmpty())
{
// If the cell can be selected.
if (this.canselect)
{
System.out.print("[ " + CANSELECT + " ]"); // Print "*."
}
// Prints a empty space.
else
{
System.out.print("[ " + " " + " ]");
}
}
else
{
char content = BLACK;
if (this.value == 0)
{
content = WHITE;
System.out.print("[ " + content + " ]"); // For black "B" & for white "W."
}
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.util.ArrayList;
public class Board
{
// 8 rows by 8 columns board.
public static final int num = 8;
// Matrix
private Cell[][] cell = new Cell[num][num];
// Counter for both players moves.
int[] counter = new int[2];
// Game over.
boolean gameOver;
final static int BLACK = 1;
final static int WHITE = 0;
public final Move up = new Move(0, -1); // Up
public final Move down = new Move(0, 1); // Down
public final Move left = new Move(-1, 0); // Left
public final Move right = new Move(1, 0); // Right
public final Move upLeft = new Move(-1, -1); // Up and left
public final Move upRight = new Move(1, -1); // Up and right
public final Move downLeft = new Move(-1, 1); // Down and left
public final Move downRight = new Move(1, 1); // Down and right
// Array of possible directions.
final Move directions[] = { up, down, left, right, upLeft, upRight, downLeft, downRight };
public Board()
{
// Goes through the whole board.
for (int row = 0; row < num; row++)
{
// Sets all the cells to be empty.
for (int col = 0; col < num; col++)
{
this.cell[row][col] = new Cell();
}
}
// 1 for black.
this.cell[3][4].placeChip(1);
this.cell[4][3].placeChip(1);
// 0 for white .
this.cell[3][3].placeChip(0);
this.cell[4][4].placeChip(0);
// Start counter at 2 for each player.
counter[0] = 2; // White player
counter[1] = 2; // Black player
// Allows moves at start of game.
gameOver = false;
}
/**
* Gets the cell clicked.
* Row selected.
* Col selected.
*/
public Cell getCell(int row, int col)
{
return cell[row][col];
}
/**
* Gets the row of the selected cell.
*/
public int getNumRows()
{
return cell.length;
}
/**
* Gets the col of the selected cell.
*/
public int getNumCols()
{
return cell[0].length;
}
/**
* Displays the board with row and col numbers.
*/
public void display()
{
for (int i = 0; i < num; i++)
{
System.out.print(i + " ");
for (int j = 0; j < num; j++)
{
this.cell[i][j].display();
}
System.out.println(" ");
}
System.out.print(" ");
for (int j = 0; j < num; j++)
{
System.out.print(" " + j + " ");
}
System.out.println();
}
/**
* Displays the winner of the game.
*/
public void winner()
{
if (getChipsCount(0)<getChipsCount(1))
{
System.out.println("Black Won!");
}
else if(getChipsCount(1)<getChipsCount(0))
{
System.out.println("White Won!");
}
}
/**
* Displays the scores of both players.
*/
public void scoreDisplay()
{
System.out.println("White score: " + getChipsCount(0));
System.out.println("Black score: " + getChipsCount(1));
System.out.println();
}
/**
* Finds all the valid and available moves of current player.
*/
public boolean findLegalMove(Move move, int player)
{
// No legal moves found by default.
boolean result = false;
// Finds the opponent.
int opponent = (player + 1) % 2;
// Player playing.
int cPlayer = player;
int i = move.getI(); // Gets the position of i axis.
int j = move.getJ(); // Gets the position of j axis.
// Checks if the cell is empty.
if (cell[i][j].isEmpty() == false)
{
return false; // If the cell is not empty, no moves will be available.
}
else
{
// Gets all the directions.
for (int k = 0; k < directions.length; k++)
{
Move direction = directions[k];
int iDir = direction.getI(); //Gets i and j axis.
int jDir = direction.getJ();
int jump = 2; // Jumps one chip.
try {
if (cell[i + iDir][j + jDir].getPlayer() == opponent)
{
while ((j + (jump * jDir)) > -1 && (j + (jump * jDir)) < 8 && (i + (jump * iDir)) < 8 && (i + (jump * iDir)) > -1)
{
// If cell cannot be empty.
if (!cell[i + jump * iDir][j + jump * jDir].isEmpty())
{
if (cell[i + jump * iDir][j + jump * jDir].getPlayer() == cPlayer)
{
return true;
}
else if (cell[i + jump * iDir][j + jump * jDir].isEmpty())
{
break;
}
}
else
{
break;
}
jump++; // Jumps another extra chip.
}
}
}
catch (Exception e)
{
}
}
}
// If true, move found. If false, no moves found.
return result;
}
/**
* Places the chip on the board
*/
public void placeChip(int colour, int row, int col)
{
this.cell[row][col].placeChip(colour);
}
/**
* An array list of all valid moves available.
*/
public ArrayList<Move> validMoves(int colour)
{
ArrayList<Move> allValidMoves = new ArrayList<Move>();
for (int i = 0; i < cell.length; i++)
{
for (int j = 0; j < cell.length; j++)
{
cell[i][j].unselect();
Move testMove = new Move(i, j);
boolean valid = findLegalMove(testMove, colour);
if (valid)
{
allValidMoves.add(testMove);
}
}
}
return allValidMoves;
}
/**
* Allows the cell to be selected.
*/
public void setCanSelect(Move move)
{
this.cell[move.getI()][move.getJ()].setSelect();
}
/**
* Allows the cell to be selected
*/
public boolean canSelect(Move move)
{
return this.cell[move.getI()][move.getJ()].canSelect();
}
/**
* Replaces the chip(s) in between the players old and current chip.
*/
public void replaceChip(Move move, int player)
{
int opponent = (player + 1) % 2;
int playing = player;
int i = move.getI();
int j = move.getJ();
for (int movement = 0; movement < directions.length; movement++)
{
Move direction = directions[movement];
int iDir = direction.getI();
int jDir = direction.getJ();
boolean possible = false;
// Checks for the opponent in the all directions.
if ((j + jDir) > -1 && (j + jDir) < num && (i + iDir) < num && (i + iDir) > -1)
{
if (cell[i + iDir][j + jDir].getPlayer() == opponent)
{
possible = true;
}
}
if (possible == true)
{
int jump = 2;
while ((j + (jump * jDir)) > -1 && (j + (jump * jDir)) < 8 && (i + (jump * iDir)) < 8 && (i + (jump * iDir)) > -1)
{
// Thecell cannot be emptied.
if (!cell[i + jump * iDir][j + jump * jDir].isEmpty())
{
if (cell[i + jump * iDir][j + jump * jDir].getPlayer() == playing)
{
for (int k = 1; k < jump; k++)
{
cell[i + k * iDir][j + k * jDir].changeChip();
}
break;
}
jump++;
}
}
}
}
}
/**
* Updates the number/counter/disks of chips on the board per player.
*/
public int getChipsCount(int colour)
{
int score = 0;
for (int i = 0; i < num; i++)
{
for (int j = 0; j < num; j++)
{
if (cell[i][j].getPlayer() == colour)
{
score++;
}
}
}
return score;
}
/**
* Checks if all the 64 chips have been placed on board which then means the game is over.
*/
public boolean gameOver()
{
int count = 0;
// If cells are full, game over.
if (counter[0] + counter[1] == 64)
{
return true;
}
else
{
for (int j = 0; j < num; j++)
{
for (int i = 0; i < num; i++)
{
if (findLegalMove(new Move(i, j), 0) == true)
{
count++;
}
if (findLegalMove(new Move(i, j), 1) == true)
{
count++;
}
}
}
// If there is no legal moves left then the game will be over.
if (count == 0)
{
return true;
}
}
return false;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class Player
{
Scanner kb = new Scanner(System.in);
// Player's name.
private String name;
// Colour of the chips.
private int colour;
// Board
private Board board;
/**
* Creates a player.
*/
public Player(String name, int colour, Board board)
{
this.name = name;
this.colour = colour;
this.board = board;
}
/**
* Places the piece for the chosen player at the chosen location. Replaces the piece in between
* the old piece and the new piece to the players colour.
*/
public void placeChip(int row, int col)
{
this.board.placeChip(this.colour, row, col);
Move move = new Move(row, col);
this.board.replaceChip(move, this.colour);
}
/**
* Sets the players name to a variable.
*/
public void setNames() throws IOException
{
System.out.println("What is your name: ");
String line = kb.nextLine();
this.name = line;
}
/**
* Gets the name of the player.
*/
public String getName()
{
return this.name;
}
/**
* Gets the colour number of the player.
*/
public int getcolour()
{
return this.colour;
}
/**
* Finds valid moves, and allows them to be selected.
*/
public void findCanSelect()
{
ArrayList<Move> moves = board.validMoves(this.colour);
for (Move move : moves)
{
board.setCanSelect(move);
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------
public class Turn
{
// The players number.
private int value;
/**
* Creates a turn starting with a random player.
*/
public Turn()
{
this.value = (int) (Math.random() * 2.0d);
}
/**
* Creates a turn starting with the selected first player.
*/
public Turn(int v)
{
this.value = v;
}
/**
* Returns the player whose turn it is.
*/
public int getTurn()
{
return this.value;
}
/**
* Changes the turn to the other player.
*/
public void change()
{
this.value = (this.value + 1) % 2;
}
}
-------------------------------------------------------------------------------------------------------
class Move
{
// Position on i and j axis.
int i;
int j;
/**
* Creates the directions on the i and j axis.
*/
public Move(int i, int j)
{
this.i = i;
this.j = j;
}
/**
* Gets the location of the position on the i axis.
*/
public int getI()
{
return i;
}
/**
* Gets the location of the position on j axis.
*/
public int getJ()
{
return j;
}
}
---------------------------------------------------------------------------------------------------------
import java.io.IOException;
import java.util.Scanner;
public class Driver
{
Scanner kb = new Scanner(System.in);
// Creates the board.
private Board board = new Board();
// Array of players.
private Player[] players = new Player[2];
// Creates a turn.
private Turn turn;
int[] count = new int[2];
final static int BLACK = 1;
final static int WHITE = 0;
public static void main(String[] args) throws IOException
{
new Driver().startGame();
}
/**
* Starts the game by finding first players possible moves
*/
public void startGame() throws IOException
{
int who = this.initPlayers();
this.turn = new Turn((who + 1) % 2);
// Asks players for their names.
for (int i = 0; i < 2; i++)
{
System.out.print("Player " + (i + 1) + " ");
players[i].setNames();
}
// Indicates player's turn.
System.out.println(players[0].getName() + " moves");
this.players[turn.getTurn()].findCanSelect();
board.display(); // Displays board.
// Finds possible moves when game is not over.
while (!board.gameOver())
{
// Count of possible moves.
int count = 0;
// Searches the entire board.
for (int row = 0; row < Board.num; row++)
{
for (int col = 0; col < Board.num; col++)
{
//Finds valid moves.
if (board.findLegalMove(new Move(row, col), turn.getTurn()) == true)
{
count++; // Adds a possible move to the count.
}
}
}
// When no possible moves are available.
if (count == 0)
{
turn.change(); // Switches to other players turn.
board.display(); // Prints the updated board.
board.scoreDisplay(); //Prints updated score.
count = 0; // Reset all the possible moves to 0.
}
else
{
int row = this.getRow();
int col = this.getCol();
// Creates a new move.
Move move = new Move(row, col);
// If a valid move.
if (board.canSelect(move))
{
// Place and replace chip.
this.players[turn.getTurn()].placeChip(row, col);
turn.change(); // Then changes the turn to the other player.
}
// Finds the possible moves.
this.players[turn.getTurn()].findCanSelect();
board.display(); // Displays updated board with possible moves.
// Indicates whose turn it is.
System.out.println(players[turn.getTurn()].getName() + " moves");
}
}
System.out.println("Game over!");
}
/**
* Creates two players.
*/
private int initPlayers()
{
Turn a = new Turn(); // Temporary turn.
this.players[0] = new Player("name 1", a.getTurn(), this.board); // Player 1
a.change(); // Changes to player 2.
this.players[1] = new Player("name 2", a.getTurn(), this.board); // Player 2
return 1;
}
/**
* Gets the row for move.
*/
private int getRow()
{
System.out.print("Select a row: ");
Integer value = -1;
value = kb.nextInt();
return value; // Returns the value selected.
}
/**
* Gets the col for move.
*/
private int getCol()
{
System.out.print("Select a column: ");
Integer value = -1;
value = kb.nextInt();
return value; // Returns value selected.
}
}
import java.io.IOException;
import java.util.Scanner;
public class Driver {
Scanner kb = new Scanner(System.in);
private Board board = new Board();
private Player[] players = new Player[2];
private Turn turn;
int[] count = new int[2];
final static int BLACK = 1;
final static int WHITE = 0;
public static void main(String[] args) throws
IOException {
new
Driver().startGame();
}
public void startGame() throws IOException {
int who =
this.initPlayers();
this.turn = new
Turn((who + 1) % 2);
for (int i = 0; i
< 2; i++) {
System.out.print("Player " + (i + 1) + " ");
players[i].setNames();
}
System.out.println(players[0].getName() + " moves");
this.players[turn.getTurn()].findCanSelect();
board.display();
while (!board.gameOver()) {
int count = 0;
for (int row = 0; row < Board.num; row++){
for (int col = 0; col < Board.num; col++){
if (board.findLegalMove(new Move(row, col), turn.getTurn()) ==
true) {
count++;
}
}
}
if (count == 0) {
turn.change();
board.display();
board.scoreDisplay();
count = 0;
}
else {
int row = this.getRow();
int col = this.getCol();
Move move = new Move(row, col);
if (board.canSelect(move)) {
this.players[turn.getTurn()].placeChip(row, col);
turn.change();
}
this.players[turn.getTurn()].findCanSelect();
board.display();
System.out.println(players[turn.getTurn()].getName() + "
moves");
}
}
System.out.println("Game
over!");
}
// Creates two players
private int initPlayers() {
Turn a = new Turn(); //
temporary turn
this.players[0] = new
Player("name 1", a.getTurn(), this.board); // player 1
a.change(); // changes
to player 2
this.players[1] = new
Player("name 2", a.getTurn(), this.board); // player 2
return 1;
}
// Gets the row for the move
private int getRow() {
System.out.print("Select
a row: ");
Integer value =
-1;
value =
kb.nextInt();
return value;
}
// Gets the col for the move
private int getCol() {
System.out.print("Select
a column: ");
Integer value =
-1;
value =
kb.nextInt();
return value;
}
}
-------------------------------------------------------------------------------------------------------
import java.util.ArrayList;
public class Board {
public static final int num = 8;
private Cell[][] cell = new
Cell[num][num];
int[] counter = new int[2];
boolean gameOver;
final static int BLACK = 1;
final static int WHITE = 0;
public final Move up = new Move(0, -1);
public final Move down = new Move(0, 1);
public final Move right = new Move(1, 0);
public final Move left = new Move(-1, 0);
public final Move upRight = new Move(1,
-1);
public final Move upLeft = new Move(-1,
-1);
public final Move downRight = new Move(1,
1);
public final Move downLeft = new Move(-1,
1);
final Move directions[] = { up, down, right, left, upRight, upLeft, downRight, downLeft }; // array of possible directions
public Board() {
for (int row = 0; row
< num; row++){
for (int col = 0; col < num; col++){
this.cell[row][col] = new Cell();
}
}
this.cell[3][4].placeChip(1);
this.cell[4][3].placeChip(1);
this.cell[3][3].placeChip(0);
this.cell[4][4].placeChip(0);
counter[0] = 2;
counter[1] = 2;
// allows moves by
default at start of game
gameOver = false;
}
//Gets the cell clicked
public Cell getCell(int row, int col){
return
cell[row][col];
}
// Gets the row of selected cell
public int getNumRows(){
return
cell.length;
}
// Gets the col of selected cell
public int getNumCols(){
return
cell[0].length;
}
// Displays the board with rows and col
numbers
public void display() {
for (int i = 0; i
< num; i++) {
System.out.print(i + " ");
for (int j = 0; j < num; j++) {
this.cell[i][j].display();
}
System.out.println(" ");
}
System.out.print(" ");
for (int j = 0; j <
num; j++) {
System.out.print(" " + j + " ");
}
System.out.println();
}
//Displays the winner of the game
public void winner(){
if
(getChipsCount(0)<getChipsCount(1)){
System.out.println("Black Won!");
}else
if(getChipsCount(1)<getChipsCount(0)){
System.out.println("White Won!");
}
}
//Displays the scores of both players
public void scoreDisplay() {
System.out.println("White score: " + getChipsCount(0));
System.out.println("Black score: " + getChipsCount(1));
System.out.println();
}
// Finds all the valid and available moves of
current player
public boolean findLegalMove(Move move, int player) {
boolean result =
false;
int opponent = (player +
1) % 2;
int cPlayer =
player;
int i =
move.getI();
int j = move.getJ();
if
(cell[i][j].isEmpty() == false) {
return false;
} else {
for (int k = 0; k < directions.length; k++) {
Move direction = directions[k];
int iDir = direction.getI();
int jDir = direction.getJ();
int jump = 2;
try {
if (cell[i + iDir][j + jDir].getPlayer() == opponent) {
while ((j + (jump * jDir)) > -1&& (j + (jump * jDir))
< 8 && (i + (jump * iDir)) < 8 && (i + (jump
* iDir)) > -1) {
if (!cell[i + jump * iDir][j + jump * jDir].isEmpty()) {
if (cell[i + jump * iDir][j + jump * jDir].getPlayer() ==
cPlayer)
return true;
else if (cell[i + jump * iDir][j + jump * jDir].isEmpty())
break;
} else {
break;
}
jump++;
}
}
} catch (Exception e) {
}
}
}
return result;
}
// Places the chip on the board
public void placeChip(int colour, int row,
int col) {
this.cell[row][col].placeChip(colour);
}
// An array list of all valid moves
available
public ArrayList<Move> validMoves(int
colour) {
ArrayList<Move>
allValidMoves = new ArrayList<Move>();
for (int i = 0; i
< cell.length; i++) {
for (int j = 0; j < cell.length; j++) {
cell[i][j].unselect();
Move testMove = new Move(i, j);
boolean valid = findLegalMove(testMove, colour);
if (valid) {
allValidMoves.add(testMove);
}
}
}
return
allValidMoves;
}
// Allows the cell to be selected
public void setCanSelect(Move move) {
this.cell[move.getI()][move.getJ()].setSelect();
}
//Allows the cell to be selected
public boolean canSelect(Move move) {
return
this.cell[move.getI()][move.getJ()].canSelect();
}
// Replaces the chip(s) in between the players
old and current chip.
public void replaceChip(Move move, int
player) {
int opponent = (player +
1) % 2;
int playing =
player;
int i =
move.getI();
int j = move.getJ();
for (int movement =
0; movement < directions.length; movement++) {
Move direction = directions[movement];
int iDir = direction.getI();
int jDir = direction.getJ();
boolean possible = false;
if ((j + jDir) > -1 && (j + jDir) < num && (i
+ iDir) < num
&& (i + iDir) > -1) {
if (cell[i + iDir][j + jDir].getPlayer() == opponent) {
possible = true;
}
}
if (possible == true) {
int jump = 2;
while ((j + (jump * jDir)) > -1 && (j + (jump * jDir))
< 8
&& (i + (jump * iDir)) < 8 && (i + (jump *
iDir)) > -1) {
if (!cell[i + jump * iDir][j + jump * jDir].isEmpty())
if (cell[i + jump * iDir][j + jump * jDir].getPlayer() == playing)
{
for (int k = 1; k < jump; k++) {
cell[i + k * iDir][j + k * jDir].changeChip();
}
break;
}
jump++;
}
}
}
}
// Updates the number/counter of chips on the
board per player
public int getChipsCount(int colour) {
int score=0;
for (int i = 0; i
< num; i++) {
for (int j = 0; j < num; j++) {
if (cell[i][j].getPlayer() == colour) {
score++;
}
}
}
return score;
}
// Checks if all the 64 chips have been placed
on board meaning the game is over.
public boolean gameOver() {
int count = 0;
if (counter[0] +
counter[1] == 64) {
return true;
}
else {
for (int j = 0; j < num; j++) {
for (int i = 0; i < num; i++) {
if (findLegalMove(new Move(i, j), 0) == true) {
count++;
}
if (findLegalMove(new Move(i, j), 1) == true) {
count++;
}
}
}
if (count == 0) {
return true;
}
}
return false;
}
}
---------------------------------------------------------------------------------------------------------------
public class Cell {
public static final char BLACK = 'B';
public static final char WHITE = 'W';
public static final char CANSELECT = '*';
public boolean empty;
public boolean canselect;
public int value;
//Class constructor. Cell is empty by default.
public Cell() {
this.empty = true;
this.value = -1;
}
// Checks if cell is empty.
public boolean isEmpty() {
return this.empty;
}
// Returns player's colour
public int getPlayer() {
return this.value;
}
// Places a chip in the cell
public void placeChip(int player) {
this.empty =
false;
this.value =
player;
}
//Changes the colour value of chip (0,1)
public void changeChip() {
placeChip((value + 1) %
2);
}
// Makes cell possible to select/choose
public void setSelect() {
this.canselect =
true;
}
// Makes the cell selectable
public boolean canSelect() {
return
this.canselect;
}
//Makes the cell not selectable
public void unselect() {
this.canselect =
false;
}
//Displays the cell so that valid moves are *,
black is B, and white is W
public void display() {
if
(this.isEmpty())
{
if (this.canselect)
System.out.print("[ " + CANSELECT + " ]");
else
System.out.print("[ " + " " + " ]");
} else {
char content = BLACK;
if (this.value == 0)
content = WHITE;
System.out.print("[ " + content + " ]");
}
}
}
-----------------------------------------------------------------------------------------------------
class Move {
int i;
int j;
// Creates the directions on the i and j
axis
public Move(int i, int j) {
this.i = i;
this.j = j;
}
// Gets the location of the position on the i
axis
public int getI() {
return i;
}
// Gets the location of the position on j
axis
public int getJ() {
return j;
}
}
-------------------------------------------------------------------------------------------------
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class Player {
Scanner kb = new Scanner(System.in);
private String name;
private int colour;
private Board board;
public Player(String name, int colour, Board
board) {
this.name = name;
this.colour =
colour;
this.board =
board;
}
//Places the piece for the chosen player at the
chosen location. Replaces the piece in between the old piece and
the new piece to the players colour.
public void placeChip(int row, int col)
{
this.board.placeChip(this.colour, row, col);
Move move = new
Move(row, col);
this.board.replaceChip(move, this.colour);
}
//Sets the players name to a variable
public void setNames() throws IOException {
System.out.println("What is your name: ");
String line =
kb.nextLine();
this.name = line;
}
// Gets the name of the player
public String getName() {
return this.name;
}
// Gets the colour number of the player
public int getcolour() {
return
this.colour;
}
//Finds the valid moves and allows them to be selected
public void findCanSelect() {
ArrayList<Move> moves = board.validMoves(this.colour);
for (Move move :
moves)
board.setCanSelect(move);
}
}
-------------------------------------------------------------------------------------------------------------------------------
public class Turn {
private int value;
//Creates a turn starting with a random
player
public Turn() {
this.value = (int)
(Math.random() * 2.0d);
}
// Creates a turn starting with selected first
player
public Turn(int v) {
this.value = v;
}
// Returns the player whose turn it is
public int getTurn() {
return this.value;
}
//Change the turn to the other player
public void change() {
this.value = (this.value
+ 1) % 2;
}
}
This is my code for my game called Reversi, I need to you to make the...
This is my code for a TicTacToe game. However, I don't know how to write JUnit tests. Please help me with my JUnit Tests. I will post below what I have so far. package cs145TicTacToe; import java.util.Scanner; /** * A multiplayer Tic Tac Toe game */ public class TicTacToe { private char currentPlayer; private char[][] board; private char winner; /** * Default constructor * Initializes the board to be 3 by 3 and...
JAVA Only Help on the sections that say Student provide code. The student Provide code has comments that i put to state what i need help with. import java.util.Scanner; public class TicTacToe { private final int BOARDSIZE = 3; // size of the board private enum Status { WIN, DRAW, CONTINUE }; // game states private char[][] board; // board representation private boolean firstPlayer; // whether it's player 1's move private boolean gameOver; // whether...
Please modify the following code to NOT have "TicTacToe extends Board" (I don't want any extending). Please ensure the resulting code completes EACH part of the following prompt: "Your task is to create a game of Tic-Tac-Toe using a 2-Dimensional String array as the game board. Start by creating a Board class that holds the array. The constructor should use a traditional for-loop to fill the array with "blank" Strings (eg. "-"). You may want to include other instance data......
Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame { static String[][]maze; public static void main(String[] args) { maze=new String[30][30]; maze=fillArray("mazefile.txt"); } public static String[][]fillArray(String file) { maze = new String[30][30]; try{...
JAVA TIC TAC TOE - please help me correct my code Write a program that will allow two players to play a game of TIC TAC TOE. When the program starts, it will display a tic tac toe board as below | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 The program will assign X to Player 1, and O to Player The program will ask Player 1, to...
Hello, I am currently taking a Foundations of Programming course where we are learning the basics of Java. I am struggling with a part of a question assigned by the professor. He gave us this code to fill in: import java.util.Arrays; import java.util.Random; public class RobotGo { public static Random r = new Random(58); public static void main(String[] args) { char[][] currentBoard = createRandomObstacle(createBoard(10, 20), 100); displayBoard(startNavigation(currentBoard)) } public static int[] getRandomCoordinate(int maxY, int maxX) { int[] coor = new...
I just need a help in replacing player 2 and to make it unbeatable here is my code: #include<iostream> using namespace std; const int ROWS=3; const int COLS=3; void fillBoard(char [][3]); void showBoard(char [][3]); void getChoice(char [][3],bool); bool gameOver(char [][3]); int main() { char board[ROWS][COLS]; bool playerToggle=false; fillBoard(board); showBoard(board); while(!gameOver(board)) { getChoice(board,playerToggle); showBoard(board); playerToggle=!playerToggle; } return 1; } void fillBoard(char board[][3]) { for(int i=0;i<ROWS;i++) for(int j=0;j<COLS;j++) board[i][j]='*'; } void showBoard(char board[][3]) { cout<<" 1 2 3"<<endl; for(int i=0;i<ROWS;i++) { cout<<(i+1)<<"...
Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner method, it declares a winner for horizontal wins, but not for vertical. if anyone can see what im doing wrong. public class ConnectFour { /** Number of columns on the board. */ public static final int COLUMNS = 7; /** Number of rows on the board. */ public static final int ROWS = 6; /** Character for computer player's pieces */ public static final...
JAVA JAR HELP...ASAP I have the code that i need for my game Connect 4, but i need to create a jar file . the instructions are below. It has to pass some parameters. I am really confused on doing so.l I dont know what to do next. Can someone help me and give detailed descritiopm opn how you ran the jar file in CMD import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Connect4 { ...
Hi i need heeeeelllllp on this assignment i need to print the numbers diagonal top right corner to the bottom left corner and i dont know how to do it please help me thank you dd another method to the bottom of the "TwoDimArraysMethods.java" file called "printDiagonalRL()" public static void printDiagonalRL(int[][] matrix) 4. Call this method in the main file ("TwoDimArraysAsParam.java") passing it "board." e.g. TwoDimArraysMethods.printDiagonal(board); 5. Your new method should print any numbers along the diagonal from...