diff --git a/packages/shared/src/__tests__/game_map.test.ts b/packages/shared/src/__tests__/game_map.test.ts new file mode 100644 index 00000000..b5d5f207 --- /dev/null +++ b/packages/shared/src/__tests__/game_map.test.ts @@ -0,0 +1,9 @@ +import { getDefaultConfig, getVariantList, makeGameObject } from "../game_map"; + +test.each(getVariantList())("Build %s from default config", (variant) => { + const default_config = getDefaultConfig(variant); + + // This is a dummy expectation + // This test is basically a success if neither function call throws an error + expect(makeGameObject(variant, default_config)).toBeDefined(); +}); diff --git a/packages/shared/src/variants/pyramid.ts b/packages/shared/src/variants/pyramid.ts index 650a5a71..f9f9de15 100644 --- a/packages/shared/src/variants/pyramid.ts +++ b/packages/shared/src/variants/pyramid.ts @@ -3,14 +3,16 @@ import { Grid } from "../lib/grid"; export class PyramidGo extends Baduk { private weights: Grid; - constructor(config: BadukConfig) { + constructor(config?: BadukConfig) { super(config); - this.weights = new Grid(config.width, config.height) + // Note: config may be undefined, but this.config is + // defined after the AbstractGame constructor is called. + const { width, height } = this.config; + + this.weights = new Grid(width, height) .fill(0) - .map((_, { x, y }) => - Math.min(x + 1, y + 1, config.width - x, config.height - y), - ); + .map((_, { x, y }) => Math.min(x + 1, y + 1, width - x, height - y)); } get result(): string {