This commit is contained in:
2026-01-11 10:35:12 +00:00
parent 373ddd863d
commit 511aade81c
9 changed files with 127 additions and 25 deletions
@@ -111,8 +111,8 @@ describe('che_NPC능동', () => {
const runner = new TestGameRunner(world, 200, 1);
// Add NPC General manually to snapshot
const cityId = MINIMAL_MAP.cities[0].id;
const destCityId = MINIMAL_MAP.cities[1].id;
const cityId = MINIMAL_MAP.cities[0]!.id;
const destCityId = MINIMAL_MAP.cities[1]!.id;
const general: General = {
id: 1,
@@ -144,7 +144,7 @@ describe('che_NPC능동', () => {
};
world.snapshot.generals.push(general);
const outcome = await runner.runTurn([
await runner.runTurn([
{
generalId: general.id,
commandKey: 'che_NPC능동',
@@ -166,8 +166,8 @@ describe('che_NPC능동', () => {
});
const world = new InMemoryWorld(bootstrapResult.snapshot);
const cityId = MINIMAL_MAP.cities[0].id;
const destCityId = MINIMAL_MAP.cities[1].id;
const cityId = MINIMAL_MAP.cities[0]!.id;
const destCityId = MINIMAL_MAP.cities[1]!.id;
const general: General = {
id: 1,
@@ -0,0 +1,73 @@
import { describe, expect, it } from 'vitest';
import { getCityDistance, searchDistance } from '@sammo-ts/logic/world/distance.js';
import type { MapDefinition } from '@sammo-ts/logic/world/types.js';
describe('World Distance', () => {
const mockMap: MapDefinition = {
id: 'test_map',
name: 'Test Map',
cities: [
{ id: 1, connections: [2, 3] },
{ id: 2, connections: [1, 4] },
{ id: 3, connections: [1, 5] },
{ id: 4, connections: [2, 6] },
{ id: 5, connections: [3, 7] },
{ id: 6, connections: [4] },
{ id: 7, connections: [5] },
// Isolated city
{ id: 8, connections: [] },
] as any[],
};
describe('getCityDistance', () => {
it('should return 0 for same city', () => {
expect(getCityDistance(mockMap, 1, 1)).to.equal(0);
});
it('should return 1 for adjacent cities', () => {
expect(getCityDistance(mockMap, 1, 2)).to.equal(1);
expect(getCityDistance(mockMap, 1, 3)).to.equal(1);
});
it('should return correct distance for distant cities', () => {
expect(getCityDistance(mockMap, 1, 4)).to.equal(2); // 1-2-4
expect(getCityDistance(mockMap, 1, 6)).to.equal(3); // 1-2-4-6
});
it('should return Infinity for unreachable cities', () => {
expect(getCityDistance(mockMap, 1, 8)).to.equal(Infinity);
});
});
describe('searchDistance', () => {
it('should include start city with distance 0', () => {
const result = searchDistance(mockMap, 1, 0);
expect(result).to.deep.equal({ 1: 0 });
});
it('should find cities within range 1', () => {
const result = searchDistance(mockMap, 1, 1);
expect(result).to.deep.equal({
1: 0,
2: 1,
3: 1,
});
});
it('should find cities within range 2', () => {
const result = searchDistance(mockMap, 1, 2);
expect(result).to.deep.equal({
1: 0,
2: 1,
3: 1,
4: 2,
5: 2,
});
});
it('should not include unreachable cities', () => {
const result = searchDistance(mockMap, 1, 10);
expect(result).not.to.have.property('8');
});
});
});