MORE CHESS.

This commit is contained in:
Jacob Signorovitch
2025-04-24 14:46:14 -04:00
parent d046e04104
commit b6746d16a4
4 changed files with 43 additions and 5 deletions

View File

@@ -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 }

View File

@@ -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);
}
} }

View File

@@ -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); }
}

View File

@@ -0,0 +1,7 @@
package chess;
// Utility class.
class Util {
// Width of a chessboard.
static int boardW = 8;
}