Question
the play_game.py file code is below and and it the file you need to run to use your module noughtsandcrosses.py from noughtsandcrosses import * def
the play_game.py file code is below and and it the file you need to run to use your module "noughtsandcrosses.py
from noughtsandcrosses import * def main(): board = [ ['1','2','3'],\ ['4','5','6'],\ ['7','8','9']] welcome(board) total_score = 0 while True: choice = menu() if choice == '1': score = play_game(board) total_score += score print('Your current score is:',total_score) if choice == '2': save_score(total_score) if choice == '3': leader_board = load_scores() display_leaderboard(leader_board) if choice == 'q': print('Thank you for playing the "Unbeatable Noughts and Crosses" game.') print('Good bye') return # Program execution begins here if __name__ == '__main__': main()
noughtsandcrosses.py file code is below this is the file you need to complete
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
lask Your task is to develop a program that play the classic game of Noughts and Crosses, or TicTac-Toe. Overview: Noughts and Crosses is a simple classic game for 2 players, played on a three-by-three grid, in which players take it in turns to place their mark, either a nought O or a cross X, in a cell of the grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner. For example: To start the game, the convention is that X plays first. For the program you are going to develop, a human player plays against the computer, and the human player goes first with the cross X. Getting Started: Start by download the two Python files play_game.py and noughtsandcrosses.py. The file play_game.py is the main game program and it is already complete and it imports the noughtsandcrosses.py module in order to play the game. Your task is to fully complete the module noughtsandcrosses.py. As with the previous Coursework, a number of incomplete functions are given to you and you must use these as they are. You must not change their arguments or the way they return values. Requirements: The requirement for each function is detailed in template file noughtsandcrosses.py and also explained below: def draw_board(board) (2\%) You are required to develop code to draw the noughts and crosses board, for example: def welcome(board) (2\%) You are required to develop code to print the welcome message and display the board by calling draw_board(board). For example: Welcome to the "Unbeatable Noughts and Crosses" game. The board layout is show below: When prompted, enter the number corresponding to the square you want. def initialise_board(board) (2%) You are required to develop code to set all elements of the board to one space ' def get_player_move(board) (5\%) You are required to ask the user for the cell to put the X in, and return row and col 4Chooseyoursquare:15726839:1 The player has to input a valid cell. def choose_computer_move(board) (25\%) You are required to develop code to let the computer chose a cell to put a nought in and return row and col def check_for_win(board, mark) (5\%) You are required to develop code to check if either the player or the computer has won return True if someone won, False otherwise def check_for_draw(board) (4\%) You are required to develop cope to check if all cells are occupied return True if it is, False otherwise You are required to develop code to play the game. 1. Start with a call to the initialise_board(board) function to set the board cells to all single spaces' ' 2. Then draw the board 3. Then in a loop, get the player move 4. Update and draw the board 5. Check if the player has won by calling check_for_win(board, mark), if so, return 1 for the score. 6. If not check for a draw by calling check_for_draw(board). 7. If drawn, return 0 for the score 8. If not, then call choose_computer_move(board) to choose a move for the computer 9. Update and draw the board 10. Check if the computer has won by calling check_for_win(board, mark), 11. If so, return 1 for the score 12. If not check for a draw by calling check_for_draw(board) 13. If drawn, return 0 for the score 14. Repeat the loop from (3) You are required to develop code to get user input of either '1', '2', '3' or ' q '. For example: Enter one of the following options: 1 - Play the game 2 - Save your score in the leaderboard 3 - Load and display the leaderboard q - End the program 1,2,3 or q ? 1 defload_scoreso (10%) You are required to develop code to load the leaderboard scores from the file 'leaderboard.txt'. The function has to return the scores in a Python dictionary, with the player names as key and the scores as values. def save_score(score) (10%) You are required to develop code to ask the player for their name and then save the current score to the file 'leaderboard.txt' def display_leaderboard(leaders) (5\%) You are required to develop code to display the leaderboard scores passed in the Python dictionary parameter "leaderStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started