-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPawn.java
109 lines (89 loc) · 2.77 KB
/
Pawn.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
package Chess;
import java.util.List;
public class Pawn extends ChessPiece{
public Pawn(String pos, char color, List<String> blocked, List<String> otherColorSpaces)
{
super(pos, color, blocked, otherColorSpaces);
}
@Override
protected List<String> getPossibleMoves()
{
forward();
capture();
return possibleMoves;
}
private void forward()
{
resetTrackers("UD");
if(color == 'w')
{
up++;
String currentPos = right + "" + up;
if(!blockedSpaces.contains(currentPos) && !otherColorSpaces.contains(currentPos) && checkUpperLowerBounds(up))
{
possibleMoves.add(currentPos);
up++;
currentPos = right + "" + up;
if(position[1] == '2' && !blockedSpaces.contains(currentPos) && !otherColorSpaces.contains(currentPos))
{
possibleMoves.add(currentPos);
}
}
}
else //black
{
down--;
String currentPos = right + "" + down;
if(!blockedSpaces.contains(currentPos) && !otherColorSpaces.contains(currentPos) && checkUpperLowerBounds(down))
{
possibleMoves.add(currentPos);
down--;
currentPos = right + "" + down;
if(position[1] == '7' && !blockedSpaces.contains(currentPos) && !otherColorSpaces.contains(currentPos))
{
possibleMoves.add(currentPos);
}
}
}
}
private void capture()
{
resetTrackers("UD RL");
if(color == 'w')
{
up++;
right++;
String upRight = right + "" + up;
if(otherColorSpaces.contains(upRight))
{
possibleMoves.add(upRight);
}
resetTrackers("UD RL");
up++;
left--;
String upLeft = left + "" + up;
if(otherColorSpaces.contains(upLeft))
{
possibleMoves.add(upLeft);
}
}
else
{
down--;
right++;
String downRight = right + "" + down;
if(otherColorSpaces.contains(downRight))
{
possibleMoves.add(downRight);
}
resetTrackers("UD RL");
down--;
left--;
String downLeft = left + "" + down;
if(otherColorSpaces.contains(downLeft))
{
possibleMoves.add(downLeft);
}
}
}
}