File tree Expand file tree Collapse file tree 1 file changed +19
-16
lines changed
Expand file tree Collapse file tree 1 file changed +19
-16
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ fn get_capturable_cells(
102102 let mut can_capture_cell = vec ! [ ] ;
103103 let is_king = piece_type == PieceType :: King ;
104104 let is_pawn = piece_type == PieceType :: Pawn ;
105+ let is_knight = piece_type == PieceType :: Knight ;
105106
106107 for ( dr, dc) in move_rules {
107108 let mut cr = r as i32 ;
@@ -122,8 +123,8 @@ fn get_capturable_cells(
122123 } ) ;
123124 break ;
124125 }
125- // King and Pawn can only move one space .
126- if is_king || is_pawn {
126+ // King, Pawn and Knight can only move one time .
127+ if is_king || is_pawn || is_knight {
127128 break ;
128129 }
129130 }
@@ -164,25 +165,27 @@ mod test_solo_chess_solver {
164165 fn random_cases_with_a_solution ( ) {
165166 // There are ten levels from chess.com. So I randomly picked some, mostly from upper levels.
166167
167- // Level 6
168+ // Level 7
168169 let mut board = board ! [
169- ( 0 , 0 , Queen ) ,
170- ( 1 , 2 , Queen ) ,
171- ( 3 , 1 , Knight ) ,
172- ( 5 , 1 , Queen ) ,
170+ ( 3 , 0 , Bishop ) ,
171+ ( 1 , 1 , Knight ) ,
172+ ( 2 , 3 , Queen ) ,
173+ ( 3 , 2 , Knight ) ,
173174 ( 5 , 5 , Rook ) ,
174- ( 6 , 4 , Queen ) ,
175- ( 6 , 6 , Queen ) ,
175+ ( 3 , 5 , Knight ) ,
176+ ( 4 , 2 , Knight ) ,
177+ ( 5 , 5 , Bishop ) ,
178+ ( 6 , 1 , Rook ) ,
176179 ] ;
177180 let actual = solo_chess_solver ( & mut board) ;
178- println ! ( "{actual:?}" ) ;
179181 let expected = steps ! [
180- ( 3 , 1 , 1 , 2 , Knight ) ,
181- ( 1 , 2 , 0 , 0 , Knight ) ,
182- ( 5 , 1 , 5 , 5 , Queen ) ,
183- ( 5 , 5 , 0 , 0 , Queen ) ,
184- ( 6 , 4 , 6 , 6 , Queen ) ,
185- ( 6 , 6 , 0 , 0 , Queen ) ,
182+ ( 3 , 2 , 1 , 1 , Knight ) ,
183+ ( 3 , 5 , 2 , 3 , Knight ) ,
184+ ( 2 , 3 , 1 , 1 , Knight ) ,
185+ ( 4 , 2 , 3 , 0 , Knight ) ,
186+ ( 3 , 0 , 1 , 1 , Knight ) ,
187+ ( 5 , 5 , 1 , 1 , Bishop ) ,
188+ ( 6 , 1 , 1 , 1 , Rook ) ,
186189 ] ;
187190 assert_eq ! ( expected, actual) ;
188191 }
You can’t perform that action at this time.
0 commit comments