QUESTION IMAGE
Question
- given the following code snippet for the tic tac toe game, which part of the ai computer algorithm is executed? (click here to see the complete program)
- if isspacefree(board, 5):
return 5
- for i in range(1, 10):
copy = getboardcopy(board)
if isspacefree(copy, i):
makemove(copy, playerletter, i)
if iswinner(copy, playerletter):
return i
- for i in range(1, 10):
copy = getboardcopy(board)
if isspacefree(copy, i):
makemove(copy, computerletter, i)
if iswinner(copy, computerletter):
return i
- return
chooserandommovefromlist(board, 2, 4, 6, 8)
- move =
chooserandommovefromlist(board, 1, 3, 7, 9)
if move != none:
return move
a. try to take one of the corners, if they are free
b. check if the player could win on the next move, and block that move.
c. check if computer can win in the next move.
d. move on one of the sides.
e. try to take the center, if it is free.
The first if statement checks if the center space (index 5 in a 1 - 9 numbering for a Tic - Tac - Toe board) is free and if so, returns 5, which means trying to take the center if it is free.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
e. Try to take the center, if it is free