feat: add Prism snake and gameplay database lifecycle
Build and Push Docker Container / build-and-push (push) Successful in 8m3s
Build and Push Docker Container / build-and-push (push) Successful in 8m3s
- Add bitboard-accelerated Prism and versioned Supreme snake implementations. - Add database-backed move benchmarks and focused strategy tests. - Normalize gameplay storage while preserving replay compatibility. - Add deterministic game quality scoring and replay retention tiers. - Add backup-first SQLite cleanup, verification, and replacement tooling. - Add safe compact-plus-delta database merging with conflict detection. - Extend SQLite and PostgreSQL schemas for replay and quality metadata. - Add PostgreSQL development service and pytest import configuration. - Update gameplay documentation and the quart_common submodule revision.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import unittest
|
||||
|
||||
from snakes import SnakeBuilder, get_snake_version
|
||||
from snakes.ApexBattleSnake import ApexBattleSnake
|
||||
from snakes.PrismBattleSnake_GPT_5_6_Sol import PrismBattleSnake_GPT_5_6_Sol
|
||||
from snakes.bitboard import BitBoard
|
||||
|
||||
class TestBitBoard(unittest.TestCase):
|
||||
|
||||
def test_flood_fill_respects_walls(self):
|
||||
board = BitBoard(3, 3)
|
||||
blocked = board.set_to_bits({(1, 0), (1, 1), (1, 2)})
|
||||
|
||||
self.assertEqual(board.flood_count(board.idx(0, 1), blocked), 3)
|
||||
self.assertEqual(board.path_distance(board.idx(0, 1), board.idx(2, 1), blocked), None)
|
||||
|
||||
def test_territory_counts_ties_for_neither_side(self):
|
||||
board = BitBoard(5, 1)
|
||||
|
||||
self.assertEqual(board.territory(board.idx(0, 0), [board.idx(4, 0)], 0), 0)
|
||||
|
||||
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)))
|
||||
|
||||
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.assertIsInstance(SnakeBuilder.build("PrismBattleSnake_GPT_5_6_Sol"), PrismBattleSnake_GPT_5_6_Sol)
|
||||
|
||||
def test_bitboard_primitives_match_apex(self):
|
||||
apex = ApexBattleSnake()
|
||||
prism = PrismBattleSnake_GPT_5_6_Sol()
|
||||
blocked = {(1, 0), (1, 1), (3, 2), (3, 3)}
|
||||
|
||||
self.assertEqual(
|
||||
prism._flood_fill_count((0, 0), blocked, 5, 5),
|
||||
apex._flood_fill_count((0, 0), blocked, 5, 5),
|
||||
)
|
||||
self.assertEqual(
|
||||
prism._distance_map((0, 0), blocked, 5, 5),
|
||||
apex._distance_map((0, 0), blocked, 5, 5),
|
||||
)
|
||||
self.assertEqual(
|
||||
prism._path_distance((0, 0), (4, 4), blocked, 5, 5),
|
||||
apex._path_distance((0, 0), (4, 4), blocked, 5, 5),
|
||||
)
|
||||
|
||||
def test_mutated_blocked_set_does_not_return_stale_result(self):
|
||||
snake = PrismBattleSnake_GPT_5_6_Sol()
|
||||
blocked: set[tuple[int, int]] = set()
|
||||
|
||||
open_count = snake._flood_fill_count((1, 1), blocked, 3, 3)
|
||||
blocked.update({(0, 1), (1, 0), (2, 1), (1, 2)})
|
||||
trapped_count = snake._flood_fill_count((1, 1), blocked, 3, 3)
|
||||
|
||||
self.assertEqual(open_count, 9)
|
||||
self.assertEqual(trapped_count, 1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user