코드 이식

This commit is contained in:
2026-01-11 09:49:22 +00:00
parent 6497b09b9d
commit dc0b9271fb
14 changed files with 2195 additions and 76 deletions
+28
View File
@@ -0,0 +1,28 @@
import type { MapDefinition } from '@sammo-ts/logic/world/types.js';
export const getCityDistance = (map: MapDefinition, startCityId: number, endCityId: number): number => {
if (startCityId === endCityId) return 0;
const visited = new Set<number>();
const queue: [number, number][] = [[startCityId, 0]]; // [cityId, distance]
visited.add(startCityId);
while (queue.length > 0) {
const [currentId, dist] = queue.shift()!;
const cityDef = map.cities.find(c => c.id === currentId);
if (!cityDef) continue;
for (const neighborId of cityDef.connections) {
if (neighborId === endCityId) {
return dist + 1;
}
if (!visited.has(neighborId)) {
visited.add(neighborId);
queue.push([neighborId, dist + 1]);
}
}
}
return Infinity;
};
+1
View File
@@ -2,3 +2,4 @@ export * from './types.js';
export * from './bootstrap.js';
export * from './loader.js';
export * from './unitSet.js';
export * from './distance.js';