@@ -744,68 +744,68 @@ describe('MoveGenerator', () => {
744
744
test ( 'should generate all 8 moves for knight in center of empty board' , ( ) => {
745
745
const knight = new Piece ( 'knight' , 'white' , 3 , '♘' ) ;
746
746
board . squares [ 28 ] = knight ; // e4
747
-
747
+
748
748
const moves = moveGenerator . generateKnightMoves ( knight , 28 ) ;
749
749
expect ( moves ) . toHaveLength ( 8 ) ;
750
750
} ) ;
751
-
751
+
752
752
test ( 'should generate 2 moves for knight in corner (a1)' , ( ) => {
753
753
const knight = new Piece ( 'knight' , 'white' , 3 , '♘' ) ;
754
754
board . squares [ 56 ] = knight ; // a1
755
-
755
+
756
756
const moves = moveGenerator . generateKnightMoves ( knight , 56 ) ;
757
757
expect ( moves ) . toHaveLength ( 2 ) ;
758
- const destinations = moves . map ( ( m ) => m . to ) ;
758
+ const destinations = moves . map ( m => m . to ) ;
759
759
expect ( destinations ) . toEqual ( expect . arrayContaining ( [ 41 , 50 ] ) ) ; // c2, b3
760
760
} ) ;
761
-
761
+
762
762
test ( 'should generate 4 moves for knight on edge (a4)' , ( ) => {
763
763
const knight = new Piece ( 'knight' , 'white' , 3 , '♘' ) ;
764
764
board . squares [ 32 ] = knight ; // a4
765
-
765
+
766
766
const moves = moveGenerator . generateKnightMoves ( knight , 32 ) ;
767
767
expect ( moves ) . toHaveLength ( 4 ) ;
768
768
} ) ;
769
-
769
+
770
770
test ( 'should not be blocked by surrounding pieces' , ( ) => {
771
771
const knight = new Piece ( 'knight' , 'white' , 3 , '♘' ) ;
772
772
board . squares [ 28 ] = knight ; // e4
773
-
773
+
774
774
// Surround the knight
775
775
board . squares [ 27 ] = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ; // d4
776
776
board . squares [ 29 ] = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ; // f4
777
777
board . squares [ 36 ] = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ; // e5
778
778
board . squares [ 20 ] = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ; // e3
779
-
779
+
780
780
const moves = moveGenerator . generateKnightMoves ( knight , 28 ) ;
781
781
expect ( moves ) . toHaveLength ( 8 ) ; // Still has 8 moves
782
782
} ) ;
783
-
783
+
784
784
test ( 'should capture enemy pieces but not land on friendly pieces' , ( ) => {
785
785
const knight = new Piece ( 'knight' , 'white' , 3 , '♘' ) ;
786
786
board . squares [ 28 ] = knight ; // e4
787
-
787
+
788
788
// Friendly piece at one destination
789
789
board . squares [ 11 ] = new Piece ( 'pawn' , 'white' , 1 , '♙' ) ; // d2, blocks one move
790
790
// Enemy piece at another
791
791
board . squares [ 13 ] = new Piece ( 'pawn' , 'black' , 1 , '♟' ) ; // f2, can be captured
792
-
792
+
793
793
const moves = moveGenerator . generateKnightMoves ( knight , 28 ) ;
794
794
expect ( moves ) . toHaveLength ( 7 ) ; // 8 possible moves - 1 blocked by friendly
795
-
796
- const captureMove = moves . find ( ( m ) => m . to === 13 ) ;
795
+
796
+ const captureMove = moves . find ( m => m . to === 13 ) ;
797
797
expect ( captureMove ) . toBeDefined ( ) ;
798
798
expect ( captureMove . type ) . toBe ( 'capture' ) ;
799
799
expect ( captureMove . captured ) . toBe ( 'pawn' ) ;
800
800
} ) ;
801
-
801
+
802
802
test ( 'isValidKnightMove should prevent wrapping' , ( ) => {
803
803
// Valid moves
804
804
expect ( moveGenerator . isValidKnightMove ( 0 , 10 ) ) . toBe ( true ) ; // a8 to b6
805
805
expect ( moveGenerator . isValidKnightMove ( 28 , 11 ) ) . toBe ( true ) ; // e4 to d2
806
-
806
+
807
807
// Invalid moves (wrapping from h-file to a-file)
808
- expect ( moveGenerator . isValidKnightMove ( 7 , 22 ) ) . toBe ( false ) ; // h8 to a6
808
+ expect ( moveGenerator . isValidKnightMove ( 7 , 16 ) ) . toBe ( false ) ; // h8 to a6
809
809
expect ( moveGenerator . isValidKnightMove ( 15 , 25 ) ) . toBe ( false ) ; // h7 to b5
810
810
} ) ;
811
811
} ) ;
@@ -858,9 +858,9 @@ describe('MoveGenerator', () => {
858
858
test ( 'should route to correct piece-specific method for knight' , ( ) => {
859
859
const whiteKnight = new Piece ( 'knight' , 'white' , 3 , '♘' ) ;
860
860
board . squares [ 28 ] = whiteKnight ;
861
-
861
+
862
862
const moves = moveGenerator . generateMoves ( whiteKnight , 28 ) ;
863
-
863
+
864
864
expect ( moves . length ) . toBeGreaterThan ( 0 ) ;
865
865
expect ( moves [ 0 ] . piece ) . toBe ( 'knight' ) ;
866
866
} ) ;
0 commit comments