1. Homepage
  2. Programming
  3. [2022] MCD4710 Introduction to Algorithms and Programming Assignment 2: Tic Tac Toe

[2022] MCD4710 Introduction to Algorithms and Programming Assignment 2: Tic Tac Toe

Engage in a Conversation
MCD4710Introduction to Algorithms and ProgrammingAustraliaMonash CollegePython

MCD4710 - Introduction to Algorithms and Programming Assignment 2 (10%) CourseNana.COM

Due: Thursday, September 1, 2022, 11:55 pm - Week 10 CourseNana.COM

Objectives CourseNana.COM

The objectives of this assignment are: CourseNana.COM

●  To gain experience in designing algorithms for a given problem description and implementing those algorithms in Python. CourseNana.COM

●  To demonstrate your understanding on: CourseNana.COM

o Implementing problem solving strategies
o Recognizing the relationship between a problem description and program design o Decomposing code into functions in Python. CourseNana.COM

Submission Procedure CourseNana.COM

Your assignment will not be accepted unless it meets these requirements: CourseNana.COM

  1. Your name and student ID must be included at the start of every file in your submission.
  2. Save your file(s) into a zip file called YourStudentID.zip
  3. Submit your zip file containing your entire submission to Moodle.

Late submission will have 5% deduction of the total assignment marks per day (including weekends). Assignments submitted 7 days after the due date will not be accepted. CourseNana.COM

Assignment code interview CourseNana.COM

Each student will be interviewed during a lab session regarding their submission to gauge your personal understanding of your Assignment code. The purpose of this is to ensure that you have completed the code yourself and that you understand the code submitted. Your assignment mark will be scaled according to the responses provided. CourseNana.COM

Task 1: Initialize the board CourseNana.COM

Implement a function named init_board() which creates a 3x3 board. Fill in each cell with a hyphen, indicating that the cells are all empty. Implement the board as a table (ie. a list of lists) in python. This function should return the table (i.e. list of lists). It should not print the board. CourseNana.COM

Input: No input taken
Output: A table that represents the 3x3 tic-tac-toe board with all the cells filled with a hyphen
CourseNana.COM

For example: CourseNana.COM

>>> board = init_board()
>>> board
[['-', '-', '-'], ['-', '-', '-'], ['-', '-', '-']]
CourseNana.COM

Task 2: Print board CourseNana.COM

Write a function named print_board(board)that prints the given board in the format shown in the example below. CourseNana.COM

Input: The current status of the board Output: Prints the current board to the screen CourseNana.COM

For example: CourseNana.COM

>>> board = init_board() CourseNana.COM

>>> print_board(board) ------------- |-|-|-| ------------- |-|-|-| ------------- |-|-|-| ------------- CourseNana.COM

Task 3: Check if the board is filled CourseNana.COM

Write a function named is_filled(board)that returns True if the board is fully filled with X’s and/or O’s and False otherwise. CourseNana.COM

Input: The current status of the board
Output: True if the board is filled, False otherwise
CourseNana.COM

For example: CourseNana.COM

>>> board = init_board() >>> is_filled(board) CourseNana.COM

False
>>> test_board = [['X','O','X'],['O','X','O'],['X','O','X']] >>> is_filled(test_board)
True
CourseNana.COM

Task 4: Check if a player has won CourseNana.COM

Write a function named player_won(board)that checks if one of the players has won. If a player has won, the function should display on the screen which player has won and return True. If none of the players has won the function should return False. CourseNana.COM

Note: You should consider decomposition in this task. CourseNana.COM

Input: The current status of the board
Output: True if the board is filled, False otherwise
CourseNana.COM

For example: CourseNana.COM

>>> test_board = [['X','O','X'],['O','X','O'],['X','O','X']] >>> player_won(test_board)
Congrats!! You win!
True
CourseNana.COM

>>> test_board = [['O','X','O'],['X','O','X'],['O','X','O']] >>> player_won(test_board)
I win! Nice try!
True
CourseNana.COM

>>> test_board = [['X','-','O'],['X','-','O'],['X','-','-']] >>> player_won(test_board)
Congrats!! You win!
True
CourseNana.COM

>>> test_board = [['O','O','X'],['X','X','O'],['O','X','O']] >>> player_won(test_board)
False
CourseNana.COM

Task 5: Update the board CourseNana.COM

Write a function named update_board(board,row,col,player)that places the next ‘X’ or ‘O’ on the board. You need to check if the selected cell is empty before updating the board. If the chosen cell is not empty the function should return False. If the update was successful, the function should return True. CourseNana.COM

Input: The current status of the board, the row, column and the player (‘X’ or ‘O’) for the next move. Output: True if the board is successfully updated, False otherwise. CourseNana.COM

For example: CourseNana.COM

>>> test_board = [['X','O','-'],['-','X','-'],['-','O','-']] >>> update_board(test_board,1,0,'X')
True
>>> test_board = [['X','O','-'],['-','X','-'],['X','O','-']] >>> update_board(test_board,2,1,'O')
CourseNana.COM

False CourseNana.COM

Task 6: Next move of the computer CourseNana.COM

Now we need to decide on the position of the next move for the computer. We have two levels of difficulty for the user. The next move of the computer depends on the difficulty level chosen by the user at the beginning of the game. CourseNana.COM

Write a function named next_move(board,level)that returns the position (row,col) of the next placement of ‘O’ using the following recommendations based on the level selected
(Note: you should breakdown the problem and write other helper functions for this task, thus decomposing your code).
CourseNana.COM

For the easy level, your code should randomly select one of the available positions. CourseNana.COM

For the hard level your code should try to find the best option at hand, using the following criteria in the given order (ie. you move to the next criterion only if the previous ones are not met). CourseNana.COM

1.    If there are two ‘O’s in a row, column or a diagonal, the next move should fill the corresponding row, column or diagonal with another ‘O’ so that the computer wins. CourseNana.COM

2.    If there are two ‘X’ s in a row, column or a diagonal, the next move should fill the corresponding row, column or diagonal with an ‘O’ so that the computer blocks the user’s next winning move. CourseNana.COM

3.    If there is an ‘O’ in a row, column or a diagonal, the next move should place another ‘O’ on the same row, column or diagonal. CourseNana.COM

4.    If there are no ‘O’s on the board, place an ‘O’ in any random available position. CourseNana.COM

Note: Only two test cases are provided. Some board configurations can result in more than one possible output. You should test your code with more configurations interactively via the play function which you will implement in task 7 below. CourseNana.COM

Input: The current status of the board and the difficulty level
Output: Position of the next move, as a tuple (row,column)
For example:
>>> test_board = [['X','-','-'],['X','O','-'],['O','-','-']] >>> next_move(test_board,'hard') CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
MCD4710代写,Introduction to Algorithms and Programming代写,Australia代写,Monash College代写,Python代写,MCD4710代编,Introduction to Algorithms and Programming代编,Australia代编,Monash College代编,Python代编,MCD4710代考,Introduction to Algorithms and Programming代考,Australia代考,Monash College代考,Python代考,MCD4710help,Introduction to Algorithms and Programminghelp,Australiahelp,Monash Collegehelp,Pythonhelp,MCD4710作业代写,Introduction to Algorithms and Programming作业代写,Australia作业代写,Monash College作业代写,Python作业代写,MCD4710编程代写,Introduction to Algorithms and Programming编程代写,Australia编程代写,Monash College编程代写,Python编程代写,MCD4710programming help,Introduction to Algorithms and Programmingprogramming help,Australiaprogramming help,Monash Collegeprogramming help,Pythonprogramming help,MCD4710assignment help,Introduction to Algorithms and Programmingassignment help,Australiaassignment help,Monash Collegeassignment help,Pythonassignment help,MCD4710solution,Introduction to Algorithms and Programmingsolution,Australiasolution,Monash Collegesolution,Pythonsolution,