Go

environment gif

This environment is part of the classic environments. Please read that page first for general information.

Name Value
Actions Discrete
Agents 2
Parallel API Yes
Manual Control No
Action Shape Discrete(362)
Action Values Discrete(362)
Observation Shape (19, 19, 3)
Observation Values [0, 1]
Import from pettingzoo.classic import go_v4
Agents agents= ['black_0', 'white_0']

Agent Environment Cycle

environment aec diagram

Go

Go is a board game with 2 players, black and white. The black player starts by placing a black stone at an empty board intersection. The white player follows by placing a stone of their own, aiming to either surround more territory than their opponent or capture the opponent’s stones. The game ends if both players sequentially decide to pass.

Our implementation is a wrapper for MiniGo.

Arguments

Go takes two optional arguments that define the board size (int) and komi compensation points (float). The default values for the board size and komi are 19 and 7.5, respectively.

go_v4.env(board_size = 19, komi = 7.5)

board_size: The length of each size of the board.

komi: The number of points given to white to compensate it for the disadvantage inherent to moving second. 7.5 is the standard value for Chinese tournament Go, but may not be perfectly balanced.

Observation Space

The observation is a dictionary which contains an 'obs' element which is the usual RL observation described below, and an 'action_mask' which holds the legal moves, described in the Legal Actions Mask section.

The main observation shape is a function of the board size N and has a shape of (N, N, 3). The first plane, (:, :, 0), represent the stones on the board for the current player while the second plane, (:, :, 1), encodes the stones of the opponent. The third plane, (:, :, 2), is all 1 if the current player is black_0 or all 0 if the player is white_0. The state of the board is represented with the top left corner as (0, 0). For example, a (9, 9) board is

   0 1 2 3 4 5 6 7 8
 0 . . . . . . . . .  0
 1 . . . . . . . . .  1
 2 . . . . . . . . .  2
 3 . . . . . . . . .  3
 4 . . . . . . . . .  4
 5 . . . . . . . . .  5
 6 . . . . . . . . .  6
 7 . . . . . . . . .  7
 8 . . . . . . . . .  8
   0 1 2 3 4 5 6 7 8
Plane Description
0 Current Player’s stones
0: no stone, 1: stone
1 Opponent Player’s stones
0: no stone, 1: stone
2 Player
0: white, 1: black

While rendering, the board coordinate system is GTP.

The legal moves available to the current agent are found in the action_mask element of the dictionary observation. The action_mask is a binary vector where each index of the vector represents whether the action is legal or not. The action_mask will be all zeros for any agent except the one whos turn it is. Taking an illegal move ends the game with a reward of -1 for the illegally moving agent and a reward of 0 for all other agents.

Action Space

Similar to the observation space, the action space is dependent on the board size N.

Action ID Description
Place a stone on the 1st row of the board.
0: (0,0), 1: (0,1), …, N-1: (0,N-1)
Place a stone on the 2nd row of the board.
N: (1,0), N+1: (1,1), …, 2N-1: (1,N-1)
Place a stone on the Nth row of the board.
N^2-N: (N-1,0), N^2-N+1: (N-1,1), …, N^2-1: (N-1,N-1)
Pass

For example, you would use action 4 to place a stone on the board at the (0,3) location or action N^2 to pass. You can transform a non-pass action a back into its 2D (x,y) coordinate by computing (a//N, a%N) The total action space is .

Rewards

Winner Loser
+1 -1