toFileRep & Board(String[] array)
This commit is contained in:
parent
e416232614
commit
92ee8a45f4
|
|
@ -107,8 +107,9 @@ public class Board {
|
||||||
str += "B";
|
str += "B";
|
||||||
str += board[i][j].getType().getSummary();
|
str += board[i][j].getType().getSummary();
|
||||||
}
|
}
|
||||||
|
if (j != 7) {
|
||||||
str += ",";
|
str += ",";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
str += "\n";
|
str += "\n";
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +126,6 @@ public class Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pieces;
|
return pieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,7 +180,6 @@ public class Board {
|
||||||
if (board[j][i+1] != null) {
|
if (board[j][i+1] != null) {
|
||||||
moves.add(new int[] {i+1, j});
|
moves.add(new int[] {i+1, j});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
@ -194,7 +193,6 @@ public class Board {
|
||||||
if (board[j+1][i] != null) {
|
if (board[j+1][i] != null) {
|
||||||
moves.add(new int[] {i, j+1});
|
moves.add(new int[] {i, j+1});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
j += 1;
|
j += 1;
|
||||||
|
|
@ -208,7 +206,6 @@ public class Board {
|
||||||
if (board[j][i-1] != null) {
|
if (board[j][i-1] != null) {
|
||||||
moves.add(new int[] {i-1, j});
|
moves.add(new int[] {i-1, j});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
|
|
@ -273,7 +270,6 @@ public class Board {
|
||||||
if (board[j+1][i+1] != null) {
|
if (board[j+1][i+1] != null) {
|
||||||
moves.add(new int[] {i+1, j+1});
|
moves.add(new int[] {i+1, j+1});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
@ -288,7 +284,6 @@ public class Board {
|
||||||
if (board[j+1][i-1] != null) {
|
if (board[j+1][i-1] != null) {
|
||||||
moves.add(new int[] {i-1, j+1});
|
moves.add(new int[] {i-1, j+1});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
|
|
@ -303,7 +298,6 @@ public class Board {
|
||||||
if (board[j-1][i+1] != null) {
|
if (board[j-1][i+1] != null) {
|
||||||
moves.add(new int[] {i+1, j-1});
|
moves.add(new int[] {i+1, j-1});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
@ -335,7 +329,6 @@ public class Board {
|
||||||
if (board[j][i+1] != null) {
|
if (board[j][i+1] != null) {
|
||||||
moves.add(new int[] {i+1, j});
|
moves.add(new int[] {i+1, j});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
@ -349,7 +342,6 @@ public class Board {
|
||||||
if (board[j+1][i] != null) {
|
if (board[j+1][i] != null) {
|
||||||
moves.add(new int[] {i, j+1});
|
moves.add(new int[] {i, j+1});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
j += 1;
|
j += 1;
|
||||||
|
|
@ -363,7 +355,6 @@ public class Board {
|
||||||
if (board[j][i-1] != null) {
|
if (board[j][i-1] != null) {
|
||||||
moves.add(new int[] {i-1, j});
|
moves.add(new int[] {i-1, j});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
|
|
@ -390,7 +381,6 @@ public class Board {
|
||||||
if (board[j+1][i+1] != null) {
|
if (board[j+1][i+1] != null) {
|
||||||
moves.add(new int[] {i+1, j+1});
|
moves.add(new int[] {i+1, j+1});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
@ -405,7 +395,6 @@ public class Board {
|
||||||
if (board[j+1][i-1] != null) {
|
if (board[j+1][i-1] != null) {
|
||||||
moves.add(new int[] {i-1, j+1});
|
moves.add(new int[] {i-1, j+1});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
|
|
@ -420,7 +409,6 @@ public class Board {
|
||||||
if (board[j-1][i+1] != null) {
|
if (board[j-1][i+1] != null) {
|
||||||
moves.add(new int[] {i+1, j-1});
|
moves.add(new int[] {i+1, j-1});
|
||||||
metPiece = true;
|
metPiece = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
@ -522,18 +510,6 @@ public class Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*while (metPiece == false && i < 8 && j < 8) {
|
|
||||||
if (x == i && y == j) {
|
|
||||||
if (board[j][i] != null) {
|
|
||||||
}
|
|
||||||
moves.add(new int[] {i, j});
|
|
||||||
}
|
|
||||||
else if (x != this.x && y == this.y) {
|
|
||||||
if (board[y][x] != null) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
return moves;
|
return moves;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -555,14 +531,45 @@ public class Board {
|
||||||
/* saving-loading feature :*/
|
/* saving-loading feature :*/
|
||||||
|
|
||||||
public String[] toFileRep() {
|
public String[] toFileRep() {
|
||||||
//TODO
|
String myFile = this.toString();
|
||||||
return null;
|
String turn = "B";
|
||||||
|
if (this.isTurnWhite() == true) {
|
||||||
|
turn = "W";
|
||||||
|
}
|
||||||
|
myFile += turn;
|
||||||
|
String[] myArray = myFile.split("\n");
|
||||||
|
return myArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Board(String[] array) {
|
public Board(String[] array) {
|
||||||
//TODO
|
this.colNum = 8;
|
||||||
|
this.lineNum = 8;
|
||||||
|
this.board = new Piece[lineNum][colNum];
|
||||||
|
this.x = -1;
|
||||||
|
this.y = -1;
|
||||||
|
this.turns = 0;
|
||||||
|
this.whiteTurn = true;
|
||||||
|
|
||||||
|
String[] line;
|
||||||
|
boolean white;
|
||||||
|
char character;
|
||||||
|
PieceType type;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
line = array[i].split(",");
|
||||||
|
for (int j = 0; j < 8; j++) {
|
||||||
|
if (!line[j].equals(" ")) {
|
||||||
|
white = line[j].charAt(0) == 'W';
|
||||||
|
character = line[j].charAt(1);
|
||||||
|
type = PieceType.fromSummary(character);
|
||||||
|
setPiece(white, type, j, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (array[8] == "B") {
|
||||||
|
whiteTurn = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* The following methods require more work ! */
|
/* The following methods require more work ! */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue