How to do it...

We proceed with the recipe as follows:

  1. We need to start by loading the necessary libraries for this script, as follows:
import tensorflow as tf 
import matplotlib.pyplot as plt 
import csv 
import random 
import numpy as np 
import random 
  1. Next, we declare the following batch size for training our model:
batch_size = 50 
  1. To make visualizing the boards a bit easier, we will create a function that outputs Tic Tac Toe boards with Xs and Os. This is done with the following code:
 def print_board(board):    symbols = ['O', ' ', 'X']    board_plus1 = [int(x) + 1 for x in board]    board_line1 = ' {} | {} | {}'.format(symbols[board_plus1[0]],                                         symbols[board_plus1[1]],                                         symbols[board_plus1[2]]) board_line2 = ' {} | {} | {}'.format(symbols[board_plus1[3]], ...

Get TensorFlow Machine Learning Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.