-
Notifications
You must be signed in to change notification settings - Fork 0
/
Knight.java
152 lines (116 loc) · 2.94 KB
/
Knight.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
package Chess;
import java.util.List;
public class Knight extends ChessPiece{
public Knight(String pos, char color, List<String> blocked, List<String> otherColorSpaces)
{
super(pos, color, blocked, otherColorSpaces);
}
@Override
protected List<String> getPossibleMoves()
{
up1Right2();
up2Right1();
up1Left2();
up2Left1();
down1Right2();
down2Right1();
down1Left2();
down2Left1();
return possibleMoves;
}
private void add(String move)
{
if(!blockedSpaces.contains(move))
{
possibleMoves.add(move);
}
}
private void up1Right2()
{
resetTrackers("UD RL");
up++;
right += 2;
if(checkUpperLowerBounds(up) && checkRightLeftBounds(right))
{
String move = right + "" + up;
add(move);
}
}
private void up2Right1()
{
resetTrackers("UD RL");
up += 2;
right++;
if(checkUpperLowerBounds(up) && checkRightLeftBounds(right))
{
String move = right + "" + up;
add(move);
}
}
private void up1Left2()
{
resetTrackers("UD RL");
up++;
left -= 2;
if(checkUpperLowerBounds(up) && checkRightLeftBounds(left))
{
String move = left + "" + up;
add(move);
}
}
private void up2Left1()
{
resetTrackers("UD RL");
up += 2;
left--;
if(checkUpperLowerBounds(up) && checkRightLeftBounds(left))
{
String move = left + "" + up;
add(move);
}
}
private void down1Right2()
{
resetTrackers("UD RL");
down--;
right += 2;
if(checkUpperLowerBounds(down) && checkRightLeftBounds(right))
{
String move = right + "" + down;
add(move);
}
}
private void down2Right1()
{
resetTrackers("UD RL");
down -= 2;
right++;
if(checkUpperLowerBounds(down) && checkRightLeftBounds(right))
{
String move = right + "" + down;
add(move);
}
}
private void down1Left2()
{
resetTrackers("UD RL");
down--;
left -= 2;
if(checkUpperLowerBounds(down) && checkRightLeftBounds(left))
{
String move = left + "" + down;
add(move);
}
}
private void down2Left1()
{
resetTrackers("UD RL");
down -= 2;
left--;
if(checkUpperLowerBounds(down) && checkRightLeftBounds(left))
{
String move = left + "" + down;
add(move);
}
}
}