-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiece.java
More file actions
67 lines (51 loc) · 1.38 KB
/
Piece.java
File metadata and controls
67 lines (51 loc) · 1.38 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
import java.util.ArrayList;
import java.util.List;
public abstract class Piece{
protected Coordinates position;
protected Player owner;
public Piece(int x, int y, Player owner){
position = new Coordinates(x,y);
this.owner = owner;
}
public enum Type {
KING,
QUEEN,
ROOK,
BISHOP,
KNIGHT,
PAWN
}
public void setPosition(Coordinates destination){
position = destination;
}
public Player getOwner(){
return this.owner;
}
public ChessColor getColor(){
return owner.color;
}
public Coordinates getPosition(){
return position;
}
public int getX(){
return position.getX();
}
public int getY(){
return position.getY();
}
public List<Move> getAllMoves(Board board) {
List<Move> allMoves = new ArrayList();
for (Coordinates coordinates : board.getAllCoordinates()){
if (isMoveAuthorized(board, coordinates) && coordinates !=null){
allMoves.add(new Move(board, this.getPosition(),coordinates));
}
}
return allMoves;
}
public boolean sameColor(Piece piece){
return this.getColor() == piece.getColor();
}
public abstract boolean isMoveAuthorized(Board board, Coordinates destination);
public abstract Type getType();
public abstract int getValue();
}