Advent of AI Slop Day 5: Pelican on a Bike

Endless winter-city ride: pelican on a bicycle or reindeer on a unicycle,
procedural canvas skyline, garlands to duck, snowmen to hop, fish to hoard.
This commit is contained in:
hermes committed 2026-12-05 23:17:21 +00:00
commit f2eec57b5e
16 files changed
+2267

No files matched your search

+127
View File
@@ -0,0 +1,127 @@
# Smoke-test the built Day 5 pelican-on-a-bike game: start, jump, duck, crash, best-score persistence, reindeer, preview shot.
import http.server, threading, functools, sys, os
DIST = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else 'dist')
SHOT = os.environ.get('SHOT', '') # if set, capture 1200x630 preview here
httpd = http.server.ThreadingHTTPServer(('127.0.0.1', 8767), functools.partial(http.server.SimpleHTTPRequestHandler, directory=DIST))
threading.Thread(target=httpd.serve_forever, daemon=True).start()
from playwright.sync_api import sync_playwright
errs, msgs = [], []
with sync_playwright() as p:
b = p.chromium.launch(
executable_path='/home/hermeswebui/.hermes/home/.cache/ms-playwright/chromium-1234/chrome-linux64/chrome',
args=['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'])
pg = b.new_page(viewport={'width': 1200, 'height': 630})
pg.on('pageerror', lambda e: errs.append(str(e)))
pg.on('console', lambda m: msgs.append(f"{m.type}: {m.text}"))
pg.goto('http://127.0.0.1:8767/', wait_until='networkidle')
pg.wait_for_timeout(500)
print('title:', pg.title())
assert 'Day 5' in pg.title()
assert pg.locator('#menu').is_visible(), 'menu should show on load'
# start as pelican
pg.click('#card-pelican')
assert pg.evaluate('window.__aos5.phase') == 'playing'
# park the obstacle spawner far away so the physics checks run on a clean road
pg.evaluate('window.__aos5.distSinceSpawn = -1e9')
pg.wait_for_timeout(2500)
score = int(pg.locator('#hud-score').inner_text())
dist = int(pg.locator('#hud-dist').inner_text())
kmh = int(pg.locator('#hud-speed').inner_text())
print(f'after 2.5s: score={score} dist={dist}m kmh={kmh}')
assert score > 0 and dist > 0 and kmh > 0
# jump raises the rider
y0 = pg.evaluate('window.__aos5.rider.y')
pg.keyboard.press('Space')
pg.wait_for_timeout(250)
y1 = pg.evaluate('window.__aos5.rider.y')
print('jump: y', y0, '->', y1)
assert y1 < y0, 'rider did not leave the ground'
pg.wait_for_timeout(900)
assert pg.evaluate('window.__aos5.rider.onGround') is True, 'rider never landed'
# duck lowers the hitbox
pg.keyboard.down('ArrowDown')
pg.wait_for_timeout(400)
duck = pg.evaluate('window.__aos5.duckOn')
assert duck is True
pg.keyboard.up('ArrowDown')
# pause / resume
pg.keyboard.press('KeyP')
assert pg.evaluate('window.__aos5.phase') == 'paused'
assert pg.locator('#pause').is_visible()
pg.keyboard.press('KeyP')
assert pg.evaluate('window.__aos5.phase') == 'playing'
if SHOT:
pg.evaluate('window.__aos5.distSinceSpawn = 0') # let traffic come back for the screenshot
# wait until an obstacle is nicely on screen, then style the page to fit 1200x630
for _ in range(60):
near = pg.evaluate("window.__aos5.obstacles.filter(o => o.kind !== 'garland' && o.x > 380 && o.x < 1000).length")
if near >= 1:
break
pg.keyboard.press('Space')
pg.wait_for_timeout(400)
pg.evaluate('''() => {
document.querySelector('header').style.display = 'none';
document.querySelector('.hint').style.display = 'none';
const app = document.getElementById('app');
app.style.padding = '0'; app.style.maxWidth = '1200px';
const hud = document.getElementById('hud');
hud.style.margin = '0'; hud.style.height = '30px'; hud.style.alignItems = 'center';
hud.style.overflow = 'hidden';
const stage = document.getElementById('stage');
stage.style.border = 'none'; stage.style.borderRadius = '0';
const cv = document.getElementById('game');
cv.style.width = '1200px'; cv.style.height = '600px';
document.body.style.overflow = 'hidden';
window.scrollTo(0, 0);
}''')
pg.wait_for_timeout(300)
box = pg.locator('#game').bounding_box()
print('canvas box for shot:', box)
assert box['y'] >= 28 and box['y'] + box['height'] <= 632, 'canvas not framed in 630px'
pg.screenshot(path=SHOT, clip={'x': 0, 'y': 0, 'width': 1200, 'height': 630})
print('preview shot ->', SHOT)
pg.reload(wait_until='networkidle')
pg.wait_for_timeout(400)
# force a crash -> overlay + best score
if pg.evaluate('window.__aos5.phase') != 'playing':
pg.click('#card-pelican')
pg.wait_for_timeout(1200)
pg.evaluate('window.__aos5.crash()')
pg.wait_for_timeout(1500)
assert pg.locator('#gameover').is_visible(), 'game over overlay missing'
fs = int(pg.locator('#final-score').inner_text())
print('crash final score:', fs)
assert fs > 0
best_txt = pg.locator('#best-line').inner_text()
print('best line:', best_txt)
# restart via button, ride as reindeer, double jump
pg.click('#restart-btn')
pg.evaluate("window.__aos5.setChar('reindeer', 0); window.__aos5.start()")
pg.keyboard.press('Space')
pg.wait_for_timeout(120)
pg.keyboard.press('Space') # double jump
jl = pg.evaluate('window.__aos5.rider.jumpsLeft')
print('reindeer jumps left after double jump:', jl)
assert jl == 0
pg.wait_for_timeout(600)
# best persists across reload
pg.reload(wait_until='networkidle')
pg.wait_for_timeout(400)
stored = pg.evaluate("localStorage.getItem('aos5-best-pelican')")
print('persisted pelican best:', stored)
assert stored is not None and int(stored) > 0
print('pageerrors:', errs)
assert not errs, f'JS page errors: {errs}'
bad = [m for m in msgs if m.startswith('error')]
assert not bad, f'console errors: {bad}'
print('SMOKE OK')
b.close()