@@ -17,24 +17,28 @@ describe('Board', () => {
17
17
test ( 'should correctly set up initial board with pieces' , ( ) => {
18
18
board . setupInitialBoard ( ) ;
19
19
// Check a few specific squares
20
- expect ( board . squares [ 0 ] ) . not . toBeNull ( ) ; // Rook at a1
21
- expect ( board . squares [ 1 ] ) . not . toBeNull ( ) ; // Knight at b1
22
- expect ( board . squares [ 8 ] ) . not . toBeNull ( ) ; // Pawn at a2
23
- expect ( board . squares [ 63 ] ) . not . toBeNull ( ) ; // Rook at h8
24
- expect ( board . squares [ 55 ] ) . not . toBeNull ( ) ; // Pawn at h7
20
+ expect ( board . squares [ 0 ] ) . not . toBeNull ( ) ; // Rook at a8 (black back rank)
21
+ expect ( board . squares [ 1 ] ) . not . toBeNull ( ) ; // Knight at b8
22
+ expect ( board . squares [ 8 ] ) . not . toBeNull ( ) ; // Pawn at a7 (black pawn)
23
+ expect ( board . squares [ 63 ] ) . not . toBeNull ( ) ; // Rook at h1 (white back rank)
24
+ expect ( board . squares [ 48 ] ) . not . toBeNull ( ) ; // Pawn at a2 (white pawn)
25
25
26
- // Check piece types and colors using getter methods (example for white pawn at a2 )
26
+ // Check piece types and colors using getter methods (black pawn at a7 )
27
27
expect ( board . squares [ 8 ] . getType ( ) ) . toBe ( 'pawn' ) ;
28
- expect ( board . squares [ 8 ] . getColor ( ) ) . toBe ( 'white' ) ;
28
+ expect ( board . squares [ 8 ] . getColor ( ) ) . toBe ( 'black' ) ;
29
+
30
+ // Check white pawn at a2 (position 48)
31
+ expect ( board . squares [ 48 ] . getType ( ) ) . toBe ( 'pawn' ) ;
32
+ expect ( board . squares [ 48 ] . getColor ( ) ) . toBe ( 'white' ) ;
29
33
30
34
// Check empty square in the middle
31
35
expect ( board . squares [ 20 ] ) . toBeNull ( ) ;
32
36
} ) ;
33
37
34
38
test ( 'should move a piece from one square to another' , ( ) => {
35
39
board . setupInitialBoard ( ) ;
36
- const originalPiece = board . squares [ 0 ] ; // Rook at a1
37
- const moveResult = board . movePiece ( 0 , 16 ) ; // Move rook to a3
40
+ const originalPiece = board . squares [ 0 ] ; // Rook at a8 (black back rank)
41
+ const moveResult = board . movePiece ( 0 , 16 ) ; // Move rook to a6
38
42
39
43
expect ( board . squares [ 16 ] ) . toBe ( originalPiece ) ;
40
44
expect ( board . squares [ 0 ] ) . toBeNull ( ) ;
@@ -53,17 +57,17 @@ describe('Board', () => {
53
57
board . setupInitialBoard ( ) ;
54
58
55
59
// Move white pawn to capture position
56
- board . movePiece ( 8 , 16 ) ; // Move pawn from a2 to a3
57
- board . movePiece ( 16 , 24 ) ; // Move pawn from a3 to a4
58
- board . movePiece ( 24 , 32 ) ; // Move pawn from a4 to a5
59
- board . movePiece ( 32 , 40 ) ; // Move pawn from a5 to a6
60
+ board . movePiece ( 48 , 40 ) ; // Move pawn from a2 to a6
61
+ board . movePiece ( 40 , 32 ) ; // Move pawn from a6 to a5
62
+ board . movePiece ( 32 , 24 ) ; // Move pawn from a5 to a4
63
+ board . movePiece ( 24 , 16 ) ; // Move pawn from a4 to a6
60
64
61
65
// Now capture black pawn
62
- const moveResult = board . movePiece ( 40 , 48 ) ; // Capture black pawn at a7
66
+ const moveResult = board . movePiece ( 16 , 8 ) ; // Capture black pawn at a7
63
67
64
68
expect ( moveResult ) . toEqual ( {
65
- from : 40 ,
66
- to : 48 ,
69
+ from : 16 ,
70
+ to : 8 ,
67
71
pieceMoved : 'pawn' ,
68
72
pieceCaptured : 'pawn' ,
69
73
success : true ,
@@ -72,7 +76,7 @@ describe('Board', () => {
72
76
73
77
test ( 'should mark pieces as moved after first move' , ( ) => {
74
78
board . setupInitialBoard ( ) ;
75
- const rook = board . squares [ 0 ] ; // White rook at a1
79
+ const rook = board . squares [ 0 ] ; // Black rook at a8
76
80
77
81
// Initially, piece should not have moved
78
82
expect ( rook . getHasMoved ( ) ) . toBe ( false ) ;
@@ -86,7 +90,7 @@ describe('Board', () => {
86
90
87
91
test ( 'should not mark piece as moved again if already moved' , ( ) => {
88
92
board . setupInitialBoard ( ) ;
89
- const rook = board . squares [ 0 ] ; // White rook at a1
93
+ const rook = board . squares [ 0 ] ; // Black rook at a8
90
94
91
95
// Move the piece first time
92
96
board . movePiece ( 0 , 16 ) ;
@@ -140,43 +144,43 @@ describe('Board', () => {
140
144
141
145
test ( 'should handle king moves and mark as moved (important for castling)' , ( ) => {
142
146
board . setupInitialBoard ( ) ;
143
- const whiteKing = board . squares [ 4 ] ; // White king at e1
147
+ const blackKing = board . squares [ 4 ] ; // Black king at e8
144
148
145
- expect ( whiteKing . getType ( ) ) . toBe ( 'king' ) ;
146
- expect ( whiteKing . getHasMoved ( ) ) . toBe ( false ) ;
149
+ expect ( blackKing . getType ( ) ) . toBe ( 'king' ) ;
150
+ expect ( blackKing . getHasMoved ( ) ) . toBe ( false ) ;
147
151
148
152
// Move king
149
- const moveResult = board . movePiece ( 4 , 12 ) ; // Move king to e2
153
+ const moveResult = board . movePiece ( 4 , 12 ) ; // Move king to e7
150
154
151
155
expect ( moveResult . pieceMoved ) . toBe ( 'king' ) ;
152
- expect ( whiteKing . getHasMoved ( ) ) . toBe ( true ) ;
156
+ expect ( blackKing . getHasMoved ( ) ) . toBe ( true ) ;
153
157
} ) ;
154
158
155
159
test ( 'should handle rook moves and mark as moved (important for castling)' , ( ) => {
156
160
board . setupInitialBoard ( ) ;
157
- const whiteRook = board . squares [ 0 ] ; // White rook at a1
161
+ const blackRook = board . squares [ 0 ] ; // Black rook at a8
158
162
159
- expect ( whiteRook . getType ( ) ) . toBe ( 'rook' ) ;
160
- expect ( whiteRook . getHasMoved ( ) ) . toBe ( false ) ;
163
+ expect ( blackRook . getType ( ) ) . toBe ( 'rook' ) ;
164
+ expect ( blackRook . getHasMoved ( ) ) . toBe ( false ) ;
161
165
162
166
// Move rook
163
- const moveResult = board . movePiece ( 0 , 8 ) ; // Move rook to a2
167
+ const moveResult = board . movePiece ( 0 , 8 ) ; // Move rook to a7
164
168
165
169
expect ( moveResult . pieceMoved ) . toBe ( 'rook' ) ;
166
- expect ( whiteRook . getHasMoved ( ) ) . toBe ( true ) ;
170
+ expect ( blackRook . getHasMoved ( ) ) . toBe ( true ) ;
167
171
} ) ;
168
172
169
173
test ( 'should handle pawn moves and mark as moved (important for double move rules)' , ( ) => {
170
174
board . setupInitialBoard ( ) ;
171
- const whitePawn = board . squares [ 8 ] ; // White pawn at a2
175
+ const blackPawn = board . squares [ 8 ] ; // Black pawn at a7
172
176
173
- expect ( whitePawn . getType ( ) ) . toBe ( 'pawn' ) ;
174
- expect ( whitePawn . getHasMoved ( ) ) . toBe ( false ) ;
177
+ expect ( blackPawn . getType ( ) ) . toBe ( 'pawn' ) ;
178
+ expect ( blackPawn . getHasMoved ( ) ) . toBe ( false ) ;
175
179
176
180
// Move pawn
177
- const moveResult = board . movePiece ( 8 , 16 ) ; // Move pawn to a3
181
+ const moveResult = board . movePiece ( 8 , 16 ) ; // Move pawn to a6
178
182
179
183
expect ( moveResult . pieceMoved ) . toBe ( 'pawn' ) ;
180
- expect ( whitePawn . getHasMoved ( ) ) . toBe ( true ) ;
184
+ expect ( blackPawn . getHasMoved ( ) ) . toBe ( true ) ;
181
185
} ) ;
182
- } ) ;
186
+ } ) ;
0 commit comments