-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChessPiece.java
87 lines (72 loc) · 1.96 KB
/
ChessPiece.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
package Chess;
import java.util.ArrayList;
import java.util.List;
//Parent class for Pawn, Bishop, Knight, Rook, Queen, and King
public abstract class ChessPiece {
protected ArrayList<String> possibleMoves;
protected char[] position;
protected char color, right, left, up, down;
protected int start;
protected List<String> blockedSpaces; //same color
protected List<String> otherColorSpaces;
public ChessPiece(String pos, char color, List<String> blocked, List<String> otherColorSpaces)
{
this.possibleMoves = new ArrayList<>();
this.position = pos.toCharArray();
this.color = color;
this.blockedSpaces = blocked;
this.otherColorSpaces = otherColorSpaces;
this.right = position[0];
this.left = position[0];
this.up = position[1];
this.down = position[1];
if(color == 'w')
{
start = 1;
}
else
{
start = 8;
}
}
protected List<String> getPossibleMoves()
{
return possibleMoves;
}
protected void resetTrackers(String delim)
{
if(delim.contains("RL"))
{
this.right = position[0];
this.left = position[0];
}
if(delim.contains("UD"))
{
this.up = position[1];
this.down = position[1];
}
}
protected void printPossibleMoves(String ptm, List<String> moves)
{
String c;
if(color == 'w')
{
c = "WHITE";
}
else
{
c = "BLACK";
}
System.out.println("LEGAL MOVES FOR " + c + " " + ptm + ": " + moves.toString());
}
//Numbers
protected boolean checkUpperLowerBounds(char ud)
{
return ud > 48 && ud < 57;
}
//Letters
protected boolean checkRightLeftBounds(char rl)
{
return rl > 96 && rl < 105;
}
}