1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aniked [119]
4 years ago
7

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, lim

iting 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.
Computers and Technology
1 answer:
Artist 52 [7]4 years ago
8 0

Answer:

Check the explanation

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

You might be interested in
Write an application that solicits and inputs three integers from the user and then displays the sum, average, product, smallest
Oksana_A [137]

Answer:

Please find below program

Explanation:

import java.util.Scanner;

public class Tester {

public static void main(String[] args) {

 

 // create an object of scanner class

 Scanner scanner  = new Scanner(System.in);

 

 //prompt user to enter first number

 System.out.println("Enter first integer: ");

 

 // read value from entered by user and keep it in num1

 int num1 = scanner.nextInt();

 

 //prompt user to enter second number

 System.out.println("Enter second integer: ");

 

 // read value from entered by user and keep it in num2

 int num2 = scanner.nextInt();

 

 //prompt user to enter third number

 System.out.println("Enter third integer: ");

 

 // read value from entered by user and keep it in num3

 int num3 = scanner.nextInt();

 //close scanner as we have done with user input

 scanner.close();

 

 //calculate sum

 int sum = num1+num2+num3;

 

 //calculate average

 int average = sum/3;

 

 //calculate product

 int product = num1*num2*num3;

 

 //find out largest number

 int largest = 0;

 if (num1>=num2){

  if(num1>=num3)

   largest = num1;

  else

   largest = num3;

 }else {

  if(num2>=num3)

   largest = num2;

  else

   largest = num3;

 }

 

 // find out smallest number

 int smallest = 0;

 if (num1<=num2){

  if(num1<=num3)

   smallest = num1;

  else

   smallest = num3;

 }else {

  if(num2<=num3)

   smallest = num2;

  else

   smallest = num3;

 }

 

 // print all the information

 System.out.println("Sum of three numbers : "+sum);

 System.out.println("Product of three numbers : "+product);

 System.out.println("Average of three numbers : "+average);

 System.out.println("Smallest number : "+smallest);

 System.out.println("Largest number : "+largest);

}

}

3 0
4 years ago
Print person1's kids, call the incNumKids() method, and print again, outputting text as below. End each line with a newline.
Hatshy [7]

Answer:

Hi there! This is a good question to grasp the concepts of object-oriented classes, encapsulation and abstraction of classes and their properties in Java. Please find the details below.

Explanation:

You can implement the solution by calling the getNumKids() function of the personInfo object or directly using the personKid input from the user to display the initial number of kids for the user. Then, calling the incNumKids() increases the kids count. Finally, displaying the new number of kids is done by invoking the getNumKids() method of the PersonInfo object that returns the private property of numKids to the user. The user cannot access this property without the get and set methods.

CallPersonInfo.java =====

import java.util.Scanner;

public class CallPersonInfo {

public static void main (String [] args) {

Scanner scnr = new Scanner(System.in);

PersonInfo person1 = new PersonInfo();

int personsKid;

personsKid = scnr.nextInt();

person1.setNumKids(personsKid);

System.out.println("Kids: " + personKid); // or person1.getNumKids();

   person1.incNumKids();

   System.out.println("New baby, kids now: " + personInfoObject.getNumKids());

 

}

}

You can also write the code in the same file as PersonInfo.java as below.

import java.util.Scanner;

class PersonInfo {

 private int numKids;

 public void setNumKids(int setPersonsKids) {

   numKids = setPersonsKids;

 }

 public void incNumKids() {

   numKids = numKids + 1;

 }

 public int getNumKids() {

   return numKids;

 }

 public static void main(String args[]) {

   System.out.println("Enter number of kids: ");

   Scanner scan = new Scanner(System.in);

   int num_kids = scan.nextInt();

   PersonInfo personInfoObject = new PersonInfo();

   personInfoObject.setNumKids(num_kids);

   System.out.println("Kids: " + num_kids);

   personInfoObject.incNumKids();

   System.out.println("New baby, kids now: " + personInfoObject.getNumKids());

 }

}

5 0
3 years ago
Create the Following Menu in a loop so the menu will continually show until the user chooses to exit.AddMultiplyExitAdd a value
ycow [4]

Answer:

I have added the code again with the mistakes are corrected please see the comments in code. You have mistake in while loop condition.

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

int options ();

int option1 ();

int option2 ();

int option3 ();

double addition (double num1, double num2);

double multiplication (double num1, double num2);

int main()

{  

jump:

int option = 0;  

cout << "1. Add" << endl;

cout << "2. Multiply" << endl;

cout << "3. Exit" << endl;

 cout << "Enter option 1 for addition, option 2 for multiplication, or option 3 to exit" "Enter an option: ";

  cin >> option;

   switch (option)  

{  

case 1:option1;  

int option1 ();

{  

double num1 = 0;  

double num2 = 0;

// void int key = 0;  

cout << " Enter a number: ";  

cin >> num1;  

cout<< " Enter a second number: ";  

cin >> num2;  

double sum = addition(num1, num2);  

cout << " Sum is: " << sum <<endl;

 } break;  

 case 2: option2;  

 int option2 ();

 {  

 double num1 = 0;  

 double num2 = 0;

 cout << " Enter a number:";

 cin >> num1;

 cout << " Enter a second number: ";

 cin >> num2;

 double product = multiplication(num1, num2);

  cout << " Product is: " << product << endl;

  //system("cls");

  }  

  break;

   case 3: option3;  

   int option3();

    {

 return 0;

 }  

 break;  

 default: cout << " Invalid number entered: ";

 }

 //do {main();}

 //while (option < 3); //you have mistake in this loop please have a look

 while (option<3)

 {

  goto jump;

 }

 

 }

 double addition(double num1, double num2)

 {

  return num1 + num2;

  }

 double multiplication(double num1, double num2)

 {

  return num1*num2;

  }

Explanation:

You can also do this by using goto statement in switch case and menu will be repeated until the user not select to exit and now it will work with the loop as well.

I hope it will help you!

4 0
3 years ago
State and explain three importance of internet education​
Ne4ueva [31]

Answer:

It can improve the quality of education in many ways. It opens doorways to a wealth of information, knowledge and educational resources, increasing opportunities for learning in and beyond the classroom. Teachers use online materials to prepare lessons, and students to extend their range of learning

Explanation:

4 0
3 years ago
Read 2 more answers
What property of semi-metals is useful in the computer industry?
artcher [175]
The answer is (a. Semi-conducting)
In the computer industry, semi-metals with a semiconducting property are useful in making of semiconductors. These metals have high resistance but lower than compare to insulators. This conductor could be crystalline or amorphous solids.
4 0
3 years ago
Other questions:
  • URGENT!! Ronald wants to search for an image of a sports car. Ronald doesn’t have to remember the specific name of the image to
    5·1 answer
  • Which tab should gemima use to open the formula dialog box
    13·2 answers
  • Time (non-statistical) division multiplexing differs from frequency division multiplexing because it:
    5·1 answer
  • In excel, a number can contain the characters__
    8·1 answer
  • A final class can't be extended.<br><br> *True<br><br> *False
    9·1 answer
  • How many bits would be needed to count all the students in class today
    9·1 answer
  • We investigated a program which is probably used as one component of a bigger password breaking algorithm. We determined that th
    14·1 answer
  • Which type of computer networks are bigger as well as smaller than a MAN?
    10·1 answer
  • Why would you browse by entering a URL rather than use a link in a Web page
    15·1 answer
  • Based on three scores that the user inputs, display the average of the score and the letter grade that is assigned fort he test
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!