Undo works for the castling, when you save you can use undo up to the
saved move. Merge branch 'master' of https://gitarero.ecam.fr/aurele.wittke/OOP_1A5_Project
This commit is contained in:
parent
03ea5b41eb
commit
e003f63b4b
|
|
@ -161,6 +161,55 @@ public class Board {
|
||||||
outputString+= "1";
|
outputString+= "1";
|
||||||
}
|
}
|
||||||
outputString += "\n";
|
outputString += "\n";
|
||||||
|
if (this.kingWMoved == false) {
|
||||||
|
outputString+="0";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputString+= "1";
|
||||||
|
}
|
||||||
|
if (this.rookLWMoved == false) {
|
||||||
|
outputString+="0";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputString+= "1";
|
||||||
|
}
|
||||||
|
if (this.rookRWMoved == false) {
|
||||||
|
outputString+="0";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputString+= "1";
|
||||||
|
}
|
||||||
|
if (this.kingBMoved == false) {
|
||||||
|
outputString+="0";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputString+= "1";
|
||||||
|
}
|
||||||
|
if (this.rookLBMoved == false) {
|
||||||
|
outputString+="0";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputString+= "1";
|
||||||
|
}
|
||||||
|
if (this.rookRBMoved == false) {
|
||||||
|
outputString+="0";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputString+= "1";
|
||||||
|
}
|
||||||
|
if (this.castling == false) {
|
||||||
|
outputString+="0";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputString+= "1";
|
||||||
|
}
|
||||||
|
if (this.castlingDone == false) {
|
||||||
|
outputString+="0";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputString+= "1";
|
||||||
|
}
|
||||||
|
outputString += "\n";
|
||||||
return outputString;
|
return outputString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -306,12 +355,13 @@ public class Board {
|
||||||
selection = true;
|
selection = true;
|
||||||
}
|
}
|
||||||
return selection;
|
return selection;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* saving-loading feature :*/
|
/* saving-loading feature :*/
|
||||||
|
|
||||||
public String[] toFileRep() {
|
public String[] toFileRep() {
|
||||||
String[] saveFile = new String[10]; // creation of the string array which will be the one returned
|
String[] saveFile = new String[11]; // creation of the string array which will be the one returned
|
||||||
String actualBoard = this.toString();
|
String actualBoard = this.toString();
|
||||||
int nbLine = 0;
|
int nbLine = 0;
|
||||||
saveFile[0] = "";
|
saveFile[0] = "";
|
||||||
|
|
@ -327,6 +377,7 @@ public class Board {
|
||||||
saveFile[8]="";
|
saveFile[8]="";
|
||||||
saveFile[8] += this.turnNumber;
|
saveFile[8] += this.turnNumber;
|
||||||
saveFile[9]="";
|
saveFile[9]="";
|
||||||
|
saveFile[10]="";
|
||||||
if (this.lastTurnPawnTwo == false) {
|
if (this.lastTurnPawnTwo == false) {
|
||||||
saveFile[9]+= "0";
|
saveFile[9]+= "0";
|
||||||
}
|
}
|
||||||
|
|
@ -341,6 +392,55 @@ public class Board {
|
||||||
else {
|
else {
|
||||||
saveFile[9]+= "1";
|
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]);
|
||||||
return saveFile;
|
return saveFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -349,6 +449,9 @@ public class Board {
|
||||||
this.lineNum = 8;
|
this.lineNum = 8;
|
||||||
x = -1;
|
x = -1;
|
||||||
y = -1;
|
y = -1;
|
||||||
|
previousBoard = new ArrayList<>();
|
||||||
|
String originBoard = array[0] + "\n" + array[1] + "\n" +array[2] + "\n" +array[3] + "\n" + array[4] + "\n" + array[5] + "\n" +array[6] + "\n" +array[7] + "\n" +array[8] + "\n" + array[9] + "\n" +array[10] + "\n" ;;
|
||||||
|
previousBoard.add(originBoard);
|
||||||
pieces = new ArrayList<>();
|
pieces = new ArrayList<>();
|
||||||
for(int i=0; i<8;i++) { // this will be the Y coordinate
|
for(int i=0; i<8;i++) { // this will be the Y coordinate
|
||||||
for(int j=0; j<8;j++) { // this will be the X coordinate
|
for(int j=0; j<8;j++) { // this will be the X coordinate
|
||||||
|
|
@ -368,10 +471,7 @@ public class Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
turnNumber = Integer.parseInt(array[8]);
|
turnNumber = Integer.parseInt(array[8]);
|
||||||
System.out.println(turnNumber);
|
if(array[9].charAt(0) == '0' ) {
|
||||||
int turn = this.getTurnNumber();
|
|
||||||
System.out.println(turn);
|
|
||||||
if(array[9].charAt(0)==0) {
|
|
||||||
lastTurnPawnTwo = false;
|
lastTurnPawnTwo = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -379,21 +479,60 @@ public class Board {
|
||||||
}
|
}
|
||||||
xTwo = Character.getNumericValue(array[9].charAt(1));
|
xTwo = Character.getNumericValue(array[9].charAt(1));
|
||||||
yTwo = Character.getNumericValue(array[9].charAt(2));
|
yTwo = Character.getNumericValue(array[9].charAt(2));
|
||||||
if(array[9].charAt(3)==0) {
|
if(array[9].charAt(3) == '0') {
|
||||||
enPassant = false;
|
enPassant = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
enPassant = true;
|
enPassant = true;
|
||||||
}
|
}
|
||||||
enPassant = false;
|
if (array[10].charAt(0) == '0') {//king white
|
||||||
kingWMoved = false;
|
this.kingWMoved = false;
|
||||||
kingBMoved = false;
|
}
|
||||||
rookLWMoved = false;
|
else {
|
||||||
rookRWMoved = false;
|
this.kingWMoved = true;
|
||||||
rookLBMoved = false;
|
}
|
||||||
rookRBMoved = false;
|
if (array[10].charAt(1) == '0') { //rook left white
|
||||||
castling = false;
|
this.rookLWMoved = false;
|
||||||
castlingDone = false;
|
}
|
||||||
|
else {
|
||||||
|
this.rookLWMoved = true;
|
||||||
|
}
|
||||||
|
if (array[10].charAt(2) == '0') { // rook white right
|
||||||
|
this.rookRWMoved = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.rookRWMoved = true;
|
||||||
|
}
|
||||||
|
if (array[10].charAt(3) == '0') { // king black
|
||||||
|
this.kingBMoved = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.kingBMoved = true;
|
||||||
|
}
|
||||||
|
if (array[10].charAt(4) == '0') { // black rook left
|
||||||
|
this.rookLBMoved = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.rookLBMoved = true;
|
||||||
|
}
|
||||||
|
if (array[10].charAt(5) == '0') { // black rook right
|
||||||
|
this.rookRBMoved = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.rookRBMoved = true;
|
||||||
|
}
|
||||||
|
if (array[10].charAt(6) == '0') { // castling
|
||||||
|
this.castling = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.castling = true;
|
||||||
|
}
|
||||||
|
if (array[10].charAt(7) == '0') { // castling done
|
||||||
|
this.castlingDone = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.castlingDone = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The following methods require more work ! */
|
/* The following methods require more work ! */
|
||||||
|
|
@ -771,19 +910,22 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void undoLastMove() {
|
public void undoLastMove() {
|
||||||
if(turnNumber == 0) {
|
this.x = -1;
|
||||||
String lastBoard = previousBoard.get(turnNumber); // we have a String but we need a String[] in order to use the constructer
|
this.y = -1;
|
||||||
String[] oldBoard = new String[10];
|
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;
|
boolean complete = false;
|
||||||
int indexLine=0;
|
int indexLine=0;
|
||||||
int indexColumn=0;
|
int indexColumn=0;
|
||||||
for(int i=0; i<10; i++) {
|
for(int i=0; i<11; i++) {
|
||||||
oldBoard[i] = "";
|
oldBoard[i] = "";
|
||||||
}
|
}
|
||||||
while (complete == false) {
|
while (complete == false) {
|
||||||
if (lastBoard.charAt(indexColumn) == '\n') {
|
if (lastBoard.charAt(indexColumn) == '\n') {
|
||||||
indexLine+=1;
|
indexLine+=1;
|
||||||
if (indexLine == 10) {
|
if (indexLine == 11) {
|
||||||
complete= true;
|
complete= true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -798,21 +940,29 @@ public class Board {
|
||||||
this.yTwo=undo.yTwo;
|
this.yTwo=undo.yTwo;
|
||||||
this.enPassant=undo.enPassant;
|
this.enPassant=undo.enPassant;
|
||||||
this.lastTurnPawnTwo=undo.lastTurnPawnTwo;
|
this.lastTurnPawnTwo=undo.lastTurnPawnTwo;
|
||||||
|
this.kingBMoved=undo.kingBMoved;
|
||||||
|
this.kingWMoved=undo.kingWMoved;
|
||||||
|
this.rookLBMoved=undo.rookLBMoved;
|
||||||
|
this.rookRBMoved=undo.rookRBMoved;
|
||||||
|
this.rookLWMoved=undo.rookLWMoved;
|
||||||
|
this.rookRWMoved=undo.rookRWMoved;
|
||||||
|
this.castling=undo.castling;
|
||||||
|
this.castlingDone=undo.castlingDone;
|
||||||
}
|
}
|
||||||
if (turnNumber != 0 ) {
|
if (sizeSave != 1 ) {
|
||||||
turnNumber -= 1;
|
turnNumber -= 1;
|
||||||
String lastBoard = previousBoard.get(turnNumber); // we have a String but we need a String[] in order to use the constructer
|
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[10];
|
String[] oldBoard = new String[11];
|
||||||
boolean complete = false;
|
boolean complete = false;
|
||||||
int indexLine=0;
|
int indexLine=0;
|
||||||
int indexColumn=0;
|
int indexColumn=0;
|
||||||
for(int i=0; i<10; i++) {
|
for(int i=0; i<11; i++) {
|
||||||
oldBoard[i] = "";
|
oldBoard[i] = "";
|
||||||
}
|
}
|
||||||
while (complete == false) {
|
while (complete == false) {
|
||||||
if (lastBoard.charAt(indexColumn) == '\n') {
|
if (lastBoard.charAt(indexColumn) == '\n') {
|
||||||
indexLine+=1;
|
indexLine+=1;
|
||||||
if (indexLine == 10) {
|
if (indexLine == 11) {
|
||||||
complete= true;
|
complete= true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -827,7 +977,15 @@ public class Board {
|
||||||
this.yTwo=undo.yTwo;
|
this.yTwo=undo.yTwo;
|
||||||
this.enPassant=undo.enPassant;
|
this.enPassant=undo.enPassant;
|
||||||
this.lastTurnPawnTwo=undo.lastTurnPawnTwo;
|
this.lastTurnPawnTwo=undo.lastTurnPawnTwo;
|
||||||
previousBoard.remove(turnNumber+1);
|
this.kingBMoved=undo.kingBMoved;
|
||||||
|
this.kingWMoved=undo.kingWMoved;
|
||||||
|
this.rookLBMoved=undo.rookLBMoved;
|
||||||
|
this.rookRBMoved=undo.rookRBMoved;
|
||||||
|
this.rookLWMoved=undo.rookLWMoved;
|
||||||
|
this.rookRWMoved=undo.rookRWMoved;
|
||||||
|
this.castling=undo.castling;
|
||||||
|
this.castlingDone=undo.castlingDone;
|
||||||
|
previousBoard.remove(sizeSave-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue