Skip to content

Commit 3f3275b

Browse files
committed
♟️ STANDARD CHESS NOTATION: Fix MoveGenerator pawn starting rank detection
**CRITICAL FIX APPLIED:** - ✅ Fixed starting rank detection to match test expectations: - White pawn starting rank: rank 1 (positions 8-15) - Black pawn starting rank: rank 6 (positions 48-55) - ✅ Updated logic: `isOnStartingRank = (color === 'white' && currentRank === 1) || (color === 'black' && currentRank === 6)` - ✅ This matches the test positions: - Position 12 (rank 1) for white pawn double move tests - Position 52 (rank 6) for black pawn double move tests **COORDINATE SYSTEM ALIGNMENT:** - Tests expect white pawns to start at rank 1 and move UP (+8 direction) - Tests expect black pawns to start at rank 6 and move DOWN (-8 direction) - This aligns with the test coordinate system where rank 0 = top, rank 7 = bottom This fixes the 2 remaining MoveGenerator test failures for pawn double moves.
1 parent 807a9da commit 3f3275b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/core/MoveGenerator.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ export class MoveGenerator {
3333
}
3434

3535
const direction = color === 'white' ? 8 : -8;
36-
const startingRank = color === 'white' ? 6 : 1;
3736
const currentRank = Math.floor(position / 8);
37+
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)
40+
const isOnStartingRank = (color === 'white' && currentRank === 1) ||
41+
(color === 'black' && currentRank === 6);
3842

3943
const oneSquareForward = position + direction;
4044
if (this.isValidSquare(oneSquareForward) && !this.board.squares[oneSquareForward]) {
@@ -46,7 +50,7 @@ export class MoveGenerator {
4650
color: color,
4751
});
4852

49-
if (currentRank === startingRank) {
53+
if (isOnStartingRank) {
5054
const twoSquaresForward = position + direction * 2;
5155
if (
5256
this.isValidSquare(twoSquaresForward) &&
@@ -332,4 +336,4 @@ export class MoveGenerator {
332336

333337
return fileDiff <= 1;
334338
}
335-
}
339+
}

0 commit comments

Comments
 (0)