MCPcopy Create free account
hub / github.com/geekcomputers/Python / best_move

Function best_move

Tic-Tac-Toe Games/tic-tac-toe3.py:69–82  ·  view source on GitHub ↗

Return best move for AI.

(board: Board)

Source from the content-addressed store, hash-verified

67
68
69def best_move(board: Board) -> Optional[Tuple[int, int]]:
70 """Return best move for AI."""
71 best_val = float("-inf")
72 move: Optional[Tuple[int, int]] = None
73 for i in range(3):
74 for j in range(3):
75 if board[i][j] == " ":
76 board[i][j] = "O"
77 val = minimax(board, 0, False)
78 board[i][j] = " "
79 if val > best_val:
80 best_val = val
81 move = (i, j)
82 return move
83
84
85def make_move(row: int, col: int) -> None:

Callers 1

ai_moveFunction · 0.85

Calls 1

minimaxFunction · 0.85

Tested by

no test coverage detected