62 lines
2.2 KiB
JavaScript
62 lines
2.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
generateWorld,
|
|
nearestPort,
|
|
pirateInfluenceAt,
|
|
pirateSpawnPointsForWave,
|
|
} from '../src/world/world-generator.js';
|
|
|
|
test('world generation is deterministic for a seed', () => {
|
|
const a = generateWorld({ seed: 'TEST-SEED', width: 3600, height: 3600 });
|
|
const b = generateWorld({ seed: 'TEST-SEED', width: 3600, height: 3600 });
|
|
assert.deepEqual(a, b);
|
|
});
|
|
|
|
test('different seeds create different geography', () => {
|
|
const a = generateWorld({ seed: 'A' });
|
|
const b = generateWorld({ seed: 'B' });
|
|
assert.notDeepEqual(a.islands, b.islands);
|
|
});
|
|
|
|
test('generated world contains ports, trade routes, and pirate territory', () => {
|
|
const world = generateWorld({ seed: 'TRADE-WORLD' });
|
|
assert.ok(world.islands.length >= 10);
|
|
assert.ok(world.ports.length >= 4);
|
|
assert.ok(world.tradeRoutes.length >= world.ports.length - 1);
|
|
assert.ok(world.pirateTerritories.length >= 1);
|
|
|
|
const portIds = new Set(world.ports.map(({ id }) => id));
|
|
for (const route of world.tradeRoutes) {
|
|
assert.ok(portIds.has(route.fromPortId));
|
|
assert.ok(portIds.has(route.toPortId));
|
|
assert.ok(route.value > 0);
|
|
}
|
|
});
|
|
|
|
test('pirate influence peaks inside generated pirate territory', () => {
|
|
const world = generateWorld({ seed: 'BLACKWAKE' });
|
|
const territory = world.pirateTerritories[0];
|
|
assert.ok(territory);
|
|
assert.ok(pirateInfluenceAt(world, territory.center.x, territory.center.y) >= 0.4);
|
|
});
|
|
|
|
test('wave spawns originate around generated pirate territory and remain in bounds', () => {
|
|
const world = generateWorld({ seed: 'SPAWN-WORLD' });
|
|
const player = { x: world.spawn.x, y: world.spawn.y };
|
|
const points = pirateSpawnPointsForWave(world, player, 5, 3);
|
|
assert.equal(points.length, 5);
|
|
for (const point of points) {
|
|
assert.ok(point.x >= 120 && point.x <= world.width - 120);
|
|
assert.ok(point.y >= 120 && point.y <= world.height - 120);
|
|
assert.ok(point.territoryId);
|
|
}
|
|
});
|
|
|
|
test('nearestPort reports the generated starter port nearby', () => {
|
|
const world = generateWorld({ seed: 'PORT-WORLD' });
|
|
const result = nearestPort(world, world.spawn.x, world.spawn.y);
|
|
assert.ok(result.port);
|
|
assert.ok(result.range < 400);
|
|
});
|