explodorama / files / tools / balance / show.ts
show.ts
d3e4ed26 2026-10-25 Pavel Safronov | 1 | import type { GameState } from '../../src/sim/types' |
| 2 | ||
6c3fcc31 2026-10-26 Pavel Safronov | 3 | /** |
| 4 | * The board as text, for following a bot: P you, E enemy, 1–9 a bomb, + crate, x/X exit (hidden/open), | |
| 5 | * g gem, $ drop; M metal crate, O oil barrel, r rubble, * bush, ~ oil, ^ spikes (test/helpers.ts's letters). | |
| 6 | */ | |
d3e4ed26 2026-10-25 Pavel Safronov | 7 | export function show(s: GameState): string { |
| 8 | const rows: string[] = [] | |
| 9 | for (let y = 0; y < s.height; y++) { | |
| 10 | let r = '' | |
| 11 | for (let x = 0; x < s.width; x++) { | |
| 12 | const at = (p: { x: number; y: number }) => p.x === x && p.y === y | |
| 13 | const c = s.cells[y * s.width + x] | |
| 14 | const bomb = s.bombs.find((b) => at(b.pos)) | |
| 15 | r += at(s.player) ? 'P' | |
| 16 | : s.enemies.some((e) => at(e.pos)) ? 'E' | |
| 17 | : bomb ? String(Math.max(0, bomb.timer)) | |
| 18 | : at(s.exit) ? (c === 'floor' ? 'X' : 'x') | |
| 19 | : s.gems.some((g) => at(g.pos)) ? (c === 'floor' ? 'g' : 'G') | |
| 20 | : s.drops.some((d) => at(d.pos)) ? '$' | |
6c3fcc31 2026-10-26 Pavel Safronov | 21 | : c === 'wall' ? '#' : c === 'block' ? '+' : c === 'metal' ? 'M' : c === 'barrel' ? 'O' : c === 'rubble' ? 'r' |
| 22 | : s.bushes.includes(y * s.width + x) ? '*' | |
| 23 | : s.oil.includes(y * s.width + x) ? '~' | |
| 24 | : s.spikes.some((sp) => sp.cell === y * s.width + x) ? '^' | |
| 25 | : '.' | |
d3e4ed26 2026-10-25 Pavel Safronov | 26 | } |
| 27 | rows.push(r) | |
| 28 | } | |
| 29 | return rows.join('\n') | |
| 30 | } |