MORE CHESS.
This commit is contained in:
@@ -2,8 +2,8 @@ package chess;
|
|||||||
|
|
||||||
// An actor is an entity capable of making descisions on the board.
|
// An actor is an entity capable of making descisions on the board.
|
||||||
abstract class Actor {
|
abstract class Actor {
|
||||||
ActorColor color;
|
ActorCol col;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The color an Actor may assume.
|
// The color an Actor may assume.
|
||||||
enum ActorColor { WHITE, BLACK }
|
enum ActorCol { WHITE, BLACK }
|
||||||
|
@@ -8,4 +8,26 @@ class Board {
|
|||||||
// Measured from top left.
|
// Measured from top left.
|
||||||
class Coord {
|
class Coord {
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
|
Coord(int x, int y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return coordinates relative to the selected color's position on the
|
||||||
|
// board. White on top, black on bottom.
|
||||||
|
Coord rel(ActorCol col) {
|
||||||
|
return col.equals(ActorCol.BLACK)
|
||||||
|
? new Coord(this.x, Util.boardW - this.y)
|
||||||
|
: this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whether two Coords are equal.
|
||||||
|
public Boolean equals(Coord that) {
|
||||||
|
return this.x == that.x && this.y == that.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return 31 * Integer.hashCode(this.x) + Integer.hashCode(this.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,15 @@
|
|||||||
package chess;
|
package chess;
|
||||||
|
|
||||||
// A chess piece.
|
// The piece types.
|
||||||
abstract class Piece {}
|
enum PieceType { PAWN, ROOK, KNIGHT, BISHOP, QUEEN, KING }
|
||||||
|
|
||||||
class Pawn extends Piece {}
|
// A chess piece.
|
||||||
|
abstract class Piece {
|
||||||
|
PieceType type;
|
||||||
|
|
||||||
|
Piece(PieceType type) { this.type = type; }
|
||||||
|
}
|
||||||
|
|
||||||
|
class Pawn extends Piece {
|
||||||
|
Pawn() { super(PieceType.PAWN); }
|
||||||
|
}
|
||||||
|
7
chess/src/chess/Util.java
Normal file
7
chess/src/chess/Util.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package chess;
|
||||||
|
|
||||||
|
// Utility class.
|
||||||
|
class Util {
|
||||||
|
// Width of a chessboard.
|
||||||
|
static int boardW = 8;
|
||||||
|
}
|
Reference in New Issue
Block a user