fuzzyworld

explodorama / files / test / explosions.test.ts

explosions.test.ts

Blame: the commit that last changed each line · file · history

5551eb37 2026-10-20 Pavel Safronov1import { describe, expect, it } from 'vitest'
2import { blastTiles, detonate } from '../src/sim/explosions'
3import { step } from '../src/sim/turn'
4import type { GameEvent } from '../src/sim/types'
5import { board, v } from './helpers'
6
7describe('blast', () => {
8 it('is a cross of radius fire, stopped before walls', () => {
9 const s = board(`
10 #######
11 #P....#
12 #.#.#.#
13 #.....#
14 #######`)
15 expect(blastTiles(s, { pos: v(3, 1), fire: 2 })).toEqual([v(3, 1), v(3, 2), v(3, 3), v(2, 1), v(1, 1), v(4, 1), v(5, 1)])
16 })
17
18 it('stops on the first soft block and destroys only that one', () => {
19 let s = board(`
20 #######
21 #P1++.#
22 #######`, { fire: 3 })
23 s = step(s, { id: 'wait' }).state
24 expect(s.cells.slice(7, 14)).toEqual(['wall', 'floor', 'floor', 'floor', 'block', 'floor', 'wall'])
25 })
26
27 it('chains: a bomb in the flame explodes now, whatever its timer', () => {
28 const s = board(`
29 ########
30 #P1.3.+#
31 ########`, { fire: 2 })
32 const events: GameEvent[] = []
33 s.bombs[0]!.timer = 0
34 const burned = detonate(s, events)
35 expect(s.bombs).toEqual([])
36 expect(events.filter((e) => e.type === 'exploded').map((e) => e.type === 'exploded' && e.pos)).toEqual([v(2, 1), v(4, 1)])
37 expect(burned.has(1 * 8 + 6)).toBe(true) // the second bomb's flame reached the block
38 expect(s.cells[1 * 8 + 6]).toBe('floor')
39 })
40
41 it('a block hit by two flames in one chain still stops both', () => {
42 const s = board(`
43 #######
44 #P1+1.#
45 #######`, { fire: 3 })
46 s.bombs.forEach((b) => (b.timer = 0))
47 const burned = detonate(s, [])
48 expect(burned.has(1 * 7 + 5)).toBe(true) // right bomb burns rightwards
49 expect(burned.has(1 * 7 + 1)).toBe(true) // left bomb burns the player's tile
50 expect(s.cells[1 * 7 + 3]).toBe('floor')
51 })
52})