-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiece.java
More file actions
159 lines (135 loc) · 3.93 KB
/
Copy pathPiece.java
File metadata and controls
159 lines (135 loc) · 3.93 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
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
/**
* Piece
*
* @author Faiza Salami, 7941056
* <p>
* REMARKS: An abstract piece class representing the pieces on the chess board
*/
public abstract class Piece {
char piece;
Piece captured;
public Piece(char piece) {
this.piece = piece;
captured = null;
}
/**
* checks if a piece captured a king
*
* @return boolean-returns true if the king has been captured and false otherwise
*/
public boolean capturedKing() {
if (captured != null) {
return captured.name().equals("King");
}
return false;
}
/**
* checks if its a player's piece
*
* @return boolean-returns true if its a player's piece and false otherwise
*/
public boolean isPlayerPiece() {
return Character.isUpperCase(piece);
}
/**
* checks if its an AI's piece
*
* @return boolean-returns true if its an AI's piece and false otherwise
*/
public boolean isAIPiece() {
return Character.isLowerCase(piece);
}
//getter
public char getPiece() {
return piece;
}
public Piece getCaptured() {
return captured;
}
//setter
public void setPiece(char piece) {
this.piece = piece;
}
public void setCaptured(Piece captured) {
this.captured = captured;
}
/**
* checks if the move being made is valid for a player's piece
*
* @param move the move that was made
* @param gameBoard the current game board
* @return boolean-returns true if the move is valid and false otherwise
*/
public abstract boolean validMove(Move move, Board gameBoard);
/**
* generate a move for the AI piece, easy mode. this method just moves the piece by one square
*
* @param move the move containing where the piece currently is
* @param gameBoard the current game board
* @return boolean-returns the move containing what location the piece is moving to or null if there's no available
* space for the piece to move to
*/
public abstract Move generateMove(Move move, Board gameBoard);
/**
* checks if any of the player's piece is in the AI piece's vicinity to be captured
*
* @param move the move containing the piece's current location
* @param gameBoard the current game board
* @return Move-the move containing what location the piece is moving to or null if the piece cant capture any player's piece
*/
public abstract Move capturePlayerPiece(Move move, Board gameBoard);
/**
* checks if the piece is a pawn
*
* @return boolean-returns true if it's a pawn and false otherwise
*/
public boolean isPawn() {
return piece == 'P' || piece == 'p';
}
/**
* checks if the piece is a rook
*
* @return boolean-returns true if it's a rook and false otherwise
*/
public boolean isRook() {
return piece == 'R' || piece == 'r';
}
/**
* checks if the piece is a knight
*
* @return boolean-returns true if it's a knight and false otherwise
*/
public boolean isKnight() {
return piece == 'N' || piece == 'n';
}
/**
* checks if the piece is a bishop
*
* @return boolean-returns true if it's a bishop and false otherwise
*/
public boolean isBishop() {
return piece == 'B' || piece == 'b';
}
/**
* checks if the piece is a king
*
* @return boolean-returns true if it's a king and false otherwise
*/
public boolean isKing() {
return piece == 'K' || piece == 'k';
}
/**
* checks if the piece is a queen
*
* @return boolean-returns true if it's a queen and false otherwise
*/
public boolean isQueen() {
return piece == 'Q' || piece == 'q';
}
/**
* the name of the piece
*
* @return returns the piece name
*/
public abstract String name();
}