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:
@@ -1,4 +1,4 @@
|
||||
"""PrismBattleSnake_GPT_5_6_Sol v1.0.0
|
||||
"""PrismBattleSnake_GPT_5_6_Sol v1.0.1
|
||||
|
||||
Built on ApexBattleSnake v1.0.0. All strategic logic is inherited.
|
||||
Performance improvement: all spatial primitives (flood fill, territory,
|
||||
@@ -41,7 +41,7 @@ _DIR_DELTAS = ((0, 1), (0, -1), (-1, 0), (1, 0))
|
||||
_DIR_NAMES = ("up", "down", "left", "right")
|
||||
|
||||
class PrismBattleSnake_GPT_5_6_Sol(ApexBattleSnake):
|
||||
VERSION = "1.0.0"
|
||||
VERSION = "1.0.1"
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
@@ -83,6 +83,11 @@ class PrismBattleSnake_GPT_5_6_Sol(ApexBattleSnake):
|
||||
my_snake = game_data.get_my_snake()
|
||||
my_len = my_snake.get("length", len(my_snake["body"]))
|
||||
food_set = {(f["x"], f["y"]) for f in game_data.get_food()}
|
||||
all_occupied = {
|
||||
(seg["x"], seg["y"])
|
||||
for snake in [my_snake, *other_snakes]
|
||||
for seg in snake["body"]
|
||||
}
|
||||
game_type = game_data.get_type()
|
||||
is_constrictor = game_type == "constrictor"
|
||||
w = bb.width
|
||||
@@ -100,7 +105,7 @@ class PrismBattleSnake_GPT_5_6_Sol(ApexBattleSnake):
|
||||
if not is_constrictor and len(body) >= 2:
|
||||
tail_stacked = (body[-1]["x"] == body[-2]["x"] and body[-1]["y"] == body[-2]["y"])
|
||||
if not tail_stacked:
|
||||
can_grow = self._enemy_can_grow_this_turn(snake, food_set)
|
||||
can_grow = self._enemy_can_grow_this_turn(snake, food_set, all_occupied)
|
||||
if not can_grow:
|
||||
enemy_tail_bits |= 1 << (body[-1]["y"] * w + body[-1]["x"])
|
||||
|
||||
@@ -354,17 +359,25 @@ class PrismBattleSnake_GPT_5_6_Sol(ApexBattleSnake):
|
||||
return -5000.0
|
||||
|
||||
# ── Safe next options (enemy-attack aware) ────────────────────────
|
||||
# Remove tiles where an enemy of >= our length could head-to-head.
|
||||
# The danger bitboard was precomputed; filter out tiles blocked by
|
||||
# current body (enemy can't step there either).
|
||||
danger_here = self._enemy_attack_danger & ~blocked_bits
|
||||
# Rebuild danger for the simulated length. The root-turn danger mask is
|
||||
# stale after eating and includes enemy moves blocked in this future body.
|
||||
danger_here = 0
|
||||
for enemy in other_snakes:
|
||||
enemy_len = enemy.get("length", len(enemy["body"]))
|
||||
if enemy_len < body_len:
|
||||
continue
|
||||
enemy_head = enemy["head"]
|
||||
enemy_idx = enemy_head["y"] * w + enemy_head["x"]
|
||||
danger_here |= bb._neighbor_masks[enemy_idx]
|
||||
danger_here &= ~blocked_bits
|
||||
safe_nb = nb_free & ~danger_here
|
||||
en_safe = safe_nb.bit_count()
|
||||
|
||||
if en_safe == 0:
|
||||
return -4000.0
|
||||
|
||||
sc = reachable * 1.9 + liberties * 14.0 + liberties * 11.0 + en_safe * 26.0
|
||||
next_opts = liberties
|
||||
sc = reachable * 1.9 + liberties * 14.0 + next_opts * 11.0 + en_safe * 26.0
|
||||
if en_safe == 1:
|
||||
sc -= 420.0
|
||||
return sc
|
||||
|
||||
Reference in New Issue
Block a user