-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPiece.java
111 lines (96 loc) · 1.82 KB
/
Piece.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
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
// package mini_project;
public class Piece {
// constant integer piece type
public static final int KING = 1;
public static final int QUEEN = 2;
public static final int ROOK = 3;
public static final int KNIGHT = 4;
public static final int BISHOP = 5;
public static final int PAWN = 6;
private int color; // white = 0, black = 1
private int type; // type of piece
private int row, col; // position on board
// default constructor, used for blank space
public Piece() {
}
// constructor to create pieces
public Piece(int color, int type, int row, int col) {
this.color = color;
this.type = type;
this.row = row;
this.col = col;
}
// get piece name for board
public String getPieceName() {
String name = "";
if (getColor() == 0 && getType() != 0) {
name = "w";
} else {
name = "b";
}
switch (getType()) {
case 1:
name += "KI";
break;
case 2:
name += "QU";
break;
case 3:
name += "RK";
break;
case 4:
name += "KN";
break;
case 5:
name += "BI";
break;
case 6:
name += "PN";
break;
default: // show error to terminal, break
System.out.println("The given piece type is not in the valid range.");
break;
}
return name;
}
// get type
public int getType() {
return type;
}
// set type
public void setType(int type) {
this.type = type;
}
// get color
public int getColor() {
return color;
}
// get enemy color
public int getEnemyColor() {
if (color == 0) {
return 1;
} else {
return 0;
}
}
// set color
public void setColor(int color) {
this.color = color;
}
// get row
public int getRow() {
return row;
}
// set row
public void setRow(int row) {
this.row = row;
}
// get column
public int getCol() {
return col;
}
// set column
public void setCol(int col) {
this.col = col;
}
}