Skip to content

Commit

Permalink
Pyramid Go support empty config (Fixes #163)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpjones committed Jan 7, 2024
1 parent 69ee47c commit 32d340d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 9 additions & 0 deletions packages/shared/src/__tests__/game_map.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
12 changes: 7 additions & 5 deletions packages/shared/src/variants/pyramid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { Grid } from "../lib/grid";

export class PyramidGo extends Baduk {
private weights: Grid<number>;
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 {
Expand Down

0 comments on commit 32d340d

Please sign in to comment.