This is NOT the latest version of these rules. The latest rules can be found here.
This page describes the full rigorous rules implemented by KataGo. These rules are supported in KataGo version 1.3 and later.
A hope also is that this document can serve as a reference for anyone to implement any subset of such rules themselves - including a rigorous nearly-Japanese rules that bots can use for self-play or for competitive matches completely without need for outside adjudication or dispute resolution or any other protocol besides just the bots making ordinary plays.
I believe the nearly-Japanese rules should correctly handle a wide variety of details, so long as both players play to rationally maximize their score. For example:
Bent-four-in-the-corner will die regardless of external ko threats.
No territory in seki, including no territory for one-sided dame (a common quirk of simpler territory rules).
Double-ko-seki and thousand-year-ko are sekis, double ko death is a death.
One should finish a direct ko rather than leave it open, even if there are enough ko threats to pass and still leave it open, but multi-step-ko need not be finished.
A known difference is with three-points-without-capturing, and a few other exotic rules beasts are also known that will cause a difference, but these should be very very rare.
Updated from Version 0 are some details of the cleanup phase ko rules and some of the endnotes and commentary. The changes were to get slightly more consistency with Japanese rules in some very rare cases, probably less than 1 in 1000 games. Unless a major flaw is discovered, these rules should be considered reasonably stable and KataGo will be doing a full training run with them.
Parameters
Click the buttons or individually uncheck some of the boxes to hide parts of the logic for rules you don't care about.
NOTE: Some online servers that claim to implement certain rules might actually differ. For example, OGS's implementation of Chinese rules uses positional superko, which differs from actual practice in Chinese Go tournaments that normally use just a simple ko rule. If you're implementing a bot to run on a server, always look up the details!
X,Y: Integers indicating the board size.
Komi: Integer or half-integer indicating compensation given to White for going second.
TaxRule: Minor adjustments to scoring rule, indicating what, if any, empty points may not be scored.
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)
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).
WhiteHandicapBonus: How many bonus points white receives during handicap games when black gets N stones. KataGo supports handicap games, but for simplicity, this rules document does NOT describe them. These checkboxes are included merely to provide a convenience reference as how this quirk of handicap game scoring differs between rulesets.
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.
Rules
Basic Definitions
Go is played on an X by Y rectangular grid of points by two opposing players, Black and White.
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.
Points are adjacent/bordering if they are horizontally or vertically touching.
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.
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.
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
A liberty of a black or white region is any empty point that borders it.
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.
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.
For any regions emptied by the steps of resolving captures, we say that the move captures those regions.
Additional Definitions
An empty region that borders both black and white is a dame region.
A black or white region is in atari if it is has exactly one liberty.
A {maximal-non-white, maximal-non-black} region is a {black, white} independent-life-region if it contains at least one {black,white} point and does NOT contain any dame regions or any regions in atari.[1]
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]
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:
(if Button is NotUsed): There are 2 consecutive passes.
(if Button is Used): There are 2 consecutive passes, ignoring the first pass of the game.
(if KoRule is Simple): Additionally the game also ends if:
A player passes from a state that the player has already passed from once before.[4]
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]
(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.
Although handicap games are not a focus of these rules, see [11] for some notes about handicap game scoring.
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
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.
In addition to the grid coloring, points on the grid may be marked as ko-recapture-blocked.
The state during cleanup phases consists of the grid coloring together with the ko-recapture-blocked status of all points 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-recapture 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...
Does NOT capture any region containing a point marked as ko-recapture-blocked.
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 colored by the move as ko-recapture-blocked.
Then, followed by unmarking all ko-recapture-blocked points whose grid color is empty.
An unblock-ko-recapture action consists of a player choosing a ko-move for that player that would capture a region containing a point marked as ko-recapture-blocked, and removing that mark.
Cleanup Phase Ending and Scoring
A cleanup phase ends after any of:
There are two consecutive passes.
OR a player passes from a state that the player has already passed from once before during the same phase.[9]
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-recapture-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 [10] for some remarks about the scoring.
Although handicap games are not a focus of these rules, see [11] for some notes about handicap game 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-like positions will terminate, even under area scoring where the cycle does not "cost" points. It also cuts it shorter under territory scoring, so that a badly behaving bot doesn't lose by ~infinity.
The approach taken taken by many Chinese tournaments is to simply prohibit sending-two-returning-one. (Chinese written rules appear to say positional superko, but this written rule is often not used for real tournaments). This would also be easy to implement and KataGo could easily choose to support it in the future, since for all practical purposes a neural net trained under simple ko rules should work fine without modification in an engine that bans sending-two-returning-one.
However, there is also sending-three-returning-one - and perhaps there are others messy cases too, that one would imagine professional players balking at allowing despite not having formally listed and prohibited them ahead of time in written rules. Spight's condition is a much cleaner way to handle them for now.
Some computer tournament rules handle this by simply declaring long cycles to be draws/wins/losses depending on number of stones captured. It would be easy trivial to support these too in the future if needed and probably would not in practice require retraining a neural net either. But for now, no actual human rulesets use this rule, and even in the computer world, positional or situational superko are often more popular.
(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 issue.
(Back)[7]
The unblock-ko-recapture 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-recapture for a ko-move 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 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]
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)[10]
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, and formulating it this way makes for more natural extension to Coupon Go if desired, which *does* make sense in territory scoring. KataGo for now does NOT actually support territory + button though.
(Back)[11]
A number of human rulesets allow for Black to begin with N >= 2 stones on the board when playing a game between two differently-skilled players, with these stones being placed in a ruleset-specified way, and with White making the first actual game move instead of Black. For various reasons, during handicap games many of these rulesets give White bonus points based on N, additionally on top of any komi or other settings. Some rulesets give 0 points, some give N-1 points, and some give N points.
(Back)