-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbishop.java
More file actions
189 lines (183 loc) · 7.51 KB
/
bishop.java
File metadata and controls
189 lines (183 loc) · 7.51 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Bishop class used to set the rules for bishop movemenet.
// The Bishop is missing:
// Attack Functionality
class bishop extends Pieces {
// The function override is used to set the function inside of the Pieces class to be specifically tailored to the bishop chess piece.
@Override
public boolean allowedMoves(int newRow, int newColumn) {
// The if statement is used to check if the final destination is a free spot or not.
if (chessBoard[newRow][newColumn].equals("|__|")) {
for (int i = 1; i <= 8; i++) {
// Up and to the Left
if ((newRow == this.row - i) && newColumn == this.column - i) {
//System.out.println("Up and to the left");
// The for loop is then used to check each of the row and column combinations if they're free or not (down to the right).
for (int x = 0; x < newRow; x++) {
if (!(chessBoard[newRow - x][newColumn - x].equals("|__|"))) {
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
} // Down and to the Right. (FIXED)
else if ((newRow == this.row + i) && newColumn == this.column + i) {
//System.out.println("Down and to the right");
for (int x = 0; x < (newRow - this.row); x++) {
//System.out.println(x);
if (!(chessBoard[newRow - x][newColumn - x].equals("|__|"))) {
//System.out.println(chessBoard[newRow-x][newColumn - x]);
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
} // Down and to the Left. (FIXED)
else if ((newRow == this.row + i) && newColumn == this.column - i) {
//System.out.println("Down and to the left");
for (int x = 0; x < (newRow - this.row); x++) {
if (!(chessBoard[newRow - x][newColumn + x].equals("|__|"))) {
//System.out.println(chessBoard[newRow - x][newColumn + x]);
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
} // Up and to the Right. (FIXED)
else if ((newRow == this.row - i) && newColumn == this.column + i) {
//System.out.println("Up and to the right");
for (int x = 0; x < (this.row - newRow); x++) {
if (!(chessBoard[newRow - x][newColumn + x].equals("|__|"))) {
//System.out.println(chessBoard[newRow + x][newColumn - x]);
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
}
}
} else {
for (int i = 0; i < AIPieces.length; i++) {
if (chessBoard[newRow][newColumn].equals(AIPieces[i])) {
for (int x = 1; x <= 8; x++) {
// Up and to the Right
if (newRow == (this.row - x) && newColumn == (this.column + x)) {
// System.out.println("Up and Right");
for (int z = 1; z < (row - newRow); z++) {
if (!(chessBoard[newRow - z][newColumn + z].equals("|__|"))) {
//System.out.println(chessBoard[newRow - z][newColumn + z]);
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
} // Up and to the Left.
else if (newRow == (this.row - x) && newColumn == (this.column - x)) {
//System.out.println("Up and Left");
for (int z = 1; z < (row - newRow); z++) {
if (!(chessBoard[newRow - z][newColumn - z].equals("|__|"))) {
//System.out.println(chessBoard[newRow - z][newColumn - z]);
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
} // Down and to the Left.
else if ((newRow == row + x) && (newColumn == column - x)) {
//System.out.println("Down and Left");
for (int z = 1; z < ((newRow - row) - 1); z++) {
if (!(chessBoard[newRow - z][newColumn + z].equals("|__|"))) {
//System.out.println(chessBoard[newRow - z][newColumn + z]);
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
} // Down and to the Right.
else if ((newRow == row + x) && (newColumn == column + x)) {
//System.out.println("Down and Right");
for (int z = 1; z < (newRow - row); z++) {
//System.out.println(chessBoard[newRow - z][newColumn + z]);
if (!(chessBoard[newRow - z][newColumn - z].equals("|__|"))) {
//System.out.println(chessBoard[newRow - z][newColumn - z]);
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
}
}
}
}
}
//System.out.println("test123");
return false;
}
// Used for the AI Pieces
public boolean allowedMovesAI(int newRow, int newColumn) {
for (int i = 0; i < playerPieces.length; i++) {
if (chessBoard[newRow][newColumn].equals(playerPieces[i])) {
for (int x = 1; x <= 8; x++) {
// Up and to the Right
if (newRow == (this.row - x) && newColumn == (this.column + x)) {
//System.out.println("Up and Right Bishop");
for (int z = 1; z < (this.row - newRow); z++) {
if (!(chessBoard[newRow + z][newColumn - z]).equals("|__|")) {
//System.out.println(chessBoard[newRow + z][newColumn - z]);
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
} // Up and to the Left.
else if (newRow == (this.row - x) && newColumn == (this.column - x)) {
//System.out.println("Up and Left");
for (int z = 1; z < (row - newRow); z++) {
if (!(chessBoard[newRow - z][newColumn - z].equals("|__|"))) {
//System.out.println(chessBoard[newRow - z][newColumn - z]);
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
} // Down and to the Left.
else if ((newRow == row + x) && (newColumn == column - x)) {
//System.out.println("Down and Left");
for (int z = 1; z < ((newRow - row) - 1); z++) {
if (!(chessBoard[newRow - z][newColumn + z].equals("|__|"))) {
//System.out.println(chessBoard[newRow - z][newColumn + z]);
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
} // Down and to the Right.
else if ((newRow == row + x) && (newColumn == column + x)) {
//System.out.println("Down and Right");
for (int z = 1; z < (newRow - row); z++) {
//System.out.println(chessBoard[newRow - z][newColumn + z]);
if (!(chessBoard[newRow - z][newColumn - z].equals("|__|"))) {
//System.out.println(chessBoard[newRow - z][newColumn - z]);
return false;
}
}
this.row = newRow;
this.column = newColumn;
return true;
}
}
}
}
return false;
}
}