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
/**
*Board and movement of pieces
*@author arghavan soleymanpour
*@version 2.0
*/
package Pieces;
import Main.Board;
import java.util.ArrayList;
public abstract class Piece implements Cloneable {
private int x;
private boolean isWhite;
private int y;
private Board board;
public Piece(int x , int y , boolean isWhite , Board board){
this.x = x;
this.y = y;
this.isWhite = isWhite;
this.board = board;
}
/**
* This is the method for Color of Piece
* @return isWhite.
*/
public boolean isWhite(){
return isWhite;
}
/**
* This is the method for Color of Piece
* @return isBlack.
*/
public boolean isBlack(){
return !isWhite;
}
/**
* This is the method for x-axis of Piece
* @return x-axis.
*/
public int getX() {
return x;
}
public Board getBoard() {
return board;
}
/**
* This is the method for set x-axis of Piece
* @param x x-axis
* @return void.
*/
public void setX(int x) {
this.x = x;
}
/**
* This is the method for y-axis of Piece
* @return y-axis.
*/
public int getY() {
return y;
}
/**
* This is the method for set y-axis of Piece
* @param y y-axis
* @return void.
*/
public void setY(int y) {
this.y = y;
}
/**
* This is the method for validate move of piece
* @param dx destination x
* @param dy destination y
* @return is a Valid move.
*/
abstract public boolean isValidMove(int dx,int dy);
/**
* This is the method for list of valid move of piece
* @return list of valid moves of piece.
*/
abstract public ArrayList<int[]> moves();
/**
* This is the method for check outside of piece
* @param dx destination x.
* @param dy destination y.
* @return is destination outside?.
*/
public boolean isOutside(int dx, int dy){
if (dx < 0 || dx > 8 || dy < 0 || dy > 8)
return false;
return true;
}
public Object clone(){
try {
return super.clone();
} catch (CloneNotSupportedException e) {
System.err.println("Clone Error");
e.printStackTrace();
}
return null;
}
}