169k views
0 votes
A Python data model defining the state of a game for Tic-Tac-Toe. You must fully describe the notion of a state of the game, limiting yourself to the primitive data types of the Python Programming Language. In addition, you must use the notation for defining types discussed over the course of the semester, and provide a detailed description of your model.Using your data model, you are to define the following functions in Python:

game_title - given no arguments, returns a string which will be used as the window title for a Tic-Tac-Toe game in TPGE;
game_over - a relation on states which determines whether or not the game is over in a given state;initial_state - a function which given no arguments, returns the initial state of the game of Tic-Tac-Toe;successor_state - a function which given the state of a game and a point corresponding to a mouse-click within the game window, returns the next state of the game;
image_representation - a function which given the state of a game, returns a list of TPGE images needed to draw the state for the user(s)
Using your functions from (2), implement a graphical, 2-Player version of Tic-Tac-Toe using TPGE, by following the blueprint given in simple_game.py.
For each function that you implement (helper functions and primary functions), give the function signature using the notation discussed in class.

1 Answer

4 votes

Answer:

Check the explanation

Step-by-step explanation:

Here in this game of Tic-Tac-Toe, it is using the TPGE engine which is a Tiny Python Game Engine. Let's talk about its functions like:-

def image_type(img): In this function, it is simply taking image as a parameter and returning its object type like DISC if the image is in graphical form, TEXT if it is a string, and LINE if it is other than the mentioned object.

def convert_image(img): In this function, it is simply taking image as a parameter and returning an equivalent graphical object as understood by John Zelle's. Mainly comparing for three things in this function and those are: if image equals to DISC then it is calling convert_circle(function), if image equals to LINE then it is calling convert_line(function), and if image equals to TEXT then it is calling convert_text(function),

def convert_circle(x): This function takes a list( a group of values) and makes a circle at the center of the window and the circle's radius is coming from the list.

convert_text, convert_line, convert_circle are only creating text, line, and circle and then returning it.

def graphical_elements(images): This function is taking image as a parameter and then extracting shape and color from the image and then calling convert_image(shape) and convert_type(shape) and it gives us graphic and kind respectively. Now it is checking whether kind equals to DISC If yes then filling color on the window else, setting the outline of the window

def run(): Here it is finally running the game with required parameters, the whole game is continously running under the while loop.

That's all

User OJ Kwon
by
5.2k points