Coder Social home page Coder Social logo

goscorer's Introduction

goscorer

Territory scoring in Go with automated seki detection is very challenging. The intent for this library is provide an open-source implementation that can correctly score almost any end-of-game position under Japanese-like rules that territory is not counted for groups alive in seki, if dead stones are correctly marked and enough of the eventually-necessary protective moves are made. It may not always be correct in sufficiently exotic positions, but positions not correctable with further play should be rare.

In practice, this implementation does NOT require players to fill all the dame. By default it will automatically exclude counting obvious false eye shapes that must eventually be filled, although this can be configured. Of course, this will not catch all necessary internal protections. Players still need to play enough of the dame to force internal protections that aren't simply false eye shapes.

See here for a live interactive page that you can use to test the behavior of the algorithm on different positions.

Top groups are correctly detected as alive in seki and no territory is counted. Bottom groups are alive with territory, but territory is still not counted for some of the false eyes.

There is both a Python implementation and a Javascript implementation that implement exactly the same algorithm and heuristics. The Python implementation is well-commented with verbose docstrings on the LocScore object and the primary territory_scoring function. The Javascript implementation is a port of the Python implementation, so for more detailed documentation, see the Python code rather than the Javascript code. For completeness, an area scoring implementation is also provided alongside the territory scoring implementation.

If you find any bugs or anomalies in the scoring, please let me know!

The relevant code in this repo is released under a MIT license, see LICENSE.txt for details.

Example in Python:

from goscorer import EMPTY, BLACK, WHITE, final_territory_score, territory_scoring
stones = [
  [BLACK, EMPTY, BLACK, EMPTY, WHITE],
  [BLACK, BLACK, BLACK, WHITE, EMPTY],
  [WHITE, WHITE, WHITE, BLACK, BLACK],
  [WHITE, EMPTY, WHITE, BLACK, EMPTY],
  [EMPTY, WHITE, WHITE, BLACK, BLACK],
]
marked_dead = [ [ False for _ in range(5) ] for _ in range(5) ]

# just the score
final_score = final_territory_score(
    stones,
    marked_dead,
    black_points_from_captures=0,
    white_points_from_captures=0,
    komi=6.5,
)
# detailed territory map
scoring = territory_scoring(stones,marked_dead)

Example in Javascript:

import { EMPTY, BLACK, WHITE, finalTerritoryScore, territoryScoring } from "./goscorer.js";

stones = [
  [BLACK, EMPTY, BLACK, EMPTY, WHITE],
  [BLACK, BLACK, BLACK, WHITE, EMPTY],
  [WHITE, WHITE, WHITE, BLACK, BLACK],
  [WHITE, EMPTY, WHITE, BLACK, EMPTY],
  [EMPTY, WHITE, WHITE, BLACK, BLACK],
];
markedDead = Array.from({length: 5}, () => Array.from({length: 5}, () => false));

// just the score
finalScore = finalTerritoryScore(
    stones,
    markedDead,
    0,
    0,
    6.5,
)
// detailed territory map
scoring = territoryScoring(stones,markedDead)

goscorer's People

Contributors

lightvector avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.