-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiece.java
More file actions
62 lines (49 loc) · 1.3 KB
/
Piece.java
File metadata and controls
62 lines (49 loc) · 1.3 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
import java.util.ArrayList;
public class Piece {
private String _side;
private Coordinate _position;
private ArrayList<Coordinate> moves;
public Piece( String side ){
_side = side;
moves = new ArrayList<Coordinate>();
}
public Piece( String side, int x, int y ){
_side = side;
_position = new Coordinate(x,y);
moves = new ArrayList<Coordinate>();
}
public ArrayList updateMoves( String[][] setup ){
int row = _position.getRow()-1;
int col = _position.getCol()-1;
for (int i = 0; i < 8; i++){
for (int j = 0; j < 8; j++){
if (validMove(setup,row,col,i,j)){
moves.add(new Coordinate((i+1),(j+1)));
}
}
}
return moves;
}
public boolean validMove( String[][] setup, int row, int col, int i, int j){
//SCENARIO 1: Spot is 1 square away diagonally, and has no piece. WORKING
if (setup[(i)][(j)].equals("BLACK") && Math.abs(row-i) == 1 && Math.abs(col-j) == 1){
return true;
}
return false;
}
public String toString(){
return _side + " " + _position;
}
public String getSide(){
return _side;
}
public ArrayList<Coordinate> getMoves(){
return moves;
}
public Coordinate getPosition(){
return _position;
}
public boolean hasMoves(){
return moves.size() != 0;
}
}//end class