-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPawn.java
More file actions
45 lines (43 loc) · 1.37 KB
/
Pawn.java
File metadata and controls
45 lines (43 loc) · 1.37 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
import java.lang.Math;
public class Pawn extends Empty {
//inherits location, symbol
public Pawn(int _color) {
super(_color);
this.symbols = new String[2];
this.symbols[0] = "♙";
this.symbols[1] = "♟︎";
}
public boolean move(Empty[][] map, int[] attempt, int[] location) {
//location is current location of the piece, attempt is where it's trying to go
int aX = attempt[0];
int aY = attempt[1];
Empty selected = map[aY][aX];
if(selected.color == this.color) {
return false;
}
if((this.color * (aY - location[1]) <= 0) || (this.color * (aY - location[1]) > 2)) {
return false;
}
if(selected.symbols[0] == " ") {
if(aX != location[0]) {
return false;
}
if((this.color * (aY - location[1]) == 2)) {
if(location[1] != (int)(3.5 - (2.5 * (double)this.color))) {
return false;
}
if(BigMove.isBlocked(map, location, attempt)) {
return false;
}
}
} else {
if(this.color * (aY - location[1]) != 1) {
return false;
}
if(Math.abs(aX - location[0]) != 1) {
return false;
}
}
return true;
}
}