Simplification of toRepFile and undo using split
This commit is contained in:
parent
2200b06d7b
commit
630d403731
|
|
@ -378,86 +378,7 @@ public class Board {
|
|||
/* saving-loading feature :*/
|
||||
|
||||
public String[] toFileRep() {
|
||||
String[] saveFile = new String[11]; // creation of the string array which will be the one returned
|
||||
String actualBoard = this.toString();
|
||||
int nbLine = 0;
|
||||
saveFile[0] = "";
|
||||
for(int i = 0; i<200 ;i++) { // there are in total 200 strings in the
|
||||
if (actualBoard.charAt(i) == '\n') {
|
||||
nbLine+=1;
|
||||
saveFile[nbLine]= "";
|
||||
}
|
||||
else {
|
||||
saveFile[nbLine] += actualBoard.charAt(i);
|
||||
}
|
||||
}
|
||||
saveFile[8]="";
|
||||
saveFile[8] += this.turnNumber;
|
||||
saveFile[9]="";
|
||||
saveFile[10]="";
|
||||
if (this.lastTurnPawnTwo == false) {
|
||||
saveFile[9]+= "0";
|
||||
}
|
||||
else {
|
||||
saveFile[9]+= "1";
|
||||
}
|
||||
saveFile[9] += xTwo;
|
||||
saveFile[9] += yTwo;
|
||||
if (this.enPassant == false) {
|
||||
saveFile[9]+="0";
|
||||
}
|
||||
else {
|
||||
saveFile[9]+= "1";
|
||||
}
|
||||
if (this.kingWMoved == false) {
|
||||
saveFile[10]+="0";
|
||||
}
|
||||
else {
|
||||
saveFile[10]+= "1";
|
||||
}
|
||||
if (this.rookLWMoved == false) {
|
||||
saveFile[10]+="0";
|
||||
}
|
||||
else {
|
||||
saveFile[10]+= "1";
|
||||
}
|
||||
if (this.rookRWMoved == false) {
|
||||
saveFile[10]+="0";
|
||||
}
|
||||
else {
|
||||
saveFile[10]+= "1";
|
||||
}
|
||||
if (this.kingBMoved == false) {
|
||||
saveFile[10]+="0";
|
||||
}
|
||||
else {
|
||||
saveFile[10]+= "1";
|
||||
}
|
||||
if (this.rookLBMoved == false) {
|
||||
saveFile[10]+="0";
|
||||
}
|
||||
else {
|
||||
saveFile[10]+= "1";
|
||||
}
|
||||
if (this.rookRBMoved == false) {
|
||||
saveFile[10]+="0";
|
||||
}
|
||||
else {
|
||||
saveFile[10]+= "1";
|
||||
}
|
||||
if (this.castling == false) {
|
||||
saveFile[10]+="0";
|
||||
}
|
||||
else {
|
||||
saveFile[10]+= "1";
|
||||
}
|
||||
if (this.castlingDone == false) {
|
||||
saveFile[10]+="0";
|
||||
}
|
||||
else {
|
||||
saveFile[10]+= "1";
|
||||
}
|
||||
System.out.println(saveFile[10]);
|
||||
String[] saveFile = toString().split("\n");
|
||||
return saveFile;
|
||||
}
|
||||
|
||||
|
|
@ -1182,25 +1103,7 @@ public class Board {
|
|||
int sizeSave = previousBoard.size();
|
||||
if(sizeSave == 1) {
|
||||
String lastBoard = previousBoard.get(0); // we have a String but we need a String[] in order to use the constructer
|
||||
String[] oldBoard = new String[11];
|
||||
boolean complete = false;
|
||||
int indexLine=0;
|
||||
int indexColumn=0;
|
||||
for(int i=0; i<11; i++) {
|
||||
oldBoard[i] = "";
|
||||
}
|
||||
while (complete == false) {
|
||||
if (lastBoard.charAt(indexColumn) == '\n') {
|
||||
indexLine+=1;
|
||||
if (indexLine == 11) {
|
||||
complete= true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
oldBoard[indexLine] += lastBoard.charAt(indexColumn);
|
||||
}
|
||||
indexColumn+=1;
|
||||
}
|
||||
String[] oldBoard = lastBoard.split("\n");
|
||||
Board undo = new Board(oldBoard);
|
||||
this.pieces = undo.pieces;
|
||||
this.xTwo=undo.xTwo;
|
||||
|
|
@ -1219,25 +1122,7 @@ public class Board {
|
|||
if (sizeSave != 1 ) {
|
||||
turnNumber -= 1;
|
||||
String lastBoard = previousBoard.get(sizeSave-2); // we have a String but we need a String[] in order to use the constructer
|
||||
String[] oldBoard = new String[11];
|
||||
boolean complete = false;
|
||||
int indexLine=0;
|
||||
int indexColumn=0;
|
||||
for(int i=0; i<11; i++) {
|
||||
oldBoard[i] = "";
|
||||
}
|
||||
while (complete == false) {
|
||||
if (lastBoard.charAt(indexColumn) == '\n') {
|
||||
indexLine+=1;
|
||||
if (indexLine == 11) {
|
||||
complete= true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
oldBoard[indexLine] += lastBoard.charAt(indexColumn);
|
||||
}
|
||||
indexColumn+=1;
|
||||
}
|
||||
String[] oldBoard = lastBoard.split("\n");
|
||||
Board undo = new Board(oldBoard);
|
||||
this.pieces = undo.pieces;
|
||||
this.xTwo=undo.xTwo;
|
||||
|
|
|
|||
Loading…
Reference in New Issue