import random

board = [[' ', ' ', ' '],

[' ', ' ', ' '],

[' ', ' ', ' ']]

z = 0

def normboard():

board = [[' ', ' ', ' '],

[' ', ' ', ' '],

[' ', ' ', ' ']]

return board

normboard()

def printboard():

print board[0][0], "|", board[0][1], "|", board[0][2]

print "___________"

print board[1][0], "|", board[1][1], "|", board[1][2]

print "___________"

print board[2][0], "|", board[2][1], "|", board[2][2]

printboard()

def emptyboard():

x = 0

if board == normboard():

x = 0

else:

x = 1

return x

def supercoolAI():

global z

y = random.randint(0, 2)

x = random.randint(0, 2)

if z % 2 != 0:

while winboard() == 0:

while board[x][y] != ' ':

board[x][y] = "o"

print printboard()

if winboard() == 1:

print "computer wins"

z += 1

supercoolAI()

def winboard():

x = 0

if emptyboard() == 1:

if board[0][0] == board[0][1] and board[0][1] == board[0][2] and board[0][0] != ' ' and board [0][1] != ' ' and board[0][2] != ' ':

x = 1

print "tic tac toe, 3 in a row"

elif board[1][0] == board[1][1] and board[1][1] == board[1][2] and board[1][0] != ' ' and board [1][1] != ' ' and board[1][2] != ' ':

x = 1

print "tic tac toe, 3 in a row"

elif board[2][0] == board[2][1] and board[2][1] == board[2][2] and board[2][0] != ' ' and board [2][1] != ' ' and board[2][2] != ' ':

x = 1

print "tic tac toe, 3 in a row"

elif board[0][0] == board[1][1] and board[1][1] == board[2][2] and board[0][0] != ' ' and board [1][1] != ' ' and board[2][2] != ' ':

x = 1

print "tic tac toe, 3 in a row"

elif board[0][2] == board[1][1] and board[1][1] == board[0][2] and board[0][2] != ' ' and board [1][1] != ' ' and board[0][2] != ' ':

x = 1

print "tic tac toe, 3 in a row"

elif board[0][0] == board[1][0] and board[1][0] == board[2][0] and board[0][0] != ' ' and board [1][0] != ' ' and board[2][0] != ' ':

x = 1

print "tic tac toe, 3 in a row"

elif board[0][1] == board[1][1] and board[1][1] == board[2][1] and board[0][1] != ' ' and board [1][1] != ' ' and board[2][1] != ' ':

x = 1

print "tic tac toe, 3 in a row"

elif board[0][2] == board[1][2] and board[1][2] == board[2][2] and board[0][2] != ' ' and board [1][2] != ' ' and board[2][2] != ' ':

x = 1

print "tic tac toe, 3 in a row"

else:

x = 0

else:

x = 0

return x

def checkboard():

global z

x = 0

if z % 2 == 0:

while winboard() == 0:

change = raw_input("enter the coordinates of your x: first row:top/middle/bottom right/middle/left")

if change == "top left":

board[0][0] = "x"

x += 1

z += 1

printboard()

elif change == "top middle":

board[0][1] = "x"

x += 1

z += 1

printboard()

elif change == "top right":

board[0][2] = "x"

x += 1

z += 1

printboard()

elif change == "middle left":

board[1][0] = "x"

x += 1

z += 1

printboard()

elif change == "middle middle":

board[1][1] = "x"

x += 1

z += 1

printboard()

elif change == "middle right":

board[1][2] = "x"

x+=1

z += 1

printboard()

elif change == "bottom left":

board[2][0] = "x"

x+=1

z += 1

printboard()

elif change == "bottom middle":

board[2][1] = "x"

x+=1

z += 1

printboard()

elif change == "bottom right":

board[2][2] = "x"

x+=1

z += 1

printboard()

z += 1

supercoolAI()