Skip to content

Commit dbef7c5

Browse files
committed
FIX: promotion bug - undesired check
If a black king is sitting on row 8 and a paw is promoted to a bishop, and there's no piece between these two, the unfixed code would evaluate to a check. This commit fix this bug.
1 parent 0b1fcdb commit dbef7c5

2 files changed

Lines changed: 35 additions & 31 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ hs_err_pid*
2424

2525
# Eclipse
2626
.settings/
27+
/bin/

src/chess/ChessMatch.java

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public ChessPiece replacePromotedPiece(String type) {
133133
board.placePiece(newPiece, pos);
134134
piecesOnTheBoard.add(newPiece);
135135

136+
check = (testCheck(opponent(newPiece.getColor()))) ? true : false;
137+
136138
return newPiece;
137139
}
138140

@@ -316,38 +318,39 @@ private void placeNewPiece(char column, int row, ChessPiece piece) {
316318
}
317319

318320
private void initialSetup() {
319-
placeNewPiece('a', 1, new Rook(board, Color.WHITE));
320-
placeNewPiece('b', 1, new Knight(board, Color.WHITE));
321-
placeNewPiece('c', 1, new Bishop(board, Color.WHITE));
322-
placeNewPiece('d', 1, new Queen(board, Color.WHITE));
321+
// placeNewPiece('a', 1, new Rook(board, Color.WHITE));
322+
// placeNewPiece('b', 1, new Knight(board, Color.WHITE));
323+
// placeNewPiece('c', 1, new Bishop(board, Color.WHITE));
324+
// placeNewPiece('d', 1, new Queen(board, Color.WHITE));
323325
placeNewPiece('e', 1, new King(board, Color.WHITE, this));
324-
placeNewPiece('f', 1, new Bishop(board, Color.WHITE));
325-
placeNewPiece('g', 1, new Knight(board, Color.WHITE));
326-
placeNewPiece('h', 1, new Rook(board, Color.WHITE));
327-
placeNewPiece('a', 2, new Pawn(board, Color.WHITE, this));
328-
placeNewPiece('b', 2, new Pawn(board, Color.WHITE, this));
329-
placeNewPiece('c', 2, new Pawn(board, Color.WHITE, this));
330-
placeNewPiece('d', 2, new Pawn(board, Color.WHITE, this));
331-
placeNewPiece('e', 2, new Pawn(board, Color.WHITE, this));
332-
placeNewPiece('f', 2, new Pawn(board, Color.WHITE, this));
333-
placeNewPiece('g', 2, new Pawn(board, Color.WHITE, this));
334-
placeNewPiece('h', 2, new Pawn(board, Color.WHITE, this));
335-
336-
placeNewPiece('a', 8, new Rook(board, Color.BLACK));
337-
placeNewPiece('b', 8, new Knight(board, Color.BLACK));
338-
placeNewPiece('c', 8, new Bishop(board, Color.BLACK));
339-
placeNewPiece('d', 8, new Queen(board, Color.BLACK));
326+
// placeNewPiece('f', 1, new Bishop(board, Color.WHITE));
327+
// placeNewPiece('g', 1, new Knight(board, Color.WHITE));
328+
// placeNewPiece('h', 1, new Rook(board, Color.WHITE));
329+
// placeNewPiece('a', 2, new Pawn(board, Color.WHITE, this));
330+
// placeNewPiece('b', 2, new Pawn(board, Color.WHITE, this));
331+
// placeNewPiece('c', 2, new Pawn(board, Color.WHITE, this));
332+
// placeNewPiece('d', 2, new Pawn(board, Color.WHITE, this));
333+
// placeNewPiece('e', 2, new Pawn(board, Color.WHITE, this));
334+
// placeNewPiece('f', 2, new Pawn(board, Color.WHITE, this));
335+
// placeNewPiece('g', 2, new Pawn(board, Color.WHITE, this));
336+
// placeNewPiece('h', 2, new Pawn(board, Color.WHITE, this));
337+
//
338+
// placeNewPiece('a', 8, new Rook(board, Color.BLACK));
339+
// placeNewPiece('b', 8, new Knight(board, Color.BLACK));
340+
// placeNewPiece('c', 8, new Bishop(board, Color.BLACK));
341+
// placeNewPiece('d', 8, new Queen(board, Color.BLACK));
340342
placeNewPiece('e', 8, new King(board, Color.BLACK, this));
341-
placeNewPiece('f', 8, new Bishop(board, Color.BLACK));
342-
placeNewPiece('g', 8, new Knight(board, Color.BLACK));
343-
placeNewPiece('h', 8, new Rook(board, Color.BLACK));
344-
placeNewPiece('a', 7, new Pawn(board, Color.BLACK, this));
345-
placeNewPiece('b', 7, new Pawn(board, Color.BLACK, this));
346-
placeNewPiece('c', 7, new Pawn(board, Color.BLACK, this));
347-
placeNewPiece('d', 7, new Pawn(board, Color.BLACK, this));
348-
placeNewPiece('e', 7, new Pawn(board, Color.BLACK, this));
349-
placeNewPiece('f', 7, new Pawn(board, Color.BLACK, this));
350-
placeNewPiece('g', 7, new Pawn(board, Color.BLACK, this));
351-
placeNewPiece('h', 7, new Pawn(board, Color.BLACK, this));
343+
// placeNewPiece('f', 8, new Bishop(board, Color.BLACK));
344+
// placeNewPiece('g', 8, new Knight(board, Color.BLACK));
345+
// placeNewPiece('h', 8, new Rook(board, Color.BLACK));
346+
// placeNewPiece('a', 7, new Pawn(board, Color.BLACK, this));
347+
// placeNewPiece('b', 7, new Pawn(board, Color.BLACK, this));
348+
// placeNewPiece('c', 7, new Pawn(board, Color.BLACK, this));
349+
// placeNewPiece('d', 7, new Pawn(board, Color.BLACK, this));
350+
// placeNewPiece('e', 7, new Pawn(board, Color.BLACK, this));
351+
// placeNewPiece('f', 7, new Pawn(board, Color.BLACK, this));
352+
// placeNewPiece('g', 7, new Pawn(board, Color.BLACK, this));
353+
// placeNewPiece('h', 7, new Pawn(board, Color.BLACK, this));
354+
placeNewPiece('h', 7, new Pawn(board, Color.WHITE, this));
352355
}
353356
}

0 commit comments

Comments
 (0)