From 9309e6671c090eb18ff3864557e9cbbaac14514c Mon Sep 17 00:00:00 2001 From: Jacob Signorovitch Date: Thu, 24 Apr 2025 12:15:57 -0400 Subject: [PATCH] Yes. --- chess/src/chess/Main.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/chess/src/chess/Main.java b/chess/src/chess/Main.java index 70e6cdb..c69a5d7 100644 --- a/chess/src/chess/Main.java +++ b/chess/src/chess/Main.java @@ -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 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 moves() {} +}