OO Programming and Data Structures | CS 241

03 Prove : Assignment

Overview

This assignment will give you practice using classes in Python to solve a problem.

Instructions

Write a Python 3 program to model driving a robot around in an environment. The robot has the following attributes:

It can do the following things:

The robot should begin at location (10, 10), and should start with a fuel amount of 100.

When told to move, the robot's fuel should decrease by 5, and it should move one unit in the desired direction (Left should subtract one from the x-coordinate and right should add 1 to the it. Down should add 1 to the y-coordinate, and up should subtract one from it). Displaying the status should print the location and fuel to the console in the format: "(x-coordinatey-coordinate) - Fuel: fuel-amount", such as (9, 4) - Fuel: 75.

Firing the laser should output "Pew! Pew!" to the console and reduce the fuel-amount by 15.

If the robot does not have enough fuel for any of the above actions, it should display the text, "Insufficient fuel to perform action". In that case it should not move, fire the laser, or reduce the fuel.

User Interface

The user is presented with a prompt: "Enter command: " and can enter any of the following commands:

Any other commands should be ignored, and the user re-prompted. When the user enters the quit command, the program should display the text, "Goodbye" and then exit.

Design

Your program should demonstrate good object-oriented design principles. You should use functions for appropriate main interaction, and a class with appropriate variables and methods (member functions) to model the robot.

Make sure to use good style including variable names, function headers, and appropriate comments. Avoid global variables and other elements of code that will make your code difficult to read and maintain.

Sample Output

And example run of the program could look something like the following:


Enter command: status
(10, 10) - Fuel: 100
Enter command: left
Enter command: status
(9, 10) - Fuel: 95
Enter command: left
Enter command: left
Enter command: left
Enter command: status
(6, 10) - Fuel: 80
Enter command: right
Enter command: status
(7, 10) - Fuel: 75
Enter command: up
Enter command: up
Enter command: down
Enter command: status
(7, 9) - Fuel: 60
Enter command: fire
Pew! Pew!
Enter command: up
Enter command: fire
Pew! Pew!
Enter command: status
(7, 8) - Fuel: 25
Enter command: fire
Pew! Pew!
Enter command: fire
Insufficient fuel to perform action
Enter command: status
(7, 8) - Fuel: 10
Enter command: left
Enter command: left
Enter command: left
Insufficient fuel to perform action
Enter command: status
(5, 8) - Fuel: 0
Enter command: quit
Goodbye.

Automatic Grading Script (TestBed)

To assist you in your development, an automated test script is provided. Please keep in mind, that unlike checkpoints, your program will also be evaluated for code quality and correctness.


testBed cs241/assign03 assign03.py

Submission

Submit your program by logging into the CS Department Linux system, and running the submit command with your filename. Example:


submit assign03.py

You should then select the appropriate course (CS 241), instructor, and assignment from the list.

Assessment and Grading

For your information, the instructor will use these assessment guidelines to evaluate your assignment. Feel free to refer to this to understand the expectations of this submission.