Tech With Tim Logo
Go back

Learn how to create Tic Tac Toe in python using a simple AI.

Tic Tac Toe

Before we start coding I figured I’d give a quick summary of the game and talk about how I am going to approach coding it. First of all we are going to assume that X’s always go first, letting the user make the first move. We will get input from the console with a number 1-9. Where each number represents a different number in the grid (top left is 1, bottom right is 9). Once the user moves the computer will automatically decide on it’s move and make it. I am going to be using one main game loop that calls a few different functions. Each heading of this text based tutorial will likely tell you which function is being completed. The functions we need to code are seen below.

def insertBoard(letter, pos):
    pass

def spaceIsFree(pos):
    pass

def isWinner(bo, le):
    pass

def playerMove():
    pass

def selectRandom(li):
    pass
    
def compMove():
    pass
    
def isBoardFull(board):
    pass

def printBoard():
    pass

def main():
    pass
Design & Development by Ibezio Logo