Question: Can you help me get this python code to work please. Also please post the complete running code. Will thumbs up, Thank you from ezgraphics
Can you help me get this python code to work please. Also please post the complete running code. Will thumbs up, Thank you
from ezgraphics import GraphicsWindow
win = GraphicsWindow(800, 800) win.setTitle("Tic-Tac-Toe") canvas = win.canvas()
side = (int)(800 / 3)
x = [] for i in range(9): value = (i % 3) * side x.append(value) print(x)
y = [] for i in range(9): if i < 3: y.append(0) elif i < 6: y.append(side) else: y.append(side * 2) print(y)
boxXY = [] for i in range(9): boxXY.append([x[i], y[i], 0]) # We will use 0 to represent empty, 1 for X and -1 for O. print(boxXY)
def ticTacToeBoard(): for i in range(9): canvas.drawRectangle(x[i], y[i], side, side) canvas.drawText(x[i] + 10, y[i] + 10, i + 1)
def drawO(x, y, size): canvas.drawOval(x, y, size, size)
def drawX(x, y): canvas.drawLine(x, y, x + 100, y + 100) canvas.drawLine(x, y + 100, x + 100, y)
def findBox(): box = -1 side = (int)(800 / 3) while (box == -1): boxTuple = win.getMouse() # get the XY coordinate
def findBox(): box = -1 side = (int)(800 / 3) while (box == -1): boxTuple = win.getMouse() # get the XY coordinate of the mouse. mouseX = boxTuple[0] mouseY = boxTuple[1] for i in range(9): if (x[i] < mouseX and x[i] + side > mouseX): if (y[i] < mouseY and y[i] + side > mouseY): box = i + 1 if boxXY[box][2] != 0: # if the box is not empty box = -1 # stay in the loop continue # go to the next iteration return (box)
while True: oNumber = computerPlayTicTacToeSmart(): playO(oNumber) if TicTacToeOver(): # print("Game is over") break xNumber = findBox() playX(int(xNumber)) if TicTacToeOver(): # print("Game is over") break else: # print("Keep going!") continue elif playOption == "4":
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
