-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rules.pde
182 lines (177 loc) · 4.57 KB
/
Rules.pde
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
class Rules {
boolean diagonalMulti(int ox, int oy, int nx, int ny) {
int xdiff = Math.abs(ox-nx);
int ydiff = Math.abs(oy-ny);
if (xdiff==ydiff) {
return true;
}
return false;
}
String[] diagonalMultiPath(int ox, int oy, int nx, int ny) {
int xdiff = nx-ox;
int ydiff = ny-oy;
//x and y will have seperate inxcrements depending on individual differences
int incx = xdiff>0?1:-1;
int ix = incx;
int incy = ydiff>0?1:-1;
int iy = incy;
String path[] = new String[Math.abs(xdiff)];
int p=0;
while (p<Math.abs(xdiff)) {
path[p] = (Integer.toString((ox+incx))+Integer.toString((oy+incy)));
incx+=ix;
incy+=iy;
p++;
}
return path;
}
boolean verticalMulti(int ox, int oy, int nx, int ny) {
if (nx-ox==0) {
return true;
}
return false;
}
String[] verticalMultiPath(int ox, int oy, int nx, int ny) {
int ydiff = ny-oy;
//x and y will have seperate inxcrements depending on individual differences
int incy = ydiff>0?1:-1;
int iy = incy;
String path[] = new String[Math.abs(ydiff)];
int p=0;
while (p<Math.abs(ydiff)) {
path[p] = (Integer.toString(ox)+Integer.toString((oy+incy)));
incy+=iy;
p++;
}
return path;
}
boolean horizontalMulti(int ox, int oy, int nx, int ny) {
if (ny-oy==0) {
return true;
}
return false;
}
String[] horizontalMultiPath(int ox, int oy, int nx, int ny) {
int xdiff = nx-ox;
//x and y will have seperate inxcrements depending on individual differences
int incx = xdiff>0?1:-1;
int ix = incx;
String path[] = new String[Math.abs(xdiff)];
int p=0;
while (p<Math.abs(xdiff)) {
path[p] = (Integer.toString((ox+incx))+Integer.toString(oy));
incx+=ix;
p++;
}
return path;
}
boolean jumpL(int ox, int oy, int nx, int ny) {
int xdiff = Math.abs(ox-nx);
int ydiff = Math.abs(oy-ny);
if (xdiff==1 && ydiff==2) {
return true;
}
if (xdiff==2 && ydiff==1) {
return true;
}
return false;
}
boolean omniOne(int ox, int oy, int nx, int ny) {
int xdiff = Math.abs(ox-nx);
int ydiff = Math.abs(oy-ny);
if (xdiff==1 && ydiff==0) {
return true;
}
if (xdiff==0 && ydiff==1) {
return true;
}
if (xdiff==1 && ydiff==1) {
return true;
}
return false;
}
boolean bottomUp(int ox, int oy, int nx, int ny) {
int ydiff = oy-ny;
int xdiff = nx-ox;
if (ydiff==1 && xdiff==0) {
return true;
}
return false;
}
boolean topDown(int ox, int oy, int nx, int ny) {
int ydiff = oy-ny;
int xdiff = nx-ox;
if (ydiff==-1 && xdiff==0) {
return true;
}
return false;
}
boolean bottomUp2(int ox, int oy, int nx, int ny) {
int ydiff = oy-ny;
int xdiff = nx-ox;
if (ydiff==2 && xdiff==0) {
return true;
}
return false;
}
boolean topDown2(int ox, int oy, int nx, int ny) {
int ydiff = oy-ny;
int xdiff = nx-ox;
if (ydiff==-2 && xdiff==0) {
return true;
}
return false;
}
boolean pawnAttack(int ox, int oy, int nx, int ny, boolean black) {
int xdiff = ox-nx;
int ydiff = oy - ny;
if (black) {
if (ydiff== 1 && (xdiff==1||xdiff==-1)) {
return true;
}
} else if (!black) {
if (ydiff == -1 && (xdiff==1||xdiff==-1)) {
return true;
}
}
return false;
}
boolean diagonalPiece(int ox, int oy, int nx, int ny, Board board, boolean black) {
int xdiff = (ox-nx);
int ydiff = (oy-ny);
if (black) {
if (board.getPiece(nx, ny)!=null && xdiff==1 && ydiff == 1) {
if (board.getPiece(nx, ny).black!=black) {
return true;
}
}
} else if (!black) {
if (board.getPiece(nx, ny)!=null && xdiff==1 && ydiff == -1) {
if (board.getPiece(nx, ny).black!=black) {
return true;
}
}
}
return false;
}
boolean forwardKill(int ox, int oy,String type){
if(type.equals("PawnB.png")){
if(board.getPiece(ox,oy-1)!=null){
return false;
}
}
if(type.equals("PawnW.png")){
if(board.getPiece(ox,oy+1)!=null){
return false;
}
}
return true;
}
boolean sameOverlap(int nx, int ny, Board board, boolean black) {
Piece a = board.getPiece(nx, ny);
if (a!=null && black==a.black) {
return true;
}
return false;
}
}