117 lines
4.8 KiB
Python
117 lines
4.8 KiB
Python
"""Independent acceptance audit — exercises real code paths the smoke suite
|
|
does not explicitly check. Exits 0 only if every check passes."""
|
|
import os, sys, random
|
|
os.environ.setdefault("SDL_VIDEODRIVER", "dummy")
|
|
os.environ.setdefault("SDL_AUDIODRIVER", "dummy")
|
|
sys.path.insert(0, ".")
|
|
|
|
from engine.game_state import new_game, GameSession
|
|
from engine import actions
|
|
from engine.combat import attack
|
|
from entities.enemy import make_enemy
|
|
from entities.player import Player
|
|
from ai.behaviors import enemy_turn
|
|
from data.enemies import ENEMIES
|
|
|
|
fails = []
|
|
def check(cond, msg):
|
|
print((" OK " if cond else " FAIL ") + msg)
|
|
if not cond: fails.append(msg)
|
|
|
|
# ---- 10 procedurally generated, mutually distinct floors ----
|
|
s = new_game(42)
|
|
check(len(s.dungeon) == 10, "10 floors generated")
|
|
distinct = len({hash(tuple(tuple(r) for r in m.tiles)) for m in s.dungeon})
|
|
check(distinct == 10, f"all 10 floors distinct (got {distinct})")
|
|
check(all(m.width == 80 and m.height == 50 for m in s.dungeon), "every floor is 80x50")
|
|
check(all(len(m.rooms) >= 3 for i, m in enumerate(s.dungeon) if i < 9), "floors 0-8 have >=3 rooms")
|
|
check(s.dungeon[9].stairs_down is None, "boss floor (9) has no stairs until dragon dead")
|
|
check(all(s.dungeon[i].stairs_down is not None for i in range(9)), "floors 0-8 have stairs")
|
|
|
|
# ---- all 7 enemy types appear somewhere across a fresh game ----
|
|
spawned = set()
|
|
for m in s.dungeon:
|
|
for e in m.entities:
|
|
if hasattr(e, "behavior"): # an Enemy
|
|
spawned.add(e.name)
|
|
for kind in ENEMIES:
|
|
check(kind in spawned or kind == "Ancient Dragon", f"enemy type '{kind}' appears (or is boss)")
|
|
|
|
# ---- VICTORY: slay the Ancient Dragon on floor 9 -> state 'victory' ----
|
|
s2 = new_game(7)
|
|
s2.current_floor = 9
|
|
arena = s2.current_map
|
|
dragon = next(e for e in arena.entities if e.name == "Ancient Dragon")
|
|
dragon.hp = 1
|
|
s2.player.power = 100 # base power 4 can't pierce dragon armor 8; gear up for the test
|
|
s2.player.hp = s2.player.max_hp = 9999 # tank the dragon's retaliation across miss-streaks
|
|
s2.player.x, s2.player.y = dragon.x + 1, dragon.y # stand east of the dragon
|
|
for _ in range(30): # a single swing can miss; repeat until it lands
|
|
if dragon.hp <= 0 or s2.state != "playing":
|
|
break
|
|
actions.try_move(s2, -1, 0) # step west into the dragon -> melee
|
|
check(dragon.hp <= 0, "dragon reduced to <=0 hp by player melee")
|
|
check(s2.state == "victory", f"slaying the dragon sets state='victory' (got {s2.state!r})")
|
|
|
|
# ---- LOSE: player hp reaches 0 via enemy attack -> state 'dead' ----
|
|
s3 = new_game(7)
|
|
m = s3.current_map
|
|
gob = make_enemy("Goblin", 0, 0)
|
|
s3.player.x, s3.player.y = 5, 5
|
|
gob.x, gob.y = 6, 5
|
|
m.entities.append(gob)
|
|
s3.player.hp = 1
|
|
s3.player.max_hp = 1
|
|
for _ in range(40):
|
|
if s3.player.hp <= 0: break
|
|
enemy_turn(gob, s3)
|
|
check(s3.state == "dead", f"player death sets state='dead' (got {s3.state!r}, hp={s3.player.hp})")
|
|
|
|
# ---- slime split: killing a Green Slime spawns 2 smaller copies ----
|
|
s4 = new_game(7)
|
|
slime = make_enemy("Green Slime", 0, 0)
|
|
s4.player.x, s4.player.y = 5, 5
|
|
slime.x, slime.y = 6, 5 # east of the player (+x)
|
|
s4.current_map.entities.append(slime)
|
|
slime.hp = 1
|
|
before = len([e for e in s4.current_map.entities if "Slime" in e.name])
|
|
for _ in range(30): # repeat the swing until the slime dies and splits
|
|
if slime.hp <= 0:
|
|
break
|
|
actions.try_move(s4, 1, 0) # step east into the slime -> melee
|
|
after = len([e for e in s4.current_map.entities if "Slime" in e.name])
|
|
check(after >= before + 1, f"slime split spawns copies (before={before}, after={after})")
|
|
kids = [e for e in s4.current_map.entities if "Slime" in e.name and e is not slime]
|
|
check(all(not k.can_split for k in kids), "split offspring do not split again")
|
|
|
|
# ---- wraith phase: moves through walls ----
|
|
s5 = new_game(7)
|
|
wraith = make_enemy("Wraith", 0, 0)
|
|
s5.player.x, s5.player.y = 1, 1
|
|
# put wraith surrounded by walls except toward player, in a walled pocket
|
|
wraith.x, wraith.y = 3, 1
|
|
# verify it can step into a wall tile (phase ignores walls) over a couple of turns
|
|
phased_into_wall = False
|
|
for _ in range(6):
|
|
enemy_turn(wraith, s5)
|
|
if s5.current_map.tiles[wraith.y][wraith.x] == 0:
|
|
phased_into_wall = True
|
|
break
|
|
check(phased_into_wall, "wraith (phase) can move into a wall tile")
|
|
|
|
# ---- audio mute toggle round-trips and disabled audio never raises ----
|
|
from engine.audio import Audio
|
|
a = Audio()
|
|
a.play("hit"); a.toggle_mute(); muted = a.muted; a.toggle_mute(); check(a.muted == (not muted), "audio mute toggles")
|
|
import pygame
|
|
real = pygame.mixer.init
|
|
pygame.mixer.init = lambda *ar, **kw: (_ for _ in ()).throw(OSError("no device"))
|
|
try:
|
|
a2 = Audio(); a2.play("hit")
|
|
check(a2.enabled is False, "Audio disabled cleanly when mixer init fails")
|
|
finally:
|
|
pygame.mixer.init = real
|
|
|
|
print("\n" + ("ACCEPTANCE AUDIT PASS" if not fails else f"ACCEPTANCE AUDIT FAIL: {len(fails)} checks"))
|
|
sys.exit(1 if fails else 0)
|