This environment is part of the classic environments. Please read that page first for general information.
|Observation Shape||(6, 7, 2)|
Connect Four is a 2-player turn based game, where players must connect four of their tokens vertically, horizontally or diagonally. The players drop their respective token in a column of a standing grid, where each token will fall until it reaches the bottom of the column or reaches an existing token. Players cannot place a token in a full column, and the game ends when either a player has made a sequence of 4 tokens, or when all 7 columns have been filled.
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 space is 2 planes of a 6x7 grid. Each plane represents a specific agent’s tokens, and each location in the grid represents the placement of the corresponding agent’s token. 1 indicates that the agent has a token placed in that cell, and 0 indicates they do not have a token in that cell. A 0 means that either the cell is empty, or the other agent has a token in that cell.
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.
The action space is the set of integers from 0 to 6 (inclusive), where the action represents which column a token should be dropped in.
If an agent successfully connects four of their tokens, they will be rewarded 1 point. At the same time, the opponent agent will be awarded -1 points. If the game ends in a draw, both players are rewarded 0.