Follow these steps to complete the activity:
Create a function player_can_win such that it takes all moves from the board using the all_moves_from_board function and iterates over it using a variable next_move. On each iteration, it checks if the game can be won by the sign, then it return true else false.
def player_can_win(board, sign): next_moves = all_moves_from_board(board, sign) for next_move in next_moves: if game_won_by(next_move) == sign: return True return False
We will extend the AI move such that it prefers making safe moves. A move is safe if the opponent cannot win the game in the next step.
def ai_move(board): new_boards = all_moves_from_board(board, AI_SIGN) for new_board in new_boards: if game_won_by(new_board) == AI_SIGN: return new_board safe_moves = [] for new_board in new_boards: ...