Assignment 4: Robot Lawnmower SimulationDue: Wednesday, October 29th by 11:59 PM
Your task is to write a simulation of a robot lawnmower.
Here is a link to my version of the simulator:
robotLawnmower.jar
If you have Java installed, you should be able to double-click on the file to start the program.
Note: Internet Explorer incorrectly changes the file extension of downloaded jar files. Use Firefox (or any other web browser) to download the file.
The lawn to be mowed is a 100 (width) x 75 (height) grid. Each square of the grid has grass of some height. Initially, each square does not have any grass (height = 0). At each step of the simulation, any square of the lawn has a 1 in 20 chance of growing by one unit.
At any given time, the robot lawnmower covers a 4 x 4 grid of squares, and is facing either up, right, left, or down.
At each step in the simulation, the robot may either
When the robot moves, it cuts all of the grass in the 4 x 4 grid of squares under the robot (reducing them all to height 0.)
In addition to implementing the classes to simulate the lawn and the robot, you will implement a GUI to visualize the simulation.
The basic idea is that the GUI will update the simulation 10 times per second, showing the result of the simulation in a window.
Two classes will be essential in the creation of your GUI:
Here are versions you can use as a starting point:
Both classes assume that you have a class called World representing the entire state of the simulation. The SimulationApp class assumes your World class has a method called tick that executes one time step of the simulation.
You will probably not need to change the SimulationApp class at all. You will need to modify the SimulationPanel class to provide a concrete implementation of the paint method. This method uses a Graphics object to draw the contents of the panel. You should use this method to display a visualization of your simulation. It should:
Note that your paint method is called automatically; you won't need to call it explicitly.
See the Java API documentation for the set of methods that the Graphics class supports. (It is in the java.awt package.)
You will need to devise a strategy for your robot that enables it to cut the grass as quickly as possible.
A good approach is to use a greedy strategy: move the robot towards grass that is close by.
You do not need the robot to have a "plan" that takes into account the entire lawn.
Implementing the basic features as described above will earn up to 80 points. 10 points are allocated to design (how well you used classes and methods) and coding style.
Extra credit options include:
Export your project as a zip file (File->Export...->Archive File) and upload it to the submission server as assign4. The URL of the server is
https://camel.ycp.edu:8443/