This commit is contained in:
Jacob Signorovitch
2025-04-24 12:15:57 -04:00
parent b305622f7f
commit 9309e6671c

View File

@@ -19,6 +19,15 @@ class Loc {
this.x = x;
this.y = y;
}
Loc up() { return new Loc(this.x, this.y - 1); }
Loc down() { return new Loc(this.x, this.y + 1); }
Loc right() { return new Loc(this.x + 1, this.y); }
Loc left() { return new Loc(this.x - 1, this.y); }
Loc up(PieceCol col) { return new Loc(this.x, this.y - 1 * col.n()); }
Loc down(PieceCol col) { return new Loc(this.x, this.y + 1 * col.n()); }
Loc right(PieceCol col) { return new Loc(this.x + 1, this.y * col.n()); }
Loc left(PieceCol col) { return new Loc(this.x - 1, this.y * col.n()); }
}
// The color a chess piece may assume.
@@ -30,7 +39,29 @@ enum PieceCol {
return this.equals(BLACK) ? new Color(0, 0, 0)
: new Color(255, 255, 255);
}
int n() { return this.equals(WHITE) ? 1 : -1; }
}
// The sort of piece.
enum PieceType { PAWN, ROOK, KNIGHT, BISHOP, QUEEN, KING }
abstract class Piece {
Loc loc;
PieceType type;
PieceCol col;
Piece(Loc loc, PieceType type, PieceCol col) {
this.loc = loc;
this.type = type;
this.col = col;
}
List<Loc> moves() { return List.of(this.loc.up(this.col)); }
}
class Pawn extends Piece {
Pawn(Loc loc, PieceType type, PieceCol col) { super(loc, type, col); }
List<Loc> moves() {}
}