YCP Logo Assignment 7: Robot Lawnmower Simulation

Due: Tuesday, December 15th by 11:59 PM

Important: Late submissions will not be accepted!

Your Task

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.

Simulation Details

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

  1. Move one tile forward in its current direction
  2. Change direction.

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.)

GUI Programming

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:

  • a SimulationPanel class, to display the simulation in a rectangular region of a window
  • a SimulationApp class, to provide a frame (top-level window) in which to display the simulation, and a main method to create and show the simulation frame

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:

  • Use colors and/or stippling to indicate how high the grass in each square of the lawn is
  • Each square of the lawn should be drawn as an 8 x 8 block of pixels
  • Draw the lawnmower, indicating its current direction

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.)

Lawnmower AI

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.

Grading, Extra Credit

Implementing the basic features as described above will earn up to 80 points. Of these 80 points, 10 points are allocated to design (how well you used classes and methods) and coding style.

Options for additional credit include:

  • Obstacles such as trees and water (up to 5 points)
  • Implementation of multiple lawnmower AI algorithms (up to 5 points)
  • Keep a running numeric display of the amount of grass the lawnmower cuts per unit time (up to 5 points)
  • Multiple lawnmowers - make sure they don't crash into each other! (up to 5 points)
  • User-controlled lawnmower: allow the user to control a lawnmower using the arrow keys (up to 5 points)

Submitting

Export your project as a zip file (File->Export...->Archive File) and upload it to the submission server as assign7. The URL of the server is

https://camel.ycp.edu:8443/