Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Please help so that the outputs are as follows with the commands; e . g . A 6 to B 5 will produce board [

Please help so that the outputs are as follows with the commands; e.g. A6 to B5 will produce board[5][0] and move the char 'b' to board[4][1]. If my logic is flawed please fix. this is my code and the image helps demonstrate it more.
import java.util.Scanner;
public class Checkers {
static char blackPieces ='b';
static char whitePieces ='w';
static char empty ='';
static char blackKing ='B';
static char whiteKing ='W';
static String exitCommand = "exit";
static String viewCommand = "view";
private static char[][] board = new char[8][8];
static Scanner scanner = new Scanner(System.in);
private static void initialiseBoard(){
for(int i =0; i board.length;i++){
for(int j =0; j board[i].length;j++){
if((i+j)%2==1){
if(i3){
board[i][j]= whitePieces;
}
else if(i >4){
board[i][j]= blackPieces;
}else{
board[i][j]= empty;
}
}else{
board[i][j]='';
}
}
}
}
private static void displayBoard(){
for(int i =0; i board.length; i++){
System.out.print("|");
for(int j =0; j = board.length || fromCol 0|| fromCol >= board[0].length ||
toRow 0|| toRow >= board.length || toCol 0|| toCol >= board[0].length){
return false;
}
if (board[toRow][toCol]!= empty){
return false;
}
int rowDifference = Math.abs(toRow - fromRow);
int colDifference = Math.abs(toCol - fromCol);
if (rowDifference != colDifference){
return false;
}
int rowChange = toRow - fromRow;
if (rowChange =0){
return false;
}
return true;
}
private static boolean isGameOver(){
boolean blackPiecesExist = false;
boolean whitePiecesExist = false;
for (int i =0; i board.length; i++){
for (int j =0; j board[i].length; j++){
if(board[i][j]== blackKing || board[i][j]== blackPieces){
blackPiecesExist = true;
} else if (board[i][j]== whiteKing || board[i][j]== whitePieces){
whitePiecesExist = true;
}
}
}
if (!blackPiecesExist){
System.out.println("Player 2 won");
return true;
} else if (!whitePiecesExist){
System.out.println("Player 1 won");
return true;
}
return false;
}
public static void main(String[] args){
initialiseBoard();
displayBoard();
startGame();
}
}
image text in transcribed

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_2

Step: 3

blur-text-image_3

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 Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students explore these related Databases questions

Question

internationalization of business?

Answered: 3 weeks ago