Returns the linear cell index of the AI's chosen move using depth-limited
negamax with alpha-beta pruning. At difficulty >= 1, an immediate winning
move is always taken and an immediate opponent threat is always blocked.
Details
Tie-breaking among moves with equal evaluation is deterministic (lowest linear index wins).
Note: search is exponential in depth and runs in pure R; depth 4 may take
several seconds on a 256-cell board. An optional cooperative time budget
searches successively deeper levels and returns the last fully completed
level. If none completes, the lowest legal cell is returned. Immediate wins
and blocks are checked first, including with a zero budget. Checks occur
between search operations; scheduling and a single operation can exceed the
requested elapsed time. This is not a hard real-time limit.
Examples
tsr_ai_move(tsr_new_board(), difficulty = 1L)
#> [1] 1
# \donttest{
tsr_ai_move(tsr_new_board(), difficulty = 2L)
#> [1] 1
# }