Introduction

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

You can play immediately in Browser Demo mode with zero robot hardware, or connect to the real Kinova Gen3 Lite over the local ROS 2 bridge on 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 using DICT_4X4_50 ArUco 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-Δj6 wrist 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:

Board orientation (top-down view)
            [ 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:

unbeatabot/game.py
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:

CapabilityBrowser DemoReal Robot (web_bridge)
Hardware & ROS 2 requiredNone (runs in browser)Kinova Gen3 Lite + webcam + ROS 2
AI OpponentTypeScript minimax (demo-source.ts)ROS 2 game_manager + physical arm
Board InputClick squares in browserPhysical ArUco pieces or click in /play
CalibrationSample values + simulated steppingLive /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_state or /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).

Explore the Docs

Unbeatabot — an EECS 4421 project. Layout based on Animate UI. Source on GitHub.