-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProposedBoard.java
106 lines (89 loc) · 2.11 KB
/
ProposedBoard.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.util.ArrayList;
public class ProposedBoard {
// this object will hold the next move board information for the ChessGame Object. This Board will NOT be shared
// it will be used to resolve collisions and undo moves
private ArrayList[][] proposedBoard;
public ProposedBoard() {
// create a board of chess pieces
proposedBoard = new ArrayList[8][8];
for(int i=0;i<8;++i) {
for(int j=0;j<8;++j) {
proposedBoard[j][i] = new ArrayList<Piece>();
}
}
}
public void clearAll() {
// empties the board
for(int i=0;i<8;++i) {
for(int j=0;j<8;++j) {
proposedBoard[j][i].clear();
}
}
}
public void clear(int x, int y) {
// empties the location;
proposedBoard[y][x].clear();
}
public String printAll(ArrayList<Piece> pieces) {
String s = "";
for (Piece p : pieces) {
if (p.getTeam() == Piece.Team.BLACK) {
s += "B";
} else {
s += "W";
}
if (p.getType() == Piece.Type.PAWN) {
s += "P";
} else if (p.getType() == Piece.Type.ROOK) {
s += "R";
} else if (p.getType() == Piece.Type.KNIGHT) {
s += "K";
} else if (p.getType() == Piece.Type.BISHOP) {
s += "B";
} else if (p.getType() == Piece.Type.QUEEN) {
s += "Q";
} else if (p.getType() == Piece.Type.KING) {
s += "+";
}
s+=p.getID();
s+=".";
}
return s;
}
// print the current Board
public String toString() {
String line = "";
String row = "";
for(int k=0;k<8;k++) {
row+="---";
}
row+="-\n";
for(int i=0;i<8;++i) {
line = "|";
for(int j=0;j<8;++j) {
if (proposedBoard[i][j].size() == 0) {
line += " |";
} else {
line += printAll(proposedBoard[i][j]);
line = line.substring(0,line.length()-1) + "|";
}
}
row+=line+"\n";
for(int k=0;k<8;k++) {
row+="---";
}
row+="-\n";
}
return row;
}
//returns the chess piece at those coordinates
public ArrayList<Piece> getPieces(int x, int y) {
return proposedBoard[y][x];
}
public int countPieces(int x, int y) {
return proposedBoard[y][x].size();
}
public void add (int x, int y, Piece p) {
proposedBoard[y][x].add(p);
}
}