logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

write a Python program that plays tic-tac-toe against a human player.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

ZEQ Python Programming Exercises

 

Exercise 1: Tic-tac-toe

Please write a Python program that plays tic-tac-toe against a human player. The program will have a single entry point function called tic_tac_toe which, when called from a Python terminal (or from a standalone python script) will display a blank tic-tac-toe board, and invite the user to choose a square to place his/her first move. The program will plot the user’s move and then counter with a move of its own. This cycle will repeat until either the player or the computer wins (or draws).

For example, our reference program produces this in the first couple of turns:

| |

-+-+-

| |

-+-+-

| |

Your move: top left

 

o| |

-+-+-

| |

-+-+-

| |

My move, thinking...

 

o| |x

-+-+-

| |

-+-+-

| |

Your move:

Design hints

Our reference program is under 200 lines of code and consists of around a dozen functions, and we use a class to keep all the program state together. You may use a purely functional style, or take an object- orientated approach, or a mixture of both – this is up to you. We’re looking for a simple and well- structured program that works and has no obvious defects. For bonus points, playing tic-tac-toe against your program should feel more like playing a human opponent than a rigid computer algorithm. If you want to impress us then give your program a “personality” of sorts, but don’t do anything too complicated.

Other hints in no particular order:

Handle edge cases relating to user inputs.

Use clear idiomatic python code, and try to avoid overly dense or “clever” code.

Use lots of comments to explain the intent of your code.

Your program’s output may be totally different from the example given above.

 

Exercise 2: Topological sort

 

Please write a standalone Python function that performs a topological sort (or “top sort” for short) on arbitrary graph like input data.

Background

 

From the Wikipedia article: https://en.wikipedia.org/wiki/Topological_sorting

 

In computer science, a topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge uv from vertex u to vertex v, u comes before v in the ordering. For instance, the vertices of the graph may represent tasks to be performed, and the edges may represent constraints that one task must be performed before another; in this application, a topological ordering is just a valid sequence for the tasks. Precisely, a topological sort is a graph traversal in which each node v is visited only after all its dependencies are visited.

In plain English, if we have information describing the links between objects in some overall “graph”, and those links are directional, then a topological sort of this information will produce a linear list starting with all objects that have no incoming links to other objects (i.e. no dependencies), followed by all objects that immediately depend on those, and so forth.

Consider the following Python graph structure and its corresponding graphical representation:

 

 

(5/5)
Attachments:

Expert's Answer

537 Times Downloaded

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

537 Times Downloaded

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

501 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

973 Answers

Hire Me
expert
Husnain SaeedComputer science

519 Answers

Hire Me
expert
Atharva PatilComputer science

764 Answers

Hire Me