The Moving Cat

Due: Feb 22 at 23:59 EST on MarkUs

Late policy: 1 hour grace period, following by automatic deduction of 5% per hour Additional rules

• Do not add any import statements

• Do not add code outside of your functions. Test your code using the interactive shell and the MarkUs tester

• Do not call print() or input()

• You may create additional functions.

Grading scheme

• Docstring examples - 20%

• Function correctness - 80%


MarkUs Autotester

Note that the MarkUs autotester for Assignment 1 only checks for your docstring examples and that your functions return the correct type. The function correctness tests are not provided for you to run before the deadline, so you are responsible for thoroughly testing your code. You are given unlimited tokens for running the checker for this assignment.


Provided Files

Download the starter code from MarkUs and extract the zip archive. The fifiles are described below.

• a1.py: This is the only file you will hand in. There are 4 functions for you to complete in this file.

• cat_world.py: The main program that allows you to “interact” with your cat and the world. This program will not run until you complete a1.py. You do not need to understand all the code in this file, but you should read through it and understand what the program is doing. Run this file more than once to see different world configurations.


Background

You are living in a 2D Cartesian world. You have a pet cat, who occupies a single point on the standard Cartesian plane. Your cat has gone outside to play, and is now trying to return home. You have a drone equipped with AI and a GPS receiver, which can track the location of your cat. The program on your drone was recently corrupted by a virus. To avoid paying large sums of money to recover your drone from the ransomware, you decide instead to develop a program for your dorne to monitor the cat’s location and determine if it is lost or not. The data you get from your drone is shown in Figure 1.

Figure 1: Depiction of the cat world after running cat_world.py


Tasks

All the tasks refer to functions in a1.py. For each of the 4 functions, complete the docstring (including at least 2 docstring examples) and function body.

is_home(cat_x, cat_y, home_x, home_y)

• Input parameters

cat_x and cat_y are ints which describe the position of your cat as a point (cat_x, cat_y). home_x and home_y are ints which describe the position of your home as a point (home_x, home_y).

• Expected Output

Return True if the cat is at home; i.e., the cat’s coordinates are the same as the home’s coordinates. Return False otherwise.

is_lost(cat_x, cat_y, x1, x2, y1, y2)

• Input parameters

cat_x and cat_y are ints which describe the position of your cat as a point (cat_x, cat_y). x1, x2, y1, and y2 are ints which define the following points on a standard 2D Cartesian plane:

(x1, y1)

(x1, y2)

(x2, y1)

(x2, y2)

Which form a bounding rectangle. You are guaranteed that the cat does not lie on the boundary of the rectangle, i.e. that all of the following are True:

cat_x != x1

cat_x != x2

cat_y != y1

cat_y != y2

abs(x1 - x2) >= 3

abs(y1 - y2) >= 3

Note that (x1, y1) may not necessarily be the lower-left corner of the bounding box.

• Expected Output

Return True if the cat is lost, and False otherwise. If the cat is within the bounding rectangle, the cat is not lost. If the cat is outside the bounding rectangle, the cat is considered to be lost. 

get_distance_to_home(cat_x, cat_y, home_x, home_y)

• Input parameters

cat_x and cat_y are ints which describe the position of your cat as a point (cat_x, cat_y). home_x and home_y are ints which describe the position of your home as a point (home_x, home_y).

• Expected Output

Return the Euclidean distance between your cat and your home. See Tutorial 1 for the definition of Euclidean distance.

put_fish_dish(x1, x2, y1, y2)

To lure your cat back into the bounding rectangle, you decide send a drone to place a dish of fish inside the bounding rectangle described previously. You need to tell the drone the coordinates where it should place the dish.

• Input parameters

x1, x2, y1, and y2 are ints which define the following points on a standard 2D Cartesian plane:

(x1, y1)

(x1, y2)

(x2, y1)

(x2, y2)

Which form a bounding rectangle. You may assume that:

abs(x1 - x2) >= 3

abs(y1 - y2) >= 3

Note that (x1, y1) may not necessarily be the lower-left corner of the bounding box.

• Expected Output

Return two ints which represent a point on the Cartesian plane, (x, y).

(x, y) must be located inside the bounding rectangle.

To return two values in a Python function, e.g. x and y, you should use the following syntax (note that the order which you return these values matters):

return x, y


Submission Checklist

• Complete 4 required functions

• Test your functions locally using the shell, your docstring examples, and the cat_world.py program

• Run the checker on MarkUs


Academic Integrity

This is an individual assignment. Do not share your code with others, or reference code from other sources.