-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPawn.java
67 lines (55 loc) · 1.37 KB
/
Pawn.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
import java.awt.Graphics;
import java.util.ArrayList;
public class Pawn extends Piece{
public int value;
public Pawn(int turn, int xloc, int yloc, String piece_name, int score) {
super(turn,xloc,yloc,piece_name, score);
}
@Override
// returns a list of possible moves, represented as x,y coordinates.
public ArrayList<int[]> get_moves(Piece[][] board) {
ArrayList<int[]> moves = new ArrayList<int[]>();
int i;
if (team == 0)
i = 1;
else
i = -1;
if (board[x + i][y].get_team() == -1) {
int[] move = {x+i,y};
moves.add(move);
}
if (team == 0 && x == 1 && board[x+1][y].get_team() == -1) {
int[] move = {x + 2, y};
moves.add(move);
}
if (team == 1 && x == 6 && board[x-1][y].get_team() == -1) {
int[] move = {x - 2, y};
moves.add(move);
}
if (y+1 < 8)
if (board[x + i][y+1].get_team() == (team+1)%2) {
int[] move = {x+i,y+1};
moves.add(move);
}
if (y-1 >= 0)
if (board[x + i][y-1].get_team() == (team+1)%2) {
int[] move = {x+i,y-1};
moves.add(move);
}
return moves;
}
@Override
public boolean check(King king, Piece[][] board) {
if (team == 0) {
if (king.get_loc()[0] - x == 1)
if (Math.abs(king.get_loc()[1] - y) == 1)
return true;
}
if (team == 1) {
if (king.get_loc()[0] - x == -1)
if (Math.abs(king.get_loc()[1] - y) == 1)
return true;
}
return false;
}
}