Introduction
Connect Four is a game where two players alternate turns dropping colored discs into a vertical grid. Each player uses a different color (usually red or yellow), and the objective of the game is to be the first player to get four discs in a row.
import numpy as np
import random
from kaggle_environments import make,envaluate
#create the game environment
env = make('connectx')
# TWO random agents play one game round
env.run([my_agent, 'random'])
# show the game
env.render(model='ipython')
The "random"
agent selects (uniformly) at random from the set of valid moves. In Connect Four, a move is considered valid if there's still space in the column to place a disc (i.e., if the board has seven rows, the column has fewer than seven discs).
In the code cell below, this agent plays one game round against a copy of itself.
Defining agents
the agent is always implemented as a Python function that accepts two agrumwnts:obs and config
- obs : contains two pieces of information
obs.board - the game board(a python list with one item for each grid location)
obs.mark - the piece