What Unbeatabot is, how the 3x3 board and unbeatable minimax AI work, and how Demo and Real Robot modes fit together.
Unbeatabot is an unbeatable Tic-Tac-Toe robot powered by a Kinova Gen3 Lite 6-DOF arm, OpenCV ArUco marker vision, ROS 2 Jazzy, and a Next.js web interface. Place your piece on the physical board (or click a square in the browser), and the arm picks up its own token and responds with an optimal move.
Two ways to run
http://localhost:8780.How Unbeatabot Works
Each turn follows a closed perception-planning-manipulation loop across three layers:
- Vision (
marker_input/camera_input): A fixed overhead webcam reads the 3x3 board usingDICT_4X4_50ArUco markers, locates spare off-board tokens on/spare_pieces, and publishes stable board reads to/board_state. - Game Engine (
game_manager): Tracks the game state machine, validates human moves on the physical board, evaluates minimax, and sequences arm pick-and-place moves. - Manipulation (
arm.py&wrist.py): Selects the closest reachable spare token, computes continuous minimum-Δj6wrist yaws, and executes safe approach, grasp, travel, and placement moves.
Board Numbering & Coordinate Layout
Squares are numbered row-by-row from 1 to 9. Row 1 2 3 sits nearest the Kinova arm base, and row 7 8 9 sits nearest the camera:
[ Kinova Arm Base ]
-y (O side) +y (X side)
+-----+-----+-----+
| 1 | 2 | 3 | <- nearest arm (x ~ 0.18 m)
+-----+-----+-----+
| 4 | 5 | 6 | <- middle row
+-----+-----+-----+
| 7 | 8 | 9 | <- nearest camera (x ~ 0.51 m)
+-----+-----+-----+
[ Camera ]Unbeatable Minimax AI
The minimax planner in unbeatabot/game.py searches all remaining legal moves and scores terminal boards with depth weighting:
score = (1 if win == me else -1) * (1 + empty_count)Because faster wins score higher and slower losses score less negatively, the robot never misses a forced win and never allows a fork. By default the human plays X (moves first) and the robot plays O; the best outcome against Unbeatabot is a draw. Launch with player:=O to play as O instead.
Demo vs. Real Robot Mode
Both modes share the same three-step flow inside /play:
| Capability | Browser Demo | Real Robot (web_bridge) |
|---|---|---|
| Hardware & ROS 2 required | None (runs in browser) | Kinova Gen3 Lite + webcam + ROS 2 |
| AI Opponent | TypeScript minimax (demo-source.ts) | ROS 2 game_manager + physical arm |
| Board Input | Click squares in browser | Physical ArUco pieces or click in /play |
| Calibration | Sample values + simulated stepping | Live /get_tool & Calibration.fit_points |
Game States & Input Modes
The ROS 2 game_manager moves through seven explicit states published as JSON on /game_state:
SETUP— Homes the arm and waits for the board to start empty.PLAYER_TURN— Waits for a valid move from/board_stateor/player_move.ROBOT_TURN— Runs minimax, picks a spare token, and places it on the target square.PICK_HELP,PLACE_HELP,BOARD_HELP— Pauses safely when a token grasp misses, a placement stalls, or a piece is moved illegally, waiting for human correction +/resume.GAME_OVER— Announces win/draw and waits for/new_game(or cleans up tokens via/board_pieces, returning O tokens first, then X).
Select the input source via the launch argument input:=: markers (recommended ArUco mode), camera (shape-only OpenCV detector), or keyboard (manual terminal entry).