View the step-by-step solution to:

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

This tic/tac/toe code below must have an AI to compete against the user and it must also have a function that check when tic/tac/toe has game over or not depending on who gets the three-in-a-row pattern like the traditional tic/tac/toe game.And the "clicked" function that controls the user moves must return a BOOL. This was created using Python.

This tic/tac/toe game must be fixed. Refer to the attachments and the prompt attached.

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.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.down()
turtle.forward(226)
turtle.up()
turtle.goto(x + 180, y - 20)
turtle.down()
turtle.forward(226)
turtle.up()

elif pos == "O":
#Draw O
turtle.up()
turtle.goto(x + 100, y - 180)
turtle.down()
turtle.circle(80)
turtle.up()
x += 200
if x > 100:
x = -300
y -= 200

def clicked(board, x, y):
# this function is not entirely correct, construct the function using the three parameters so it can return a BOOL
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
```

﻿

def check_game_over(board):
signature: listCstr) —&gt; 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) —&gt; 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

def clickhandler(x, y):
signature: int, int -&gt; 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: () -&gt; 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()

def do_user_move(board, x, y):
signature: list(str), int, int —&gt; bool
The current state of the board is given as
a parameter, as well as the x,y screen coordinate
indicating where the user clicked. This function
should update the board state variable
with an 0 in the corresponding position. Your
code will need to translate the screen coordinate
(a pixel position where the user clicked) into the
corresponding board position (a value between 0 and
8 inclusive, identifying one of the 9 board positions).
The function returns a bool, indicating if
the operation was successful: if the user
clicks on a position that is already occupied
or outside of the board area, the move is
invalid, and the function should return False,
otherise True. print(&quot;user clicked at
pass # your code here +str(x)+&quot;,&quot;+str(y))

### 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