From 1e83e3c415ab0f1b9bef61c29f999e76a4705384 Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Wed, 19 Jun 2024 07:35:15 -0600 Subject: [PATCH] Comments, fix autoscore test game fetcher script, include seal points in final autoscore debug output --- scripts/fetch_game_for_autoscore_testing.ts | 2 +- src/engine/autoscore.ts | 55 ++++++++++++++++++- .../{game_17150.json => game_beta_17150.json} | 0 tsconfig.json | 9 +-- 4 files changed, 57 insertions(+), 9 deletions(-) rename test/autoscore_test_files/{game_17150.json => game_beta_17150.json} (100%) diff --git a/scripts/fetch_game_for_autoscore_testing.ts b/scripts/fetch_game_for_autoscore_testing.ts index ec2ccc33..93d0b98a 100755 --- a/scripts/fetch_game_for_autoscore_testing.ts +++ b/scripts/fetch_game_for_autoscore_testing.ts @@ -12,7 +12,7 @@ Note: this script requires a JWT to be provided in the file "user.jwt" */ import { readFileSync, writeFileSync } from "fs"; -import { ScoreEstimateRequest } from "../src/ScoreEstimator"; +import { ScoreEstimateRequest } from "engine"; const jwt = readFileSync("user.jwt").toString().replace(/"/g, "").trim(); const game_id = process.argv[2]; diff --git a/src/engine/autoscore.ts b/src/engine/autoscore.ts index ebf0e8ca..7436e529 100644 --- a/src/engine/autoscore.ts +++ b/src/engine/autoscore.ts @@ -102,7 +102,20 @@ export function autoscore( score_positions(); stage("Final state"); - debug_board_output("Final ownership", final_ownership); + const final_ownership_with_seals = makeMatrix(width, height, "."); + for (let y = 0; y < height; ++y) { + for (let x = 0; x < width; ++x) { + if (sealed[y][x]) { + final_ownership_with_seals[y][x] = "s"; + } else { + final_ownership_with_seals[y][x] = + final_ownership[y][x] === 1 ? "B" : final_ownership[y][x] === 2 ? "W" : "."; + } + } + } + + //debug_board_output("Final ownership", final_ownership); + debug_board_string_output("Final ownership", final_ownership_with_seals); debug_boolean_board("Sealed", sealed, "s"); debug_board_output("Final sealed ownership", final_sealed_ownership); @@ -172,6 +185,15 @@ export function autoscore( } */ + /** + * Look for groups that look like they are at risk of a snapback and + * mark them as settled to avoid trying to be too smart, let the players + * figure out what they want to with those stones, if anything. Neighboring + * strings are also marked as settled as any that aren't are likely intwined + * in the life and death and resulting status of the snapback, so again to + * avoid trying to be too smart, just trust that the players intended to + * end the game in this state and score it. + */ function settle_snapback_locations() { stage("Settling snapbacks"); @@ -821,6 +843,37 @@ function debug_board_output(title: string, board: JGOFNumericPlayerColor[][]) { end_board(); } +function debug_board_string_output(title: string, board: string[][]) { + begin_board(title); + let out = " "; + const x_coords = "ABCDEFGHJKLMNOPQRST"; // cspell: disable-line + + for (let x = 0; x < board[0].length; ++x) { + out += `${x_coords[x]}`; + } + out += "\n"; + + for (let y = 0; y < board.length; ++y) { + out += ` ${board.length - y} `.substr(-3); + for (let x = 0; x < board[y].length; ++x) { + out += colorizeIntersection(board[y][x]); + } + + out += " " + ` ${board.length - y} `.substr(-3); + out += "\n"; + } + + out += " "; + for (let x = 0; x < board[0].length; ++x) { + out += `${x_coords[x]}`; + } + out += "\n"; + + out += "\n"; + board_output(out); + end_board(); +} + function colorizeIntersection(c: string): string { if (c === "B" || c === "S") { return black(c); diff --git a/test/autoscore_test_files/game_17150.json b/test/autoscore_test_files/game_beta_17150.json similarity index 100% rename from test/autoscore_test_files/game_17150.json rename to test/autoscore_test_files/game_beta_17150.json diff --git a/tsconfig.json b/tsconfig.json index 5fbf6724..3fdbbeb9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -33,13 +33,8 @@ "sourceMap": true, "jsx": "react" }, - "files": [ - "src/index.ts", - "src/engine/index.ts", - "jest.config.ts", - "./src/engine/util/getRandomInt.ts" - ], - "include": ["test/**/*.ts"], + "files": ["src/index.ts", "src/engine/index.ts", "jest.config.ts"], + "include": ["test/**/*.ts", "scripts/**/*.ts"], "ts-node": { "require": ["tsconfig-paths/register"] }