-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
91 lines (77 loc) · 2.94 KB
/
Player.java
File metadata and controls
91 lines (77 loc) · 2.94 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
import java.util.HashSet;
/* A player is a collection of 8 pawns, 2 rooks, 2 bishops, 2 knights a king,
* and a queen, all of the same color. They allow the Square objects to
* determine whether or not they are under attack, which thereby lets the
* program know whether or not the king can move to that square.
*/
public class Player {
private HashSet<Piece> pieces = new HashSet<Piece>();
private HashSet<Coord> squaresAttacked = new HashSet<Coord>();
private Shade clr;
private King k;
public Player(Shade c, Chessboard cb){
if (c == Shade.BLACK) {
pieces.add(new Pawn(Shade.BLACK, new int[]{0,6},cb));
pieces.add(new Pawn(Shade.BLACK, new int[]{1,6},cb));
pieces.add(new Pawn(Shade.BLACK, new int[]{2,6},cb));
pieces.add(new Pawn(Shade.BLACK, new int[]{3,6},cb));
pieces.add(new Pawn(Shade.BLACK, new int[]{4,6},cb));
pieces.add(new Pawn(Shade.BLACK, new int[]{5,6},cb));
pieces.add(new Pawn(Shade.BLACK, new int[]{6,6},cb));
pieces.add(new Pawn(Shade.BLACK, new int[]{7,6},cb));
pieces.add(new Rook(Shade.BLACK, new int[]{0,7},cb));
pieces.add(new Rook(Shade.BLACK, new int[]{7,7},cb));
pieces.add(new Knight(Shade.BLACK, new int[]{1,7},cb));
pieces.add(new Knight(Shade.BLACK, new int[]{6,7},cb));
pieces.add(new Bishop(Shade.BLACK, new int[]{2,7},cb));
pieces.add(new Bishop(Shade.BLACK, new int[]{5,7},cb));
pieces.add(new Queen(Shade.BLACK, new int[]{3,7},cb));
k = new King(Shade.BLACK, new int[]{4,7},cb);
pieces.add(k);
} else {
pieces.add(new Pawn(Shade.WHITE, new int[]{0,1},cb));
pieces.add(new Pawn(Shade.WHITE, new int[]{1,1},cb));
pieces.add(new Pawn(Shade.WHITE, new int[]{2,1},cb));
pieces.add(new Pawn(Shade.WHITE, new int[]{3,1},cb));
pieces.add(new Pawn(Shade.WHITE, new int[]{4,1},cb));
pieces.add(new Pawn(Shade.WHITE, new int[]{5,1},cb));
pieces.add(new Pawn(Shade.WHITE, new int[]{6,1},cb));
pieces.add(new Pawn(Shade.WHITE, new int[]{7,1},cb));
pieces.add(new Rook(Shade.WHITE, new int[]{0,0},cb));
pieces.add(new Rook(Shade.WHITE, new int[]{7,0},cb));
pieces.add(new Knight(Shade.WHITE, new int[]{1,0},cb));
pieces.add(new Knight(Shade.WHITE, new int[]{6,0},cb));
pieces.add(new Bishop(Shade.WHITE, new int[]{2,0},cb));
pieces.add(new Bishop(Shade.WHITE, new int[]{5,0},cb));
pieces.add(new Queen(Shade.WHITE, new int[]{3,0},cb));
k = new King(Shade.WHITE, new int[]{4,0},cb);
pieces.add(k);
}
clr = c;
}
public Shade getPlayerShade(){
return clr;
}
public HashSet<Coord> getSquaresAttacked(){
squaresAttacked.clear();
for (Piece p: pieces){
squaresAttacked.addAll(p.getAttack());
}
return squaresAttacked;
}
public Coord getKingCoord(){
return k.getCoord();
}
public void addPromotedPiece(Piece p){
pieces.add(p);
}
public HashSet<Piece> getPieces(){
return pieces;
}
public void clearPassant(){
for(Piece pc: pieces){
if (pc instanceof PassantShadow) ((PassantShadow) pc).remove();
}
return;
}
}