Must be done in Java.
PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL.
PROBLEM 1 INFORMATION IF YOU NEED IT AS WELL:
Provide the rest of the code with full comments and explanation and with proper indentation.
Use simple methods for better understanding.
Must compile.
At the end, show the exact Output that's shown in Problem3.
CODE PROVIDED FOR PROBLEM 2:
import java.util.Scanner;
public class Problem2
{
public static void main( String [] args )
{
//N denoting the size of the board
int n;
//B denoting the number of black pieces to be place on the board
int b;
//row and column position of a piece
int r,c;
//W denoting the number of white pieces to be place on the board
int w;
int i,j;
Scanner in = new Scanner(System.in);
n = in.nextInt();
String[][] board = new String[n][n];
//initialize the board with periods
for(i = 0;i
{
for(j = 0;j
{
board[i][j] = ".";
}
}
//take b and its r and c positions in one line of input
//and remove any whitespaces at end and start, split at space to separate values
in.nextLine();
String[] inp = in.nextLine().trim().split(" ");
//B will the first value in the splitted input stored in the string array
b = Integer.parseInt(inp[0]);
for(i = 1;i<2*b;i+=2)
{
r = Integer.parseInt(inp[i]);
c = Integer.parseInt(inp[i+1]);
//check for row and column exceed conditions .
//positions must be in range of n
if(r >=0 && r
{
if(c >=0 && c< n)
{
//set black posiiton in board
board[n - r - 1][c] = "*";
}
}
}
//take W and its r and c positions in one line of input
//and remove any whitespaces at end and start, split at space to separate values
inp = in.nextLine().trim().split(" ");
//W will the first value in the splitted input stored in the string array
w = Integer.parseInt(inp[0]);
for(i = 1; i<2*w ; i+=2)
{
r = Integer.parseInt(inp[i]);
c = Integer.parseInt(inp[i+1]);
//check for row and column exceed conditions .
//positions must be in range of n
if(r >=0 && r
{
if(c >=0 && c< n)
{
//set white piece position in board
board[n - r - 1][c] = "0";
}
}
}
// Get valid moves and modify the board accoridng to them
inp = in.nextLine().trim().split(" ");
int moveNum = Integer.parseInt(inp[0]);
for(i = 1; i <= 4*moveNum; i+=4) {
int r1, c1, r2, c2;
// read moves
r1 = Integer.parseInt(inp[i]);
c1 = Integer.parseInt(inp[i+1]);
r2 = Integer.parseInt(inp[i+2]);
c2 = Integer.parseInt(inp[i+3]);
//Move (r1,c1) to (r2, c2)
board[n-r2-1][c2] = board[n-r1-1][c1];
//Clear (r1,c1)
board[n-r1-1][c1] = ".";
}
//finally print out the board
for(i = 0;i
{
for(j = 0;j
{
System.out.print(board[i][j]+" ");
}
System.out.println();
}
}
}
________________________________________________________________
Show the exact Output that's shown in Problem 3. Or else it will be flagged.
CODE:
import java.util.Scanner;
public class Problem1
{
public static void main( String [] args )
{
//N denoting the size of the board
int n;
//B denoting the number of black pieces to be place on the board
int b;
//row and column position of a piece
int r,c;
//W denoting the number of white pieces to be place on the board
int w;
int i,j;
Scanner in = new Scanner(System.in);
n = in.nextInt();
String[][] board = new String[n][n];
//initialize the board with periods
for(i = 0;i<n;i++)
{
for(j = 0;j<n;j++)
{
board[i][j] = ".";
}
}
//take b and its r and c positions in one line of input
//and remove any whitespaces at end and start, split at space to separate values
in.nextLine();
String[] inp = in.nextLine().trim().split(" ");
//B will the first value in the splitted input stored in the string array
b = Integer.parseInt(inp[0]);
for(i = 1;i<2*b;i+=2)
{
r = Integer.parseInt(inp[i]);
c = Integer.parseInt(inp[i+1]);
//check for row and column exceed conditions .
//positions must be in range of n
if(r >=0 && r<n)
{
if(c >=0 && c< n)
{
//set black posiiton in board
board[n - r - 1][c] = "*";
}
}
}
//take W and its r and c positions in one line of input
//and remove any whitespaces at end and start, split at space to separate values
inp = in.nextLine().trim().split(" ");
//W will the first value in the splitted input stored in the string array
w = Integer.parseInt(inp[0]);
for(i = 1; i<2*w ; i+=2)
{
r = Integer.parseInt(inp[i]);
c = Integer.parseInt(inp[i+1]);
//check for row and column exceed conditions .
//positions must be in range of n
if(r >=0 && r<n)
{
if(c >=0 && c< n)
{
//set white piece position in board
board[n - r - 1][c] = "0";
}
}
}
// Get valid moves and modify the board accoridng to them
inp = in.nextLine().trim().split(" ");
int moveNum = Integer.parseInt(inp[0]);
for(i = 1; i <= 4*moveNum; i+=4) {
int r1, c1, r2, c2;
// read moves
r1 = Integer.parseInt(inp[i]);
c1 = Integer.parseInt(inp[i+1]);
r2 = Integer.parseInt(inp[i+2]);
c2 = Integer.parseInt(inp[i+3]);
// Check if destination is empty
if(board[n-r2-1][c2] != ".") {
System.out.println("Invalid Move!");
break;
}
// Check if the move is deiagonal
if(!(r1 == r2-1 && c1 == c2-1) &&
!(r1 == r2+1 && c1 == c2-1) &&
!(r1 == r2-1 && c1 == c2+1) &&
!(r1 == r2+1 && c1 == c2+1)) {
System.out.println("Invalid Move!");
break;
}
//Move (r1,c1) to (r2, c2)
board[n-r2-1][c2] = board[n-r1-1][c1];
//Clear (r1,c1)
board[n-r1-1][c1] = ".";
}
//finally print out the board
for(i = 0;i<n;i++)
{
for(j = 0;j<n;j++)
{
System.out.print(board[i][j]+" ");
}
System.out.println();
}
}
}
Output:
comment down for any
queries
please give a thumbs up
Must be done in Java. PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....
Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end, show the exact Output that's shown in Problem 2. CODE PROVIDED FOR PROBLEM 1: import java.util.Scanner; public class Problem1 { public static void main( String [] args ) { //N denoting the size of the board int n; ...
Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end show the exact Output that's shown in the Problem 2. CODE PROVIDED FOR PROBLEM 1: import java.util.Scanner; public class Problem1 { public static void main( String [] args ) { //N denoting the size of the board int...
please use JAVA to solve it. Checkers is played on an N XN checker board, with one side playing the black pieces and the ofther side playing the white pieces. Glven a board size N and the positions of the black and white checkers, create a program to print out the resulting checker board. INPUT Row, Column Integer N denoting the size of the board Integer B denoting the number of black pieces to be placed on the board, followed...
In Python, starting with the 8x8 board solution that will be appended here add the following functionality: 1) Add code to create a list, containing 8 lists, with each of the 8 lists containing 8 null strings as values. Call the list of lists board. code provided by prof: import turtle validMovesList=['A0','A2','A4','A6','B1','B3','B5','B7', 'C0','C2','C4','C6','D1','D3','D5','D7', 'E0','E2','E4','E6','F1','F3','F5','F7', 'G0','G2','G4','G6','H1','H3','H5','H7','quit'] def drawSquare(t,length,color): t.fillcolor(color) t.begin_fill() for num in range(4): t.forward(length) t.left(90) t.end_fill() def drawRow(t,length,color1,color2): for i in range(4): drawSquare(t,length,color1) t.forward(length) drawSquare(t,length,color2) t.forward(length) def drawCircleFilled(t,size,color): t.fillcolor(color) t.begin_fill()...
How to make a reversi/othello game in JAVA? Ideally with multiple classes and without GUI You are implementing a strategy board game played by two players, Black and White. It is played on an N by N board. The winner is the player who has more discs of his color than his opponent at the end of the game. This will happen when neither of the two players has a legal move or there are no spaces left on the...
Please develop the following code using C programming and using the specific functions, instructions and format given below. Again please use the functions given especially. Also don't copy any existing solution please write your own code. This is the first part of a series of two labs (Lab 7 and Lab 8) that will complete an implementation for a board-type game called Reversi (also called Othello). The goal of this lab is to write code that sets up the input...
solve in c++ Lab 6.3.1 Polymorphism: part 2 Objectives Familiarie the student with: . polymorphism, or using objocts of different types through a common interface using polymorphism in real programs Scenario Let's assume you write a code for the game of checkers (aka draughts). There are two types of pieces in this game: men and kings. You need to implement classes (one abstract for the pieces and two separate classes for the men and the kings) to chock if the...
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...
You are going to write a method (to be called validateBoard) that is going to validate whether or not a Tic-Tac-Toe board is possible. Tic- Tac-Toe is played on a 3 x 3 board and players take turns placing either an x or an o on the board. We will assume that in Tic-Tac-Toe the player placing x will go first arld that o will go second. (Learn more about the game here) As the player placing x pieces goes...
# In this file, fill in the ... parts with lines of code. Do not # create new functions. from random import seed, randrange P=[" ♟♜♝♞♛♚"]; L,R,BL,TL=["▌▐▄▀"] BonR=WonR=WonB=DonR=DonB=RonB=GonR=GonB=RonG='\033[1;m\033[' WonR+='7;31;47m' # For drawing a white piece on a red background WonB+='7;30;47m' # For drawing a white piece on a black background DonR+='2;37;41m' # For drawing a dark piece on a red background DonB+='2;37;40m' # For drawing a dark piece on a black background GonR+='2;33;41m' # For drawing gold on a red...