@@ -823,71 +823,71 @@ impl Board {
823823
824824 conditions
825825 }
826+ }
826827
828+ impl Puzzle {
827829 /// Check that the board satisfies the given puzzle.
828- pub fn check_puzzle ( & self , puzzle : & Puzzle ) -> Result < u16 , InvalidSolution > {
829- if puzzle . minimal_steps > puzzle . maximal_steps {
830+ pub fn check_solution ( & self , board : & Board ) -> Result < u16 , InvalidSolution > {
831+ if self . minimal_steps > self . maximal_steps {
830832 return Err ( InvalidSolution :: InvalidStepRange {
831- min_steps : puzzle . minimal_steps ,
832- max_steps : puzzle . maximal_steps ,
833+ min_steps : self . minimal_steps ,
834+ max_steps : self . maximal_steps ,
833835 } ) ;
834836 }
835- if self . size != puzzle . size {
837+ if board . size != self . size {
836838 return Err ( InvalidSolution :: SizeMismatch {
837- board_size : self . size ,
838- puzzle_size : puzzle . size ,
839+ board_size : board . size ,
840+ puzzle_size : self . size ,
839841 } ) ;
840842 }
841- if let Err ( ( condition_index, reason) ) = self . check_conditions ( & puzzle . initial_conditions ) {
843+ if let Err ( ( condition_index, reason) ) = board . check_conditions ( & self . initial_conditions ) {
842844 return Err ( InvalidSolution :: InitialConditionFailed {
843845 condition_index,
844846 reason,
845847 } ) ;
846848 }
847- if puzzle . is_strict {
848- if puzzle . minimal_steps == 0 {
849+ if self . is_strict {
850+ if self . minimal_steps == 0 {
849851 return Err ( InvalidSolution :: InvalidStepRange {
850- min_steps : puzzle . minimal_steps ,
851- max_steps : puzzle . maximal_steps ,
852+ min_steps : self . minimal_steps ,
853+ max_steps : self . maximal_steps ,
852854 } ) ;
853855 }
854- let board = self . advance ( puzzle . minimal_steps - 1 ) ;
856+ let board = board . advance ( self . minimal_steps - 1 ) ;
855857 match board. advance_until (
856- & puzzle . final_conditions ,
857- puzzle . maximal_steps - puzzle . minimal_steps + 1 ,
858+ & self . final_conditions ,
859+ self . maximal_steps - self . minimal_steps + 1 ,
858860 ) {
859861 Ok ( ( steps, _) ) => {
860862 if steps == 0 {
861863 return Err ( InvalidSolution :: FinalConditionsMustFailAt {
862- steps : puzzle . minimal_steps - 1 ,
864+ steps : self . minimal_steps - 1 ,
863865 } ) ;
864866 }
865- Ok ( puzzle . minimal_steps - 1 + steps)
867+ Ok ( self . minimal_steps - 1 + steps)
866868 }
867869 Err ( ( condition_index, reason) ) => Err ( InvalidSolution :: FinalConditionFailed {
868870 condition_index,
869- steps : puzzle . maximal_steps ,
871+ steps : self . maximal_steps ,
870872 reason,
871873 } ) ,
872874 }
873875 } else {
874- let board = self . advance ( puzzle . minimal_steps ) ;
876+ let board = board . advance ( self . minimal_steps ) ;
875877 match board. advance_until (
876- & puzzle . final_conditions ,
877- puzzle . maximal_steps - puzzle . minimal_steps ,
878+ & self . final_conditions ,
879+ self . maximal_steps - self . minimal_steps ,
878880 ) {
879- Ok ( ( steps, _) ) => Ok ( puzzle . minimal_steps + steps) ,
881+ Ok ( ( steps, _) ) => Ok ( self . minimal_steps + steps) ,
880882 Err ( ( condition_index, reason) ) => Err ( InvalidSolution :: FinalConditionFailed {
881883 condition_index,
882- steps : puzzle . maximal_steps ,
884+ steps : self . maximal_steps ,
883885 reason,
884886 } ) ,
885887 }
886888 }
887889 }
888- }
889890
890- impl Puzzle {
891891 /// Convert this puzzle to a DirectPuzzle representation for display.
892892 pub fn to_direct_puzzle ( & self ) -> DirectPuzzle {
893893 let mut initial_constraints =
@@ -1265,7 +1265,7 @@ mod tests {
12651265 } ;
12661266
12671267 assert_eq ! (
1268- board . check_puzzle ( & puzzle ) ,
1268+ puzzle . check_solution ( & board ) ,
12691269 Err ( InvalidSolution :: SizeMismatch {
12701270 board_size: 5 ,
12711271 puzzle_size: 10
@@ -1289,7 +1289,7 @@ mod tests {
12891289 } ;
12901290
12911291 assert_eq ! (
1292- board . check_puzzle ( & puzzle ) ,
1292+ puzzle . check_solution ( & board ) ,
12931293 Err ( InvalidSolution :: InvalidStepRange {
12941294 min_steps: 6 ,
12951295 max_steps: 4
@@ -1316,7 +1316,7 @@ mod tests {
13161316 } ;
13171317
13181318 assert_eq ! (
1319- board . check_puzzle ( & puzzle ) ,
1319+ puzzle . check_solution ( & board ) ,
13201320 Err ( InvalidSolution :: InitialConditionFailed {
13211321 condition_index: 0 ,
13221322 reason: ConditionFailureReason :: PositionMismatch {
@@ -1378,7 +1378,7 @@ mod tests {
13781378 } ;
13791379
13801380 // Test that after 2 steps (full blinker cycle), we get back to the initial pattern.
1381- assert_eq ! ( board . check_puzzle ( & puzzle ) , Ok ( 2 ) ) ;
1381+ assert_eq ! ( puzzle . check_solution ( & board ) , Ok ( 2 ) ) ;
13821382 }
13831383
13841384 #[ test]
@@ -1450,7 +1450,7 @@ mod tests {
14501450 ] ,
14511451 } ;
14521452
1453- assert_eq ! ( board . check_puzzle ( & puzzle ) , Ok ( 31 ) ) ;
1453+ assert_eq ! ( puzzle . check_solution ( & board ) , Ok ( 31 ) ) ;
14541454 }
14551455
14561456 #[ test]
@@ -1522,7 +1522,7 @@ mod tests {
15221522 } ;
15231523
15241524 assert_eq ! (
1525- board . check_puzzle ( & puzzle ) ,
1525+ puzzle . check_solution ( & board ) ,
15261526 Err ( InvalidSolution :: FinalConditionFailed {
15271527 condition_index: 0 ,
15281528 steps: 1 ,
@@ -1577,7 +1577,7 @@ mod tests {
15771577 } ;
15781578
15791579 // Test initial condition failure with detailed information.
1580- match board . check_puzzle ( & puzzle ) {
1580+ match puzzle . check_solution ( & board ) {
15811581 Err ( InvalidSolution :: InitialConditionFailed {
15821582 condition_index,
15831583 reason,
@@ -1628,7 +1628,7 @@ mod tests {
16281628 final_conditions : vec ! [ ] ,
16291629 } ;
16301630
1631- match board2 . check_puzzle ( & puzzle2 ) {
1631+ match puzzle2 . check_solution ( & board2 ) {
16321632 Err ( InvalidSolution :: InitialConditionFailed {
16331633 condition_index,
16341634 reason,
0 commit comments