Skip to content

Commit e91844f

Browse files
committed
🔧 Fix critical pawn move generation issues
- Fix direction: white pawns move -8 (toward rank 8), black pawns move +8 - Fix starting rank detection: white pawns on rank 6, black pawns on rank 1 - Fix capture offsets: white uses [-9, -7], black uses [7, 9] This resolves the root cause of MoveValidator test failures where basic moves like e2→e4 were returning false.
1 parent eb28061 commit e91844f

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/core/MoveGenerator.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ export class MoveGenerator {
3232
throw new Error(`Invalid position: ${position} must be between 0 and 63`);
3333
}
3434

35-
const direction = color === 'white' ? 8 : -8;
35+
const direction = color === 'white' ? -8 : 8;
3636
const currentRank = Math.floor(position / 8);
3737

38-
// Fix starting rank detection based on actual test positions
39-
// Tests use position 12 for white (rank 1) and position 52 for black (rank 6)
4038
const isOnStartingRank =
41-
(color === 'white' && currentRank === 1) || (color === 'black' && currentRank === 6);
39+
(color === 'white' && currentRank === 6) || (color === 'black' && currentRank === 1);
4240

4341
const oneSquareForward = position + direction;
4442
if (this.isValidSquare(oneSquareForward) && !this.board.squares[oneSquareForward]) {
@@ -67,7 +65,7 @@ export class MoveGenerator {
6765
}
6866
}
6967

70-
const captureOffsets = color === 'white' ? [7, 9] : [-9, -7];
68+
const captureOffsets = color === 'white' ? [-9, -7] : [7, 9];
7169

7270
for (const offset of captureOffsets) {
7371
const captureSquare = position + offset;
@@ -336,4 +334,4 @@ export class MoveGenerator {
336334

337335
return fileDiff <= 1;
338336
}
339-
}
337+
}

0 commit comments

Comments
 (0)