A MATLAB implementation of strategy-free robot board games using Monte Carlo simulation for move evaluation.
This repository contains a collection of classic board games where AI players use Monte Carlo methods to make decisions. Instead of implementing complex game strategies, the robots evaluate potential moves by simulating thousands of random games and selecting the move with the highest probability of winning or drawing.
- Connect Four - Classic 4-in-a-row on a 6x7 grid
- Connect El - Variant requiring 4 corners of a rectangle
- Connect Tee - T-shaped victory condition
- Four Corners - Connect the four corners of the board
- Tic-Tac-Toe - Traditional 3x3 grid
- Oxo - Reverse tic-tac-toe where creating "OXO" pattern wins
- Reversi - Classic piece-flipping strategy game
- Open MATLAB and navigate to the repository directory
- Add the toolbox to your path:
addpath('toolbox') addpath('toolbox/games')
- Get started with the interactive tutorial:
gettingStarted
- Or try a demo:
% Bot vs Bot Connect Four run('demos/connectfour_BotVsBot.m') % Human vs Bot Tic-Tac-Toe run('demos/tictactoe_PlayerVsBot.m')
The Monte Carlo approach evaluates each possible move by:
- Making the move on a copy of the current board
- Playing N random games from that position
- Counting wins, losses, and draws
- Selecting the move that maximizes (wins + draws)
Example usage:
game = ConnectFour;
botMoves(game, 1000); % Bot makes move after 1000 simulations
- Game Classes: Each game inherits from
FourGameBase
orhandle
- Bot Engine:
botMoves()
function handles Monte Carlo evaluation - Interactive Play:
iMove()
helper for human moves - Visualization: Real-time board display with move suggestions
Run the comprehensive test suite:
cd tests
run('RunAllTests.m')
Or run individual test classes:
runtests('TicTacToeTests')
Read the original blog post: Robot Game Playing in MATLAB