explodorama / files / tools / balance / show.ts
show.ts
| 1 | import type { GameState } from '../../src/sim/types' |
| 2 | |
| 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 | */ |
| 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)) ? '$' |
| 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 | : '.' |
| 26 | } |
| 27 | rows.push(r) |
| 28 | } |
| 29 | return rows.join('\n') |
| 30 | } |