# KataGo's Planned-To-Be-Supported Go Rules (DRAFT - Version 0)

This is NOT the latest version of these rules. The latest rules can be found here.

## Parameters

Click the buttons or individually uncheck some of the boxes to hide parts of the logic for rules you don't care about.

- X,Y:
  Integers indicating the board size.
- Komi:
  Integer or half-integer indicating compensation given to White for going second.
- KoRule:
  The variant of the rule prohibiting repetition. https://senseis.xmp.net/?KoRules
  Simple Positional Superko Situational Superko
- ScoringRule:
  Defines what the score of a finished game is. https://senseis.xmp.net/?Scoring
  Area (count stones and surrounded empty points, "Chinese"-like) Territory (count captures and surrounded empty points, "Japanese"-like)
- TaxRule:
  Minor adjustments to scoring rule, indicating what, if any, empty points may not be scored.
  None (surrounded empty points always count) Seki (empty points surrounded by groups in seki do not count) All (all groups are taxed up to 2 of their surrounded empty points - i.e. empty points surrounded by groups in seki do not count, and living groups are taxed 2 points each)
- MultiStoneSuicide:
  Whether suicide of multiple stones is allowed. (in these rules, a suicide move that kills only the stone just played and nothing else, leaving the board unchanged, is never allowed)
  Allowed Disallowed
- Button:
  Whether a half-point is awarded to the first player to be able to pass. (e.g. slightly rewarding endgame efficiency, partially reconciling area and territory scoring).
  Used Not Used
- SelfPlayOpts:
  Some optimizations that KataGo uses for self-play. These theoretically could make a difference to correct play in extremely contrived situations involving things like carefully constructed superko histories, but for all practical purposes these rules modifications are compatible with the rules without these modifications and simply speed up self-play a via faster game end, even if one or both players want to prolong the game.
  Enabled

## Rules

### Basic Definitions

1. Go is played on an X by Y rectangular grid of points by two opposing players, Black and White.
2. Each point on the grid can be colored black or white or be empty. The coloring status of all points together is the grid coloring.
3. Points are adjacent/bordering if they are horizontally or vertically touching.
4. Within a set of points, two points are connected if one is adjacent to the other or is connected to a point adjacent to the other. The set itself is connected if every pair of points in it is connected within that set.
5. A set of points and a point not in that set are adjacent/bordering if that point is adjacent to some member of the set. Two disjoint sets of points are adjacent/bordering if one borders at least one point of the other. A set of points borders a color if it borders at least one point of that color.
6. A {black, white, empty, maximal-non-black, maximal-non-white} region is any maximal connected set of {black, white, empty, non-black, non-white} points, respectively. Maximal means there is no strictly larger connected set of such points that contains it.

### Pseudolegal moves

1. A liberty of a black or white region is any empty point that borders it.
2. Resolving captures of a color consists of emptying all points of regions of that color with no liberties. Every emptying of a point this way during the game adds to the total number of captures of that color.
3. A pseudolegal move consists of a player performing the following:
   - Coloring an empty point with the player's color.
   - Then resolving captures of the opponent's color.
   - Then resolving captures of the player's color.
   ...subject the restriction that this must NOT result in same grid coloring as prior to these steps.
   ...(if MultiStoneSuicide is Disallowed) and also subject to the restriction that resolving captures of the player's own color must NOT empty any points.

### Additional Definitions

1. An empty region that borders both black and white is a dame region.
2. A black or white region is in atari if it is has exactly one liberty.
3. A {maximal-non-white, maximal-non-black} region is a {black, white} independent-life-region if it does NOT contain any dame regions or any regions in atari.[1]

4. A black or white region R is a pass-alive-group if there does not exist any sequence of consecutive pseudolegal moves of the opposing color that results in emptying R.[2]
5. A {maximal-non-black, maximal-non-white} region R is pass-alive-territory for {Black, White} if all {black, white} regions bordering it are pass-alive-groups, and all or all but one point in R is adjacent to a {black, white} pass-alive-group, respectively.[3]

### Main Phase

The game begins with a main phase of play and then possibly one or two cleanup phases.

During the main phase the state consists of:

- The grid coloring.
- (if KoRule is Simple or Situational SuperKo): Additionally, the color of the player next to take a turn.
- (if Button is Used): Additionally, whether or not at least one pass has occurred.

Starting with an empty grid, the players alternate turns, starting with Black. A turn in the main phase is either a pass or a legal move.

- A pass cedes the turn with no effect (but may possibly end the phase, as described below).
- A legal move during the main phase is any pseudolegal move that...
  - (if KoRule is Simple): ...doesn't result in the state at the start of the opponent's previous turn.
  - (if KoRule is Positional or Situational SuperKo): ...doesn't result in any earlier state.

The main phase ends after:

1. (if Button is NotUsed): There are 2 consecutive passes.
2. (if Button is Used): There are 2 consecutive passes, ignoring the first pass of the game.
3. (if KoRule is Simple): Additionally the game also ends if:
   1. A player passes from a state that the player has already passed from once before.[4]
   2. OR at the start of a player's turn, the current state has already occurred twice before since the most recent pass by either player. In this case the not only the main phase ends but the entire game immediately ends as well, with a result of "no result".[5]
4. (if SelfPlayOpts is Enabled): Additionally, the phase also ends at the end of a turn if every point on the board belongs to a pass-alive-group or pass-alive-territory. In this case the entire game ends immediately as well and is scored exactly as if the game had ended by both players repeatedly passing with no further legal moves or other actions.

After the main phase ends:

(if ScoringRule is Territory)
The game is NOT ended or scored and instead continues with two cleanup phases (see "Cleanup Phases" section below).

(if ScoringRule is Area)
The game ends and is scored as follows:

- (if SelfPlayOpts is Enabled): Before scoring, for each color, empty all points of that color within pass-alive-territory of the opposing color.
- (if TaxRule is None): A player's score is the sum of:
  - +1 for every point of their color.
  - +1 for every point in empty regions bordered by their color and not by the opposing color.
  - If the player is White, Komi.
  - (if Button is Used): +0.5 if this player was the first to pass.
- (if TaxRule is Seki): A player's score is the sum of:
  - +1 for every point of their color.
  - +1 for every empty point within independent-life-regions of their color.
  - If the player is White, Komi.
  - (if Button is Used): +0.5 if this player was the first to pass.
- (if TaxRule is All): A player's score is the sum of:
  - +1 for every point of their color.
  - +1 for every empty point within independent-life-regions of their color.
  - -2 points for every independent-life-region of their color.
  - If the player is White, Komi.
  - (if Button is Used): +0.5 if this player was the first to pass.

The player with the higher score wins, or the game is a draw if equal score.

### Cleanup Phases

These phases only occur if scoringRule is Territory.

Cleanup is designed to try to match most of the ways that positions would be ruled and scored under normal Japanese rules, so long as players self-interestedly maximize their score during cleanup. Broadly, this is done by giving players 1 point of compensation per move during the (second) cleanup phase, such that the players can now capture dead stones and resolve all disputes without loss of points for filling in territory.

A variety of details are also managed to implement other quirks of Japanese rules. Including there-are-no-points-in-seki, and the Japanese conception of each position as "independent", such that ko threats in one part of the board do not affect the status of the rest of the board. For example, a bent-four-in-the-corner will still resolve as dead under optimal play with these rules even if there are unremovable ko threats on the rest of the board. A lot of the mechanism to do this is based on the Japanese rules themselves, attempting to formalize their spirit to try to make them rigorous enough for self-play.

We do not aim for a 100% perfect match, however. For example, under this ruleset, three-points-without-capturing will (usually) entirely naturally be three points without capturing with no need for any special ruling, matching the traditional Japanese ruling (and in effect, justifying it). But the modern Japanese rules instead regard it as a seki, in which black must concede down to two points to get anything. More exotic kinds of positions will also differ between these rules and Japanese rules.

#### Cleanup Phase Basics and Definitions

1. A ko-move for a player in a position is any pseudolegal move M where the opponent would have a pseudolegal move in response, the ko-reply, that would result in exactly the grid coloring prior to M.
2. In addition to the grid coloring, for each player, points on the grid may be marked as ko-blocked for that player.
3. The state during cleanup phases consists of the grid coloring together with the ko-blocked status of all points for both players and the color of the player next to take a turn.

#### Cleanup Phase Play

Cleanup lasts for two phases[6]. In each phase, starting with the grid coloring from the end of the previous phase, the players alternate turns, starting with the opponent of the player who took the last turn of the previous phase. A turn in the cleanup is either a pass, a legal move, or an unblock-ko action.[7]

- A pass cedes the turn with no effect (but may possibly end the phase, as described below).
- A legal move by a player during a cleanup phase is any pseudolegal move that either...
  - Is NOT a ko-move.
  - Is a ko-move that both...
    - Is NOT on a point marked as ko-blocked for that player.
    - AND where that player did NOT on any earlier turn during the same cleanup phase make a legal move on exactly the same point with exactly the same grid coloring.[8]
    Then, followed by marking the point of the potential ko-reply as ko-blocked for the opponent.
  Then, followed by unmarking all ko-blocked points for the opponent that are no longer ko-moves for the opponent.[9]
- An unblock-ko action consists of a player choosing a point marked as ko-blocked for that player and removing that mark.

#### Cleanup Phase Ending and Scoring

A cleanup phase ends after any of:

1. There are two consecutive passes.
2. OR a player passes from a state that the player has already passed from once before during the same phase.[10]
3. OR at the start of a player's turn, the current state has already occurred twice before since the most recent pass by either player during this phase. In this case the not only the phase ends but the entire game immediately ends as well, with a result of "no result".

After the first cleanup phase ends, the second cleanup phase begins immediately with the same grid coloring but with all ko-blocks unmarked.

After the second cleanup phase ends, the game ends and is scored as follows:

- (if SelfPlayOpts is Enabled): Before scoring, for each color, empty all points of that color within pass-alive-territory of the opposing color. Points emptied this way also add to the total number of captures of that point's color.
- (if TaxRule is None): A player's score is the sum of:
  - +1 for every point in empty regions bordered by their color and not by the opposing color.
  - + The total number of captures of the opposing color.
  - +1 for every move made by that player during the second cleanup phase.
  - -1 for every point of their color not within independent-life-regions and that was not their color at the start of the second cleanup phase.
  - If the player is white, Komi.
  - (if Button is Used): +0.5 if this player was the first to pass during the main phase.
- (if TaxRule is Seki): A player's score is the sum of:
  - +1 for every empty point within independent-life-regions of their color.
  - + The total number of captures of the opposing color.
  - +1 for every move made by that player during the second cleanup phase.
  - -1 for every point of their color not within independent-life-regions and that was not their color at the start of the second cleanup phase.
  - If the player is white, Komi.
  - (if Button is Used): +0.5 if this player was the first to pass during the main phase.
- (if TaxRule is All): A player's score is the sum of:
  - +1 for every empty point within independent-life-regions of their color.
  - + The total number of captures of the opposing color.
  - +1 for every move made by that player during the second cleanup phase.
  - -1 for every point of their color not within independent-life-regions and that was not their color at the start of the second cleanup phase.
  - -2 points for every independent-life-region of their color.
  - If the player is white, Komi.
  - (if Button is Used): +0.5 if this player was the first to pass during the main phase.

See [11] for some remarks about the scoring.

The player with the higher score wins, or the game is a draw if equal score.

For computer AI training, the following equivalent formulation for a player's score could also be used if desired. This formulation is much more similar to area scoring, in that it factors over the board as simply a sum of +1/0/-1 for each point on the board, and moves within independent-life-regions by either player do not affect this "ownership" sum whatsoever (so long as dead stones are cleaned up and borders and dame are finished).

- (if TaxRule is None): A player's score is the sum of:
  - -1 for every move made by that player in the main phase OR first cleanup phase.
  - +1 for every point in empty regions bordered by their color and not by the opposing color.
  - +1 for every point of their color that is within independent-life-regions OR that was their color at the start of the second cleanup phase.
  - If the player is white, Komi.
  - (if Button is Used): +0.5 if this player was the first to pass during the main phase.
- (if TaxRule is Seki): A player's score is the sum of:
  - -1 for every move made by that player in the main phase OR first cleanup phase.
  - +1 for every empty point within independent-life-regions of their color.
  - +1 for every point of their color that is within independent-life-regions OR that was their color at the start of the second cleanup phase.
  - If the player is white, Komi.
  - (if Button is Used): +0.5 if this player was the first to pass during the main phase.
- (if TaxRule is All): A player's score is the sum of:
  - -1 for every move made by that player in the main phase OR first cleanup phase.
  - +1 for every empty point within independent-life-regions of their color.
  - +1 for every point of their color that is within independent-life-regions OR that was their color at the start of the second cleanup phase.
  - -2 points for every independent-life-region of their color.
  - If the player is white, Komi.
  - (if Button is Used): +0.5 if this player was the first to pass during the main phase.

[1] The intent is "independent-life-regions" indicate regions that are not seki, so long as both players finish all borders and fill all dame. This is motivated by the way Japanese rules attempt to define "seki" using dame. Using the presence of dame to determine seki is actually a pretty clever solution - my original idea had only been to use ability-to-make-pass-alive-ness, but this is considerably more awkward in practice than using dame. We also include the condition of "atari" to handle groups that have no dame but still survive without two eyes by virtue of having ko mouths. This handles double ko seki. (Back) [2] Pass-aliveness can be computed by a straightforward algorithm: https://en.wikipedia.org/wiki/Benson%27s_algorithm_(Go). Note that a slight adjustment to the algorithm presented is technically needed if multi-stone suicide is allowed. (Back) [3] Under this definition, it is possible that a region with one completely interior point is pass-alive-territory but the addition of a single stone on that interior point results in the region no longer being considered pass-alive-territory because the single stone is not a pass-alive-group. We ignore this minor "flaw" since it makes for a simpler definition and algorithmic implementation. (Back) [4] This Spight-style termination condition ensures that sending-two-returning-one-type positions will terminate, even under area scoring where the cycle does not "cost" points. (Back) [5] Under some real-life human rules, an unbounded cycle would not end the game in and of itself at exactly such a point, rather the game may be manually adjudicated as a no-result. But our goal here is to get a formalization of Japanese-like ko rules for computer self-play, so dictating a precise ending point is necessary. The requirement for no intervening passes makes absolutely sure that we do not no-resultify sending-two-returning-one style positions, even with weird unforeseen move orderings. (Back) [6] Why have two phases instead of just one? The intent is that the first phase introduces changes to the ko rules alone, allowing any positions destabilized by it to settle down. Then, the second phase additionally introduces a +1 point per move that allows players to actually begin capturing dead stones without loss of points. If both changes were introduced at once, in some cases, this leads to a highly non-intuitive "pass fight" that is absent from true Japanese rules. This can occur if a protective move becomes necessary once the ko rules change - then we may see players exchange ko threats to try to be not the second to pass and therefore to be first to play in cleanup, since being first to play in cleanup would enable making the protective move with +1 point instead of with +0 points. Introducing the ko rule and score bonus changes in separate phases eliminates this. (Back) [7] The unblock-ko action is effectively the Japanese rules's "pass for ko". We name it this way to avoid calling it a pass, since it shares little else in common with a pass with regard to the rules necessary to make cleanup work. Also, highly conveniently, an unblock-ko for a location is always mutually exclusive with a legal move for that location, which means we have no need to change the protocol for GTP or introduce new move encodings. We can continue to use the exact same 19x19 + 1 encodings in all existing protocols to represent moves. (Back) [8] This condition prevents a double ko seki from looping forever in the cleanup phase, at least in the simplest cases, in theory. It must depend on the exact grid coloring rather than be a general prohibition on continuing to unblock-ko and recapture a ko or kos over and over because if the seki is temporary such that one side can capture a surrounding group to collapse it, we must make sure capturing into the ko is not prohibited at that point. Unfortunately, as stated, this rule still allows quite a large amount of game-prolonging due to double-ko-seki, which makes it not ideal for selfplay. Is there a better formulation that is still clean to state and implement, that limits the ability of the attacker to fruitlessly cycle the double-ko-seki? (Back) [9] Unmarking non-ko-moves here avoids weirdness in certain cases involving multi-stage kos. (Back) [10] This Spight-style termination condition ensures that sending-two-returning-one-type positions will terminate, even during the second cleanup phase when the cycle no longer "costs" points. (Back) [11] The "color at the start of the second cleanup phase" condition prevents one-sided dame from granting points to the side able to fill the dame. We go ahead and have an allowance for Button Go here too. This may seem odd, since normally the intent is as a way obtain territory-scoring granularity with area-scoring, so if already using territory-scoring, why would one want such a rule? But at least when we came to implement it in KataGo, it seemed programatically no more complex (simpler, even) to just have it as an option always - it seems pretty harmless. Although I'm considering not actually training the neural net on the particular configuration of territory + button. (Back)