Question: Checker java need help debugging or understanding my issue import java.util.Scanner; public class Checkers { static char blackPieces = ' b ' ; static char
Checker java need help debugging or understanding my issue
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;
static Scanner scanner new ScannerSystemin;
private static void initialiseBoard
for int i ; i board.length; i
for int j ; j boardilength; j
if i j
if i
boardij whitePieces;
else if i
boardij blackPieces;
else
boardij empty;
else
boardij;
private static void displayBoard
for int i ; i board.length; i
System.out.print;
for int j ; j boardilength; j
System.out.printboardij;
System.out.println;
System.out.println;
System.out.println;
private static void startGame
int playerTurn ;
while isGameOver
if scannerhasNextLine
String move scanner.nextLinetrimtoLowerCase;
if moveequalsIgnoreCaseexitCommand
return;
else if moveequalsIgnoreCaseviewCommand
displayBoard;
else if processMovemove
playerTurn playerTurn : ; Switch player turn
else
System.out.printlnError;
private static boolean processMoveString move
if moveequalsIgnoreCaseviewCommand
displayBoard;
return false; No error for view command
String positions move.split to;
if positionslength
System.out.printlnInvalid move format.";
return false;
String fromPosition positionstrim;
String toPosition positionstrim;
int fromRow parseCoordinateRowfromPosition;
int fromCol parseCoordinateColfromPosition;
int toRow parseCoordinateRowtoPosition;
int toCol parseCoordinateColtoPosition;
if isValidMovefromRow fromCol, toRow, toCol
System.out.printlnInvalid move. Please try again.";
return false;
boardtoRowtoCol boardfromRowfromCol;
boardfromRowfromCol empty;
displayBoard;
return true;
private static int parseCoordinateRowString coordinate
return Character.getNumericValuecoordinatecharAt;
private static int parseCoordinateColString coordinate
return coordinate.toLowerCasecharAta;
private static boolean isValidMoveint fromRow, int fromCol, int toRow, int toCol
if fromRow fromRow board.length fromCol fromCol boardlength
toRow toRow board.length toCol toCol boardlength
return false;
if boardtoRowtoCol empty
return false;
int rowDifference Math.abstoRow fromRow;
int colDifference Math.abstoCol fromCol;
if rowDifference colDifference
return false;
int rowChange toRow fromRow;
if rowChange
return false;
return true;
private static boolean isGameOver
boolean blackPiecesExist false;
boolean whitePiecesExist false;
for int i ; i board.length; i
for int j ; j boardilength; j
if boardij blackKing boardij blackPieces
blackPiecesExist true;
else if boardij whiteKing boardij whitePieces
whitePiecesExist true;
if blackPiecesExist
System.out.printlnPlayer won";
return true;
else if whitePiecesExist
System.out.printlnPlayer won";
return true;
return false;
public static void mainString args
initialiseBoard;
displayBoard;
startGame;
current right board output is;
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
