fix: preserve gameplay data and correct duel evaluation

- Preserve snake customizations across database migrations and merges.
- Lazily load optional storage backends for SQLite maintenance scripts.
- Match Apex territory and nearest-food tie-breaking semantics.
- Resolve duel occupancy after simultaneous movement and food growth.
- Recompute simulated head-to-head danger after body growth.
- Add regression coverage and declare the aiofiles dependency.
This commit is contained in:
2026-08-01 18:16:04 +02:00
parent 4f022d3d01
commit c646392b84
14 changed files with 323 additions and 107 deletions
@@ -21,20 +21,38 @@ class TestBitBoard(unittest.TestCase):
self.assertEqual(board.territory(board.idx(0, 0), [board.idx(4, 0)], 0), 0)
def test_territory_propagates_through_contested_cells(self):
board = BitBoard(5, 3)
blocked = board.set_to_bits({(0, 1), (1, 1), (3, 1), (4, 1)})
self.assertEqual(board.territory(board.idx(0, 0), [board.idx(4, 0)], blocked), 0)
def test_territory_ignores_enemy_only_disconnected_space_like_apex(self):
board = BitBoard(5, 1)
blocked = board.set_to_bits({(2, 0)})
self.assertEqual(board.territory(board.idx(0, 0), [board.idx(4, 0)], blocked), 2)
def test_nearest_food_returns_shortest_distance(self):
board = BitBoard(5, 5)
food = board.set_to_bits({(4, 4), (2, 1)})
self.assertEqual(board.nearest_food(board.idx(0, 0), food, 0), (3, board.idx(2, 1)))
def test_nearest_food_uses_apex_direction_order_for_ties(self):
board = BitBoard(3, 3)
food = board.set_to_bits({(1, 2), (0, 1), (2, 1), (1, 0)})
self.assertEqual(board.nearest_food(board.idx(1, 1), food, 0), (1, board.idx(1, 2)))
class TestPrismBattleSnake_GPT_5_6_Sol(unittest.TestCase):
def test_api_name_and_version_are_exposed(self):
snake = PrismBattleSnake_GPT_5_6_Sol()
self.assertEqual(snake.name, "PrismBattleSnake")
self.assertEqual(snake.version, "1.0.0")
self.assertEqual(get_snake_version("PrismBattleSnake_GPT_5_6_Sol"), "1.0.0")
self.assertEqual(snake.version, "1.0.1")
self.assertEqual(get_snake_version("PrismBattleSnake_GPT_5_6_Sol"), "1.0.1")
self.assertIsInstance(SnakeBuilder.build("PrismBattleSnake_GPT_5_6_Sol"), PrismBattleSnake_GPT_5_6_Sol)
def test_bitboard_primitives_match_apex(self):
@@ -82,6 +100,18 @@ class TestPrismBattleSnake_GPT_5_6_Sol(unittest.TestCase):
self.assertGreater(value, 0)
def test_duel_search_keeps_tail_blocked_when_its_snake_eats(self):
board = BitBoard(3, 3)
search = BitboardDuelSearch(
board=board, food={(0, 1)}, hazards=set(), hazard_count={},
hazard_damage=15, deadline=None,
)
body = (board.idx(0, 0), board.idx(1, 0), board.idx(1, 1))
advanced = search._advance_body(body, board.idx(0, 1), ate=True)
self.assertIn(board.idx(1, 1), advanced)
def test_bitboard_duel_search_reuses_transpositions(self):
board = BitBoard(5, 5)
search = BitboardDuelSearch(