View the step-by-step solution to:

def check_game_over(board): signature: listCstr) > bool Given the current state of the board, determine if the game is over, by checking for a...

Please help me solve the prompt in the attachments and the other functions in the attachments can only be used to complete the tic/tac/toe code.




PROMPT.JPG


Here is my code:


import turtle
import time
import 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(board, 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)

def computer_AI(board):
    #check signature in attachments for "computer move" function then based on it, construct this function

def gameover(board):
    #check signature in attachments for "check_game_over" function then based on it, construct this function

def handler(x, y):
    #use the code from "clickhandler" function in the attachments

def main():
    #use the code from "main" function in the attachments

Clickhandler function and Main function.jpgCheck game over function and computer move function.PNG

Final output example part 2.JPGFinal output example.JPG

Check game over function and computer move function.PNG

def check_game_over(board):
signature: listCstr) —> bool
Given the current state of the board, determine
if the game is over, by checking for
a three—in—a—row pattern in horizontal,
vertical, or diagonal lines; and also if the
game has reached a stalemate, achieved when
the board is full and no further move is possible.
If there is a winner or if there is a stalemante, display
an appropriate message to the user and clear the board
in preparation for the next round. If the game is over,
return True, otherwise False. II II II pass # your code here def do_computer_move(board):
signature: listCstr) —> NoneType
Given a list representing the state of the board,
select a position for the computer's move and
update the board with an X in an appropriate
position. The algorithm for selecting the
computer's move shall be as Follows: if it is
possible for the computer to win in one move,
it must do so. If the human player is able
to win in the next move, the computer must
try to block it. Otherwise, the computer's
next move may be any random, valid position
(selected with the random.randint function). II II II pass # your code here

Clickhandler function and Main function.jpg

def clickhandler(x, y):
signature: int, int -> NoneType
This function is called by turtle in response
to a user click. The parameters are the screen
coordinates indicating where the click happened.
The function will call other functions. You do not
need to modify this function, but you do need
to understand it.
if do_user_move(the_board,x,y):
draw_board(the_board)
if not check_game_over(the_board):
do_computer_move(the_board)
draw_board(the_board)
check_game_over(the_board) def main():
signature: () -> NoneType
Runs the tic-tac-toe game. You shouldn't
need to modify this function.
turtle.tracer(0,0)
turtle.hideturtle()
turtle.onscreenclickCclickhandler)
draw_board(the_board)
turtle.mainloop() main()

Final output example part 2.JPG

Final output example.JPG

PROMPT.JPG

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question