Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"cli": "node dist/cli/index.js",
"cli:dev": "npx tsx src/cli/index.ts",
"test": "node --import tsx --test 'test/**/*.test.ts'",
"build": "npx tsc",
"build": "rimraf dist && tsc",
"build:c": "gcc -Wall -Wextra -std=c99 -lm performance/single-run.c -o performance/single-run",
"build:wasm": "emcc -Wall -Wextra -std=c99 -O3 -s WASM=1 -s MODULARIZE=1 -s EXPORT_ES6=1 -s EXPORTED_RUNTIME_METHODS='[\"UTF8ToString\",\"HEAP32\",\"_malloc\",\"_free\"]' -s EXPORT_NAME='createModule' performance/single-run-wasm.c -o performance/single-run-wasm.js -lm",
"test:performance": "npx tsx performance/single-run.ts",
Expand All @@ -28,6 +28,7 @@
"devDependencies": {
"@types/node": "^22.19.7",
"0x": "^6.0.0",
"rimraf": "^6.1.2",
"tsx": "^4.7.0"
},
"repository": {
Expand Down
12 changes: 12 additions & 0 deletions src/ai/solver/mcts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Move, Solver } from './solver.js';
import { GameState } from '../../models/gamestate.js';
import { convertOrientation } from '../utils/utils.js';

export class MCTSSolver implements Solver {
readonly name = 'MCTS Solver';
Expand Down Expand Up @@ -240,6 +241,17 @@ export class MCTS {
return null;
}

// helps to understand the decision making process
if(process.env.ALGO_DEBUG){
console.log("MCTS: uct values");
console.table(this.root.children.map((c) => ({
move: `${c.move.id} ${convertOrientation(c.move.orientation)}`,
uct: c.uctValue,
visits: c.visits,
wins: c.wins,
})).sort((a, b) => b.uct - a.uct));
}

// find the child with the most visits
const best = this.root.children.reduce((a, b) =>
a.visits > b.visits ? a : b,
Expand Down
12 changes: 3 additions & 9 deletions src/models/gamestate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ export class GameState {
const id = arr[step].id;

if (this.getById(id).state === 0) {
console.table(
this.gameField.map((row) => row.map((field) => field.state)),
);
console.table(
this.gameField.map((row) => row.map((field) => field.id)),
);
const arr = this.getFromSide(i, orientation);
throw new Error(`stone with id ${id} is not empty`);
}
Expand Down Expand Up @@ -252,9 +246,9 @@ export class GameState {

// TODO: check if move is allowed
if (!this.isValidMove(arr, takeNumber)) {
console.table(
this.gameField.map((row) => row.map((field) => field.state)),
);
// console.table(
// this.gameField.map((row) => row.map((field) => field.state)),
// );
throw Error(
`invalid move with id ${arr[takeNumber].id}, row ${row}, column ${column}, orientation ${convertOrientation(orientation)}`,
);
Expand Down
Loading