Based on the half-written tic/tac toe game code below. Construct code for the do_computer_move function in the
Question:
Based on the half-written tic/tac toe game code below. Construct code for the "do_computer_move" function in the attachments. Follow what the algorithm and and signature says. Make sure the computer controls the game piece, "O". Same goes for the "check_game_over" function in the attachments. Lastly, the "user_clicks" functions presented in the code below must be put inside the "do_user_move" function in the attachments and it must return a bool. In this function, make sure the user still controls the game piece, "X". For all functions, it must follow the signature and algorithm stated.
Lastly, all the functions must correspond to the function calls in the "clickhandler" function and the "main" function that runs the entire game in the attachments . Use the time module, random module, and turtle module wherever needed. Please make sure the turtle can go fast, especially when the user clicks on the board to make their move and when the computer makes its move. But do not use turtle.speed as it is inside the prohibited methods section. The "main" function provided in the attachments uses turtle.tracer to make it go faster. Everything must be in the appropriate functions in the attachments. Do NOT create your own functions.
Prohibited methods: These are inadequate with the code already written at the bottom:
turtle.speed
turtle.pen() or turtle.Turtle
turtle.screen or turtle.getscreen
turtle.shape, turtle.shapsize, turtle.resizemode, turtle.turtlesize
tkinter or any other built-in functions besides turtle, time or random
Here is my code:
import turtleimport timeimport random pieces = ["_", "_", "_", "_", "_", "_", "_", "_", "_"] turn = "X" def drawgame(brd): # draw board turtle.setup(600, 600) turtle.bgcolor("silver") turtle.color("white") turtle.hideturtle() turtle.speed('fastest') turtle.width(10) turtle.up() # Horizontal bars turtle.goto(-300, 100) turtle.down() turtle.forward(600) turtle.up() turtle.goto(-300, -100) turtle.down() turtle.forward(600) turtle.up() # Vertical bars turtle.goto(-100, 300) turtle.setheading(-90) turtle.down() turtle.forward(600) turtle.up() turtle.goto(100, 300) turtle.down() turtle.forward(600) turtle.up() turtle.color("blue") x, y = -300, 300 for pos in pieces: if pos == "X": # Draw X turtle.up() turtle.goto(x + 20, y - 20) turtle.setheading(-45) turtle.down() turtle.forward(226) turtle.up() turtle.goto(x + 180, y - 20) turtle.setheading(-135) turtle.down() turtle.forward(226) turtle.up() elif pos == "O": #Draw O turtle.up() turtle.goto(x + 100, y - 180) turtle.setheading(0) turtle.down() turtle.circle(80) turtle.up() x += 200 if x > 100: x = -300 y -= 200 def clicked(x, y): global turn, pieces turtle.onscreenclick(None) # disabling handler when inside handler column = (x + 300) // 200 row = (y - 300) // -200 square = int(row * 3 + column) print("User clicked ", x, ",", y, " at square ", square) if pieces[square] == "_": pieces[square] = turn if turn == "X": turn = "O" else: turn = "X" drawgame(pieces) else: print("That square is already taken") turtle.onscreenclick(clicked)
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill