1. Introduction to Artificial Intelligence
Activity 1.01: Generating All Possible Sequences of Steps in a Tic-Tac-Toe Game
Solution:
The following steps will help you to complete this activity:
- Open a new Jupyter Notebook file.
- Reuse the function codes of Steps 2–9 from the previous, Exercise 1.02, Creating an AI with Random Behavior for the Tic-Tac-Toe Game.
- Create a function that maps the
all_moves_from_board_list
function to each element of a list of boards. This way, we will have all of the nodes of a decision tree in each depth:def all_moves_from_board_list(board_list, sign): Â Â Â Â move_list = [] Â Â Â Â for board in board_list: Â Â Â Â Â Â Â Â move_list.extend(all_moves_from_board(board, sign)) Â Â Â Â return move_list
In the preceding code snippet, we have defined the
all_moves_from_board
function, which will enumerate all the possible moves from the board and add the...