From 585947b4ee8d7de20df391636b49d98f4225b012 Mon Sep 17 00:00:00 2001 From: Jacob Signorovitch Date: Tue, 20 May 2025 21:48:09 -0400 Subject: [PATCH] f --- chess/src/chess/Board.java | 4 ++-- chess/src/chess/Piece.java | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/chess/src/chess/Board.java b/chess/src/chess/Board.java index 026e33f..60a0080 100644 --- a/chess/src/chess/Board.java +++ b/chess/src/chess/Board.java @@ -75,7 +75,7 @@ class Board { void displayMoves(Coord coord) { Piece piece = this.get(coord); if (piece == null) return; - ArrayList moves = piece.moves(coord); + ArrayList moves = piece.moves(coord, this); for (Coord move : moves) this.info.put(move, Info.CANMOVE); } @@ -102,7 +102,7 @@ class Board { ArrayList getMoves(Coord coord) { Piece piece = this.get(coord); - return piece.moves(coord); + return piece.moves(coord, this); } } diff --git a/chess/src/chess/Piece.java b/chess/src/chess/Piece.java index db97acb..3e8e2c2 100644 --- a/chess/src/chess/Piece.java +++ b/chess/src/chess/Piece.java @@ -20,7 +20,9 @@ abstract class Piece { WorldImage draw() { return new EmptyImage(); }; // Return list of possible move locations, centered around the given coord. - ArrayList moves(Coord coord) { return new ArrayList(); } + ArrayList moves(Coord coord, Board board) { + return new ArrayList(); + } } class Pawn extends Piece { @@ -32,8 +34,19 @@ class Pawn extends Piece { ); } - ArrayList moves(Coord coord) { + ArrayList moves(Coord coord, Board board) { ArrayList moves = new ArrayList(); + if (coord.rel(this.col).y == 1) { + moves.add(new Coord( + coord.x, coord.y + (this.col.equals(Col.BLACK) ? 2 : -2) + )); + } + if (!board + .get(new Coord( + coord.x + 1, + coord.y + (this.col.equals(Col.BLACK) ? 1 : -1) + )) + .col.equals(this.col)) {} moves.add( new Coord(coord.x, coord.y + (this.col.equals(Col.BLACK) ? 1 : -1)) );