Connect4 Environment#
A classic Connect Four board game environment for training agents on turn-based strategy with a 6×7 grid. Players alternate dropping pieces into columns, aiming to connect four in a row horizontally, vertically, or diagonally.
Quick Start#
import asyncio
from connect4_env import Connect4Action, Connect4Env
async def main():
async with Connect4Env(base_url="http://localhost:8000") as client:
obs = await client.reset()
print(f"Board: {obs.board}")
print(f"Legal moves: {obs.legal_actions}")
# Drop a piece in column 3
result = await client.step(Connect4Action(column=3))
print(f"Reward: {result.reward}, Done: {result.done}")
asyncio.run(main())
Action Space#
Field |
Type |
Description |
|---|---|---|
|
|
Column index (0–6) where the piece will be dropped |
Invalid moves (out-of-range or full column) result in a reward of -1 and end the episode.
Observation Space#
Field |
Type |
Description |
|---|---|---|
|
|
6×7 grid — |
|
|
Column indices that are valid moves |
Rewards#
Outcome |
Reward |
|---|---|
Win (4 in a row) |
|
Draw (board full) |
|
Invalid move |
|
Otherwise |
|
State#
Field |
Type |
Description |
|---|---|---|
|
|
Unique ID for the current game |
|
|
Current board state |
|
|
Whose turn it is ( |
|
|
Number of steps taken |