tostring now has a flag variable and is weel readable thanks to lines
skipped
This commit is contained in:
parent
5e9ee6d35b
commit
f3b9526521
|
|
@ -103,24 +103,37 @@ public class Board {
|
|||
//initialize the str variable + black and white str
|
||||
String boardState = "";
|
||||
String bOrW = "" ;
|
||||
int pieceCount = 0 ;
|
||||
//initialize the str variable + black and white str
|
||||
//for loop that iterates through all the pieces in the arraylist pieces, adding conditions and simplifying the state of the board
|
||||
for(Piece piece : pieces) {
|
||||
if(piece.isWhite() == true) {
|
||||
bOrW += "White";
|
||||
bOrW += "w";
|
||||
}
|
||||
else {
|
||||
bOrW += "Black";
|
||||
bOrW += "b";
|
||||
}
|
||||
//gathering all other piece data
|
||||
String type = piece.getType().getSummary();
|
||||
int xCord = piece.getX() + 1; //adding one to better understand the grid as a human, this will convert the 0-7 coord
|
||||
int yCord = piece.getY() + 1; //system to a much more understandable 1-8 value range, which is better for an 8x8 grid
|
||||
|
||||
boardState += bOrW + "[" + type + "] (" + xCord + ";" + yCord + ")\n"; // str concatenation
|
||||
boardState += bOrW + "[" + type + "] (" + xCord + ";" + yCord + ")"; // str concatenation
|
||||
pieceCount ++;
|
||||
|
||||
if (pieceCount % 8 == 0) {
|
||||
boardState += "\n"; //add a new line
|
||||
} else {
|
||||
boardState += " "; //add space if not divsisble by 8
|
||||
}
|
||||
|
||||
bOrW = ""; //reinitialization of this local var bc white and black will pile up if not
|
||||
}
|
||||
|
||||
if (pieceCount % 8 != 0) {
|
||||
boardState += "\n"; // skip a line at the very end if piececount isnt modulo 8
|
||||
}
|
||||
|
||||
return boardState; //gives back the full string
|
||||
//TODO
|
||||
//maybe i should add a flag variable to display 5 or 6 coordinates on the same line if i have time instead of 1 coord per line
|
||||
|
|
|
|||
Loading…
Reference in New Issue