Fix impossible_ratio not being respected in knight_swap (#521) (#524)

Move make_impossible decision before the retry loop so it's fixed per
item instead of re-rolled on every attempt, which skewed the actual
ratio of impossible puzzles well above the configured value.
This commit is contained in:
Zafir Stojanovski 2026-03-27 16:18:08 +01:00 committed by GitHub
parent 49b1dbbcce
commit d26663fb3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -219,6 +219,9 @@ class KnightSwapDataset(ProceduralDataset):
"""Generate a single Knight Swap puzzle.""" """Generate a single Knight Swap puzzle."""
rng = Random(self.seed + idx) rng = Random(self.seed + idx)
# Decide if this should be an impossible puzzle (fixed per item, not per attempt)
make_impossible = rng.random() < self.config.impossible_ratio
# Keep trying with new boards until we succeed # Keep trying with new boards until we succeed
board_attempts = 0 board_attempts = 0
while board_attempts < self.config.max_attempts: while board_attempts < self.config.max_attempts:
@ -228,9 +231,6 @@ class KnightSwapDataset(ProceduralDataset):
board = self.game_logic.generate_board(num_nodes, rng, max_attempts=self.config.max_attempts) board = self.game_logic.generate_board(num_nodes, rng, max_attempts=self.config.max_attempts)
positions = list(board.keys()) positions = list(board.keys())
# Decide if this should be an impossible puzzle
make_impossible = rng.random() < self.config.impossible_ratio
# Try different piece placements on this board # Try different piece placements on this board
for _ in range(50): # Reduced attempts per board since we try multiple boards for _ in range(50): # Reduced attempts per board since we try multiple boards
# Use fixed number of pieces for more reliable generation # Use fixed number of pieces for more reliable generation