Chapter 2: AI with Search Techniques and Games
Activity 2: Teach the agent realize situations when it defends against losses
Follow these steps to complete the activity:
- Create a function
player_can_win
such that it takes all moves from the board using theall_moves_from_board
function and iterates over it using a variablenext_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...