-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPiece.java
172 lines (160 loc) · 5.2 KB
/
Piece.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
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
public class Piece {
public String symbol;
public int color;
public int currentX;
public int currentY;
public boolean allXPos = true;
public boolean allXNeg = true;
public boolean allYPos = true;
public boolean allYNeg = true;
public boolean TR = true;
public boolean BR = true;
public boolean TL = true;
public boolean BL = true;
public Piece(){
this.symbol = "-";
}
public boolean hasPiece(){
if(this.symbol.equals("-")){return false;}
return true;
}
public Piece[][] getBoardCopy(Piece[][] board){
Piece[][] b = new Piece[8][8];
for(int i = 0; i < 8; i++){
for(int j =0; j<8;j++){
b[i][j] = board[i][j];
}
}
return b;
}
public int getColor(){return this.color;}
public Piece[][] promote(int y, int x){return Main.board;}
public String toString(){return this.symbol;}
public Piece[][] move(int y, int x, Piece[][] board, boolean ghost){
return Main.board;
}
public Piece[][] slide(int a, int b, int c, int d, boolean b1, boolean b2, int x, int y, boolean xOrYAxis){
Piece[][] board = Main.board;
if(c == d){
if(board[y][x].getColor()!= color){
if(b > a){
for(int i = 1; i < b-a; i++){
if(xOrYAxis){
if(board[y-i][x].hasPiece()){
b1 = false;
}
}
if(!(xOrYAxis)){
if(board[y][x-i].hasPiece()){
b1 = false;
}
}
}
if(b1){
board[y][x] = board[currentY][currentX];
board[currentY][currentX] = new Piece();
currentX = x;
currentY = y;
return board;
}
}
else if(b < a){
for(int i = 1; i < a-b; i++){
if(xOrYAxis){
if(board[y+i][x].hasPiece()){
b2 = false;
}
}
if(!(xOrYAxis)){
if(board[y][x+i].hasPiece()){
b2 = false;
}
}
}
if(b2){
board[y][x] = board[currentY][currentX];
board[currentY][currentX] = new Piece();
currentX = x;
currentY = y;
return board;
}
}
}
}
return board;
}
public Piece[][] diag(Piece[][] board, int a, int b, int c, int d){
int flipSign1 = 1;
int flipSign2 = 1;
boolean bool = true;
if(Math.abs(a-b) == Math.abs(c-d)){
if(board[d][b].getColor()!= color){
if(a > b && c > d){
flipSign1 = -1;
flipSign2 = -1;
}
else if(a > b && c < d){
flipSign1 = -1;
flipSign2 = 1;
}
else if(a < b && c > d){
flipSign1 = -1;
flipSign2 = 1;
}
else if(a < b && c < d){
flipSign1 = 1;
flipSign2 = 1;
}
for(int i = 1; i < Math.abs(d-c);i++){
if(board[c+i*flipSign2][a+i*flipSign1].hasPiece()){
bool = false;
}
}
}
if(bool){
board[d][b] = board[c][a];
board[c][a] = new Piece();
currentX = b;
currentY = d;
return board;
}
}
return board;
}
//currentX, x, currentY, y
public Piece[][] basicMovement(Piece[][] board, int a, int b, int c, int d, int changex, int changey, boolean ghost){
boolean noConflicts = true;
if(a+changex == b && c+changey == d){
if(c < d){
for(int i = c+1; i < d; i++){
if(!(board[i][a].symbol.equals("-"))){
noConflicts = false;
}
}
}
if(d < c){
for(int i = c-1; i > d; i--){
if(!(board[i][a].symbol.equals("-"))){
noConflicts = false;
}
}
}
// System.out.println(noConflicts);
if(board[d][b].getColor()!= color && noConflicts){
board[d][b] = board[c][a];
board[c][a] = new Piece();
if(!ghost){
currentX = b;
currentY = d;
}
}
}
// for(Piece[] pa : board){
// for(Piece p : pa){
// System.out.print(p.symbol);
// }
// System.out.println();
// }
return board;
}
}