fix: fix tic tac toe tests

This commit is contained in:
2026-04-04 18:42:21 +08:00
parent de7006ef19
commit 467a56bd84
3 changed files with 94 additions and 97 deletions
+16
View File
@@ -111,3 +111,19 @@ function createEmptyPartPool<TMeta>(): PartPool<TMeta> {
},
};
}
export function createPartsFromTable<T>(items: T[], getId: (item: T, index: number) => string, getCount?: ((item: T) => number) | number){
const pool: Record<string, Part<T>> = {};
for (const entry of items) {
const count = getCount ? (typeof getCount === 'function' ? getCount(entry) : getCount) : 1;
for (let i = 0; i < count; i++) {
const id = getId(entry, i);
pool[id] = {
id,
regionId: '',
position: [],
...entry
};
}
}
return pool;
}
+1 -1
View File
@@ -14,7 +14,7 @@ export type { Part } from './core/part';
export { flip, flipTo, roll, findPartById, isCellOccupied, getPartAtPosition, isCellOccupiedByRegion, getPartAtPositionInRegion } from './core/part';
export type { PartTemplate, PartPool } from './core/part-factory';
export { createPart, createParts, createPartPool, mergePartPools } from './core/part-factory';
export { createPart, createParts, createPartPool, mergePartPools, createPartsFromTable } from './core/part-factory';
export type { Region, RegionAxis } from './core/region';
export { createRegion, applyAlign, shuffle, moveToRegion } from './core/region';