In this problem set, you will design a simulation and implement a program that uses classes to simulate robot movement. We recommend testing your code incrementally to see if your code is not working as expected. To test your code, run ps3_tests_f16.py.
As always, please do not change any given function signatures.
Make sure you consult the Style Guide as we will be taking point deductions for violations (e.g. non- descriptive variable names and uncommented code).
You will be using Python's random module, so check out its documentation. Make sure you import random at the top of your file. Some useful function calls include:
• random.randint(a, b) for integer inputs a and b, returns a random integer N such that a <= N <= b
• random.random() returns a float N such that 0.0 <= N < 1.0
• random.seed(0) starts the pseudorandom number generator Python uses at the same spot so that the sequence of random numbers it produces from different runs of your code will be the same. You may find using this is useful while debugging.
iRobot is a company that sells the Roomba vacuuming robot (watch one of the product videos to see these robots in action). Roomba robots move around the floor, cleaning the area they pass over.
You will code a simulation to compare how much time a group of Roomba-like robots will take to clean the floor of a room using two different strategies. The following simplified model of a single robot moving in a square 5x5 room should give you some intuition about the system we are simulating. A description and sample illustrations are below.
The robot starts out at some random position in the room. Its direction is specified by the angle of motion measured in degrees clockwise from “north.” Its position is specified from the lower left corner of the room, which is considered the origin (0.0, 0.0). The illustrations below show the robot's position (indicated by a black dot) as well as its direction (indicated by the direction of the red arrowhead).
Here are the components of the simulation model.
1. Room: Rooms are rectangles, divided into square tiles. At the start of the simulation, each tile is covered in some amount of dirt, which is the same across tiles. You will first implement the abstract class RectangularRoom in Problem 1, and then you will implement the subclasses EmptyRoom and FurnishedRoom in Problem 2.
2. Robot: Multiple robots can exist in the room. iRobot has invested in technology that allows the robots to exist in
the same position as another robot without causing a collision. You will implement the abstract class Robot in Problem 1. You will then implement the subclasses StandardRobot and FaultyRobot in Problems 3 and 4.
More details about the properties of these components will be described later in the problem set.
We have provided two additional files: ps3_visualize.py and ps3_verify_movement27.py. These Python files contain helper code for testing your code and for visualizing your robot simulation. Do not modify them. If one of these files throws an error, it is because of an error in your code implementation. To test your code, run ps3_tests_f16.py.
Read ps3.py carefully before starting, so that you understand the provided code and its capabilities. Remember to carefully read the docstrings for each function to understand what it should do and what it needs to return.
The first task is to implement two abstract classes, RectangularRoom and Robot. An abstract class will never be instantiated, and is instead used as a template for other classes that inherit from it. Abstract classes define methods that are shared by their subclasses. These methods can be implement ed in the abstract classes, but they can also be left unimplemented and instead implemented in their subclasses.
In the skeleton code provided, the abstract classes contain some methods which should only be implemented in the subclasses. If the comment for the method says “do not change,” please do not change it. You can test your code as you go along by running the provided tests in ps3_test_f16.py.
In ps3.py, we've provided skeletons for these classes, which you will fill in for Problem 1. We've also provided for you a complete implementation of the class Position.
• RectangularRoom - Represents the space to be cleaned and keeps track of which tiles have been cleaned.
• Robot - Stores the position, direction, and cleaning capacity of a robot.
• Position - Represents a location in x- and y-coordinates. x and y are floats satisfying 0 ≤ x < w and 0≤ y < h
• Representation:
o You will need to keep track of which parts of the floor have been cleaned by the robot(s). When a robot's location is anywhere inside a particular tile, we will consider the dirt on that entire tile to be reduced by some amount determined by the robot. We consider the tile to be “clean” when the amount of dirt on the tile is 0. We will refer to the tiles using ordered pairs of integers: (0, 0), (0, 1), …, (0, h-1), (1, 0), (1, 1), …, (w-1, h-1).
o Tiles can never have a negative amount of dirt.
• Starting Conditions:
o Initially, the entire floor is uniformly dirty. Each tile should start with an integer amount of dirt, specified by dirt_amount.
• Representation
o Each robot has a position inside the room. We'll represent the position using an instance of the Position class. Remember the Position coordinates are floats.
o A robot has a direction of motion. We'll represent the direction using a float direction
satisfying 0 ≤ direction < 360, which gives an angle in degrees from north.
o A robot has a cleaning capacity, capacity, which describes how much dirt is cleaned on each tile at each time.
• Starting Conditions
o Each robot should start at a random position in the room (hint: the Robot’s room attribute has a method you can use)
• Movement Strategy
o A robot moves according to its movement strategy, which you will implement in update_position_and_clean.
Note that room tiles are represented using ordered pairs of integers (0, 0), (0, 1), …, (0, h-1), (1, 0), (1, 1), …, (w-1, h-
1). But a robot’s Position is specified as floats (x, y). Be careful converting between the two!
If you find any places above where the specification of the simulation dynamics seems ambiguous, it is up to you to make a reasonable decision about how your program/model will behave, and document that decision in your code.
Complete the RectangularRoom and Robot abstract classes by implementing their methods according to the pecifications in ps3.py. Remember that these classes will never be instantiated; we will only instantiate their subclasses.
• Make sure to think carefully about what kind of data type you want to use to store information about the floor tiles in the RectangularRoom class.
• A majority of the methods should require only one line of code.
• The Robot class and the RectangularRoom class are abstract classes, which means that we will never make an instance of them. Instead, we will instantiate classes that inherit from the abstract classes.
• In the final implementation of these abstract classes, not all methods will be implemented. Not to worry — their subclass(es) will implement the m (e.g., Robot’s subclasses will implement the method update_position_and_clean ).
• Remember that tiles are represented using ordered pairs of integers (0, 0), (0, 1), …, (0, h-1), (1, 0), (1, 1), …, (w-1, h-1). Given a Position specified as floats (x, y), how can you determine which tile the robot is cleaning?
• Remember to give the robot an initial random position and direction. The robot’s position should be of the Position class and should be a valid position in the room. Note that the abstract class RectangularRoom has a get_random_position method that may be useful for this.
• Consider using math.floor(x) from the math module instead of int(x) to round floats to whole numbers so that numbers are always rounded down and points are ensured to be inside the room
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme