Implementing a Python Tic-Tac-Toe game
Let's build a basic implementation of Tic-Tac-Toe so we can see what an implementation of the min-max algorithm looks like. If you do not feel like copying all of this, you can find the full code in the GitHub repository https://github.com/DanielSlater/PythonDeepLearningSamples in the tic_tac_toe.py
file.
In the game board, we will be represented by a 3 x 3 tuple of integers. Tuples are used instead of lists so that later on, we can get equality between matching board states. In this case, 0 represents a square that has not been played in. The two players will be marked 1 and -1. If player one makes a move in a square, that square will be marked with their number. So here we go:
def new_board(): return ((0,0,0), ...
Get Python Deep Learning now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.