diff --git a/chess/src/chess/Actor.java b/chess/src/chess/Actor.java index 395dabb..f12fac4 100644 --- a/chess/src/chess/Actor.java +++ b/chess/src/chess/Actor.java @@ -2,8 +2,8 @@ package chess; // An actor is an entity capable of making descisions on the board. abstract class Actor { - ActorColor color; + ActorCol col; } // The color an Actor may assume. -enum ActorColor { WHITE, BLACK } +enum ActorCol { WHITE, BLACK } diff --git a/chess/src/chess/Board.java b/chess/src/chess/Board.java index c4664bc..8092c8d 100644 --- a/chess/src/chess/Board.java +++ b/chess/src/chess/Board.java @@ -8,4 +8,26 @@ class Board { // Measured from top left. class Coord { 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); + } } diff --git a/chess/src/chess/Piece.java b/chess/src/chess/Piece.java index 1a60ee8..5c78bbb 100644 --- a/chess/src/chess/Piece.java +++ b/chess/src/chess/Piece.java @@ -1,6 +1,15 @@ package chess; -// A chess piece. -abstract class Piece {} +// The piece types. +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); } +} diff --git a/chess/src/chess/Util.java b/chess/src/chess/Util.java new file mode 100644 index 0000000..fa49665 --- /dev/null +++ b/chess/src/chess/Util.java @@ -0,0 +1,7 @@ +package chess; + +// Utility class. +class Util { + // Width of a chessboard. + static int boardW = 8; +}