Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up ScoreEstimator.ts #135

Merged
merged 19 commits into from
Oct 30, 2023

Conversation

benjaminpjones
Copy link
Contributor

@benjaminpjones benjaminpjones commented Oct 26, 2023

I've wanted to play with ScoreEstimator for a while, but there is a lot going on in there, and it's not easy to test due to external dependencies on OGSScoreEstimator (c++ WASM lib) and the remote AI scorer. I figured the best way to approach this is to clean it up as much as I can in one pass and manually test all changes together. That said, let me know if there are commits that aren't desired, it shouldn't be too hard for me to remove them.

Motivations

Observations

  • There is duplicate code for calculating groups (see GoMath.GoStoneGroups)
  • Score estimator is mostly used indirectly through methods in GoEngine/GobanCore
    • The methods construct the estimator, then call a single method
    • exception: the estimator is emitted, and the UI Game class accesses the winner and amount
  • Many properties appear to be unused

Assumptions

Please let me know if these are invalid. If you have code snippets on external usages, I can create additional unit tests to help capture the behavior (similar to the "amount and winner" test).

  • Server is not using WASM anymore
  • Server uses GoEngine functions to access the ScoreEstimator, not accessing the estimator directly

Changes

See individual commit messages - I tried to make these as atomic and self-explanatory as possible.

Testing

  • Manual client testing
    • [remote] Click estimate score on the current user's finished game
    • [local] Click estimate score on the current user's ongoing game
    • [remote] Click estimate score on an ongoing game (as an observer)
    • [remote] Finish a game, mis-score, auto-score
  • Unit tests
    • created ScoreEstimator.test.ts
    • 25% increase in line coverage for ScoreEstimator.ts

Reasoning: the wait_for promise is not awaited, so the result of
getProbablyDead is meaningless here.
This function is only ever called on a prefer_remote SE. Also,
the ownership/tolerance calculation should still be valid with
WASM if ever needs to be used like that.
This looks like a copy of ScoreEstimator.area and is never used.
This helps with testing, and also will allow us to do the same adjustments
with other scoring algorithms.
These are both derived from ownership.  area appears to be unused,
and heat is used in GobanCanvas, but can just be replaced with ownership.
Copy link
Member

@anoek anoek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, this is some pretty dusty code, and you'll make a lot of people happy (myself included) if you can make it less dumb (but not too smart either!).

Regarding the not too smart part - when I introduced the KataGo backend the community basically said it was too smart, which is why we still have that WASM backend for live game estimates, so that's something to keep in mind when pondering your JS backend and for revising things to be less dumb.

Less dumb is good, too good at the game is bad, but if we can work towards some sweet spot in-between that's great :)

Anyways, I always love your refactors, thanks for taking this one on!

export interface ScoreEstimateRequest {
player_to_move: "black" | "white";
width: number;
height: number;
board_state: Array<Array<number>>;
rules: GoEngineRules;
black_prisoners?: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are still used on the backend, ogs-node repository

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point it might make more sense to have a separate type for the score estimate requests sent off to the server that include these, I'd be OK with that too depending on how much you want to change. It's convenient to have it somewhere in the goban repository that way both the UI and the server side can use it, although on the flip side maybe it still makes a bit of sense too to have a common ScoreEstimateRequest structure depending on which backend we're using, the WASM module, the server KataGo system, or the newfangled JS backend you have in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, and added back in! I don't really have a preference regarding separate types or a unified type, but I'll keep it as-is in this PR to minimize downstream churn.

These properties are still referenced on the backend.
@benjaminpjones
Copy link
Contributor Author

Thanks for reviewing! Definitely makes sense to want a "dumb" in-game estimator. The algorithms I'd like to experiment with are geometric and have no knowledge of Go (variations on the Voronoi algorithm from this thread), so I don't think they should be perceived as too smart at all.

@anoek anoek merged commit 74c1e28 into online-go:main Oct 30, 2023
1 check passed
@benjaminpjones benjaminpjones deleted the score-estimator-cleanup branch October 30, 2023 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants