Tic-tac-toe minimax helper. Always available as
game.ticBestMove — no
use required. Optional
use tic_ai; loads
lib/tic_ai.py, a thin shim that
re-registers the same API for demos. For realtime 2D/3D windows and
shaders, use use play; instead
(see play library).
#comment: board is a length-9 list; empty cells are "" (or your empty marker); #comment: ai / hu are the marks for the computer and human (e.g. "X", "O"); move.setVar(game.ticBestMove(board, "O", "X")); print.number(move);
game.ticBestMove(board, ai, hu) —
optimal minimax move (0–8), or -1 if none.
game.ticFastestWinMove(board, ai, hu) —
minimax that prefers the fastest forced win.
game.ticLoseMove(board, ai, hu) —
inverted minimax that tries to lose to the human.
Full interactive example:
examples/tic_tac_toe.spl.
Implementation: interpreter game namespace;
optional lib/tic_ai.py