Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Page of 2 ZOOM import random import os . path import json random.seed ( ) def draw _ board ( board ) : # develop

Page
of 2
ZOOM
import random
import os.path
import json
random.seed()
def draw_board(board):
# develop code to draw the board
pass
def welcome(board):
# prints the welcome message
# display the board by calling draw_board(board)
pass
def initialise_board(board):
# develop code to set all elements of the board to one space ''
return board
def get_player_move(board):
# develop code to ask the user for the cell to put the X in,
# and return row and col
return row, col
def choose_computer_move(board):
# develop code to let the computer chose a cell to put a nought in
# and return row and col
return row, col
def check_for_win(board, mark):
# develop code to check if either the player or the computer has won
# return True if someone won, False otherwise
return False
def check_for_draw(board):
# develop cope to check if all cells are occupied
# return True if it is, False otherwise
return True
def play_game(board):
# develop code to play the game
# star with a call to the initialise_board(board) function to set
# the board cells to all single spaces ''
# then draw the board
# then in a loop, get the player move, update and draw the board
# check if the player has won by calling check_for_win(board, mark),
# if so, return 1 for the score
# if not check for a draw by calling check_for_draw(board)
# if drawn, return 0 for the score
# if not, then call choose_computer_move(board)
# to choose a move for the computer
# update and draw the board
# check if the computer has won by calling check_for_win(board, mark),
# if so, return -1 for the score
# if not check for a draw by calling check_for_draw(board)
# if drawn, return 0 for the score
#repeat the loop
return 0
def menu():
# get user input of either '1','2','3' or 'q'
# 1- Play the game
# 2- Save score in file 'leaderboard.txt'
# 3- Load and display the scores from the 'leaderboard.txt'
# q - End the program
return choice
def load_scores():
# develop code to load the leaderboard scores
# from the file 'leaderboard.txt'
# return the scores in a Python dictionary
# with the player names as key and the scores as values
# return the dictionary in leaders
return leaders
def save_score(score):
# develop code to ask the player for their name
# and then save the current score to the file 'leaderboard.txt'
return
def display_leaderboard(leaders):
# develop code to display the leaderboard scores
# passed in the Python dictionary parameter leader
pass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions