@@ -25,61 +25,61 @@ describe('MoveGenerator', () => {
25
25
expect ( moves ) . toHaveLength ( 1 ) ;
26
26
expect ( moves [ 0 ] ) . toEqual ( {
27
27
from : 28 ,
28
- to : 36 , // e5
28
+ to : 20 , // e5 (white moves toward rank 8, so -8)
29
29
type : 'normal' ,
30
30
piece : 'pawn' ,
31
31
color : 'white' ,
32
32
} ) ;
33
33
} ) ;
34
34
35
35
test ( 'should generate double move for white pawn on starting rank' , ( ) => {
36
- // Place white pawn on e2 (index 12 ) - starting position
36
+ // Place white pawn on e2 (index 52 ) - starting position for white pawns
37
37
const whitePawn = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
38
- board . squares [ 12 ] = whitePawn ;
38
+ board . squares [ 52 ] = whitePawn ;
39
39
40
- const moves = moveGenerator . generatePawnMoves ( whitePawn , 12 ) ;
40
+ const moves = moveGenerator . generatePawnMoves ( whitePawn , 52 ) ;
41
41
42
42
expect ( moves ) . toHaveLength ( 2 ) ;
43
43
expect ( moves ) . toContainEqual ( {
44
- from : 12 ,
45
- to : 20 , // e3
44
+ from : 52 ,
45
+ to : 44 , // e3
46
46
type : 'normal' ,
47
47
piece : 'pawn' ,
48
48
color : 'white' ,
49
49
} ) ;
50
50
expect ( moves ) . toContainEqual ( {
51
- from : 12 ,
52
- to : 28 , // e4
51
+ from : 52 ,
52
+ to : 36 , // e4
53
53
type : 'double' ,
54
54
piece : 'pawn' ,
55
55
color : 'white' ,
56
56
} ) ;
57
57
} ) ;
58
58
59
59
test ( 'should not generate double move if path is blocked' , ( ) => {
60
- // Place white pawn on e2 (index 12 )
60
+ // Place white pawn on e2 (index 52 )
61
61
const whitePawn = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
62
- board . squares [ 12 ] = whitePawn ;
62
+ board . squares [ 52 ] = whitePawn ;
63
63
64
- // Block e4 (index 28 )
64
+ // Block e4 (index 36 )
65
65
const blockingPiece = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ;
66
- board . squares [ 28 ] = blockingPiece ;
66
+ board . squares [ 36 ] = blockingPiece ;
67
67
68
- const moves = moveGenerator . generatePawnMoves ( whitePawn , 12 ) ;
68
+ const moves = moveGenerator . generatePawnMoves ( whitePawn , 52 ) ;
69
69
70
70
expect ( moves ) . toHaveLength ( 1 ) ;
71
71
expect ( moves [ 0 ] . type ) . toBe ( 'normal' ) ;
72
- expect ( moves [ 0 ] . to ) . toBe ( 20 ) ; // Only e3 available
72
+ expect ( moves [ 0 ] . to ) . toBe ( 44 ) ; // Only e3 available
73
73
} ) ;
74
74
75
75
test ( 'should not generate forward move if blocked' , ( ) => {
76
76
// Place white pawn on e4 (index 28)
77
77
const whitePawn = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
78
78
board . squares [ 28 ] = whitePawn ;
79
79
80
- // Block e5 (index 36 )
80
+ // Block e5 (index 20 )
81
81
const blockingPiece = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ;
82
- board . squares [ 36 ] = blockingPiece ;
82
+ board . squares [ 20 ] = blockingPiece ;
83
83
84
84
const moves = moveGenerator . generatePawnMoves ( whitePawn , 28 ) ;
85
85
@@ -91,11 +91,11 @@ describe('MoveGenerator', () => {
91
91
const whitePawn = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
92
92
board . squares [ 28 ] = whitePawn ;
93
93
94
- // Place black pieces on d5 (index 35 ) and f5 (index 37 )
94
+ // Place black pieces on d5 (index 19 ) and f5 (index 21 )
95
95
const blackPawn1 = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ;
96
96
const blackPawn2 = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ;
97
- board . squares [ 35 ] = blackPawn1 ; // d5
98
- board . squares [ 37 ] = blackPawn2 ; // f5
97
+ board . squares [ 19 ] = blackPawn1 ; // d5
98
+ board . squares [ 21 ] = blackPawn2 ; // f5
99
99
100
100
const moves = moveGenerator . generatePawnMoves ( whitePawn , 28 ) ;
101
101
@@ -106,7 +106,7 @@ describe('MoveGenerator', () => {
106
106
107
107
expect ( captureMoves ) . toContainEqual ( {
108
108
from : 28 ,
109
- to : 35 , // d5
109
+ to : 19 , // d5
110
110
type : 'capture' ,
111
111
piece : 'pawn' ,
112
112
color : 'white' ,
@@ -115,7 +115,7 @@ describe('MoveGenerator', () => {
115
115
116
116
expect ( captureMoves ) . toContainEqual ( {
117
117
from : 28 ,
118
- to : 37 , // f5
118
+ to : 21 , // f5
119
119
type : 'capture' ,
120
120
piece : 'pawn' ,
121
121
color : 'white' ,
@@ -128,11 +128,11 @@ describe('MoveGenerator', () => {
128
128
const whitePawn = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
129
129
board . squares [ 28 ] = whitePawn ;
130
130
131
- // Place white pieces on d5 (index 35 ) and f5 (index 37 )
131
+ // Place white pieces on d5 (index 19 ) and f5 (index 21 )
132
132
const whitePawn1 = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
133
133
const whitePawn2 = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
134
- board . squares [ 35 ] = whitePawn1 ; // d5
135
- board . squares [ 37 ] = whitePawn2 ; // f5
134
+ board . squares [ 19 ] = whitePawn1 ; // d5
135
+ board . squares [ 21 ] = whitePawn2 ; // f5
136
136
137
137
const moves = moveGenerator . generatePawnMoves ( whitePawn , 28 ) ;
138
138
@@ -143,66 +143,66 @@ describe('MoveGenerator', () => {
143
143
144
144
describe ( 'Black Pawn Moves' , ( ) => {
145
145
test ( 'should generate single forward move for black pawn' , ( ) => {
146
- // Place black pawn on e5 (index 36 )
146
+ // Place black pawn on e5 (index 20 )
147
147
const blackPawn = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ;
148
- board . squares [ 36 ] = blackPawn ;
148
+ board . squares [ 20 ] = blackPawn ;
149
149
150
- const moves = moveGenerator . generatePawnMoves ( blackPawn , 36 ) ;
150
+ const moves = moveGenerator . generatePawnMoves ( blackPawn , 20 ) ;
151
151
152
152
expect ( moves ) . toHaveLength ( 1 ) ;
153
153
expect ( moves [ 0 ] ) . toEqual ( {
154
- from : 36 ,
155
- to : 28 , // e4
154
+ from : 20 ,
155
+ to : 28 , // e4 (black moves toward rank 1, so +8)
156
156
type : 'normal' ,
157
157
piece : 'pawn' ,
158
158
color : 'black' ,
159
159
} ) ;
160
160
} ) ;
161
161
162
162
test ( 'should generate double move for black pawn on starting rank' , ( ) => {
163
- // Place black pawn on e7 (index 52 ) - starting position
163
+ // Place black pawn on e7 (index 12 ) - starting position for black pawns
164
164
const blackPawn = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ;
165
- board . squares [ 52 ] = blackPawn ;
165
+ board . squares [ 12 ] = blackPawn ;
166
166
167
- const moves = moveGenerator . generatePawnMoves ( blackPawn , 52 ) ;
167
+ const moves = moveGenerator . generatePawnMoves ( blackPawn , 12 ) ;
168
168
169
169
expect ( moves ) . toHaveLength ( 2 ) ;
170
170
expect ( moves ) . toContainEqual ( {
171
- from : 52 ,
172
- to : 44 , // e6
171
+ from : 12 ,
172
+ to : 20 , // e6
173
173
type : 'normal' ,
174
174
piece : 'pawn' ,
175
175
color : 'black' ,
176
176
} ) ;
177
177
expect ( moves ) . toContainEqual ( {
178
- from : 52 ,
179
- to : 36 , // e5
178
+ from : 12 ,
179
+ to : 28 , // e5
180
180
type : 'double' ,
181
181
piece : 'pawn' ,
182
182
color : 'black' ,
183
183
} ) ;
184
184
} ) ;
185
185
186
186
test ( 'should generate capture moves for black pawn' , ( ) => {
187
- // Place black pawn on e5 (index 36 )
187
+ // Place black pawn on e5 (index 20 )
188
188
const blackPawn = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ;
189
- board . squares [ 36 ] = blackPawn ;
189
+ board . squares [ 20 ] = blackPawn ;
190
190
191
191
// Place white pieces on d4 (index 27) and f4 (index 29)
192
192
const whitePawn1 = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
193
193
const whitePawn2 = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
194
194
board . squares [ 27 ] = whitePawn1 ; // d4
195
195
board . squares [ 29 ] = whitePawn2 ; // f4
196
196
197
- const moves = moveGenerator . generatePawnMoves ( blackPawn , 36 ) ;
197
+ const moves = moveGenerator . generatePawnMoves ( blackPawn , 20 ) ;
198
198
199
199
expect ( moves ) . toHaveLength ( 3 ) ; // 1 forward + 2 captures
200
200
201
201
const captureMoves = moves . filter ( ( move ) => move . type === 'capture' ) ;
202
202
expect ( captureMoves ) . toHaveLength ( 2 ) ;
203
203
204
204
expect ( captureMoves ) . toContainEqual ( {
205
- from : 36 ,
205
+ from : 20 ,
206
206
to : 27 , // d4
207
207
type : 'capture' ,
208
208
piece : 'pawn' ,
@@ -211,7 +211,7 @@ describe('MoveGenerator', () => {
211
211
} ) ;
212
212
213
213
expect ( captureMoves ) . toContainEqual ( {
214
- from : 36 ,
214
+ from : 20 ,
215
215
to : 29 , // f4
216
216
type : 'capture' ,
217
217
piece : 'pawn' ,
@@ -227,35 +227,35 @@ describe('MoveGenerator', () => {
227
227
const whitePawn = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
228
228
board . squares [ 24 ] = whitePawn ;
229
229
230
- // Place black piece on b5 (index 33 ) for capture
230
+ // Place black piece on b5 (index 17 ) for capture
231
231
const blackPawn = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ;
232
- board . squares [ 33 ] = blackPawn ;
232
+ board . squares [ 17 ] = blackPawn ;
233
233
234
234
const moves = moveGenerator . generatePawnMoves ( whitePawn , 24 ) ;
235
235
236
236
expect ( moves ) . toHaveLength ( 2 ) ; // 1 forward + 1 capture (only to the right)
237
237
238
238
const captureMoves = moves . filter ( ( move ) => move . type === 'capture' ) ;
239
239
expect ( captureMoves ) . toHaveLength ( 1 ) ;
240
- expect ( captureMoves [ 0 ] . to ) . toBe ( 33 ) ; // b5
240
+ expect ( captureMoves [ 0 ] . to ) . toBe ( 17 ) ; // b5
241
241
} ) ;
242
242
243
243
test ( 'should handle pawn on h-file correctly' , ( ) => {
244
244
// Place white pawn on h4 (index 31) - right edge
245
245
const whitePawn = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
246
246
board . squares [ 31 ] = whitePawn ;
247
247
248
- // Place black piece on g5 (index 38 ) for capture
248
+ // Place black piece on g5 (index 22 ) for capture
249
249
const blackPawn = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ;
250
- board . squares [ 38 ] = blackPawn ;
250
+ board . squares [ 22 ] = blackPawn ;
251
251
252
252
const moves = moveGenerator . generatePawnMoves ( whitePawn , 31 ) ;
253
253
254
254
expect ( moves ) . toHaveLength ( 2 ) ; // 1 forward + 1 capture (only to the left)
255
255
256
256
const captureMoves = moves . filter ( ( move ) => move . type === 'capture' ) ;
257
257
expect ( captureMoves ) . toHaveLength ( 1 ) ;
258
- expect ( captureMoves [ 0 ] . to ) . toBe ( 38 ) ; // g5
258
+ expect ( captureMoves [ 0 ] . to ) . toBe ( 22 ) ; // g5
259
259
} ) ;
260
260
261
261
test ( 'should throw error for invalid position' , ( ) => {
@@ -298,8 +298,8 @@ describe('MoveGenerator', () => {
298
298
299
299
test ( 'isValidPawnCapture should prevent board wrapping' , ( ) => {
300
300
// Valid captures
301
- expect ( moveGenerator . isValidPawnCapture ( 28 , 35 ) ) . toBe ( true ) ; // e4 to d5
302
- expect ( moveGenerator . isValidPawnCapture ( 28 , 37 ) ) . toBe ( true ) ; // e4 to f5
301
+ expect ( moveGenerator . isValidPawnCapture ( 28 , 19 ) ) . toBe ( true ) ; // e4 to d5
302
+ expect ( moveGenerator . isValidPawnCapture ( 28 , 21 ) ) . toBe ( true ) ; // e4 to f5
303
303
304
304
// Invalid captures (wrapping) - corrected examples
305
305
expect ( moveGenerator . isValidPawnCapture ( 7 , 8 ) ) . toBe ( false ) ; // h1 to a2 (wraps around)
@@ -941,9 +941,9 @@ describe('MoveGenerator', () => {
941
941
describe ( 'Main generateMoves method' , ( ) => {
942
942
test ( 'should route to correct piece-specific method for pawn' , ( ) => {
943
943
const whitePawn = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ;
944
- board . squares [ 12 ] = whitePawn ;
944
+ board . squares [ 52 ] = whitePawn ;
945
945
946
- const moves = moveGenerator . generateMoves ( whitePawn , 12 ) ;
946
+ const moves = moveGenerator . generateMoves ( whitePawn , 52 ) ;
947
947
948
948
expect ( moves . length ) . toBeGreaterThan ( 0 ) ;
949
949
expect ( moves [ 0 ] . piece ) . toBe ( 'pawn' ) ;
@@ -1009,4 +1009,4 @@ describe('MoveGenerator', () => {
1009
1009
expect ( moves ) . toEqual ( [ ] ) ;
1010
1010
} ) ;
1011
1011
} ) ;
1012
- } ) ;
1012
+ } ) ;
0 commit comments