CS 2110 Homework Assignment 5

Due: Tuesday 11/30 11:59pm No extensions


Description

We have studied in depth the genetic makeup of a number of unusual and intriguing creatures. Now, we will travel back in time, to revisit the story of how these particular species were first discovered by science. In this assignment, you will write an artificial intelligence to guide "the naturalist", who boldly explores an uncharted tropical island and collects specimens of local wildlife.
The Naturalist
The Naturalist
The naturalist begins on his ship, moored just off the shore. The goal is to collect all of the animals on the island and bring them to the ship. Only 3 animals can be carried at a time, so this will require many trips to the ship. The map is represented as a graph, with each square represented as a node. The naturalist does not have a global view of the map, but he can see and move to adjacent nodes. He can search his current location for animals and, having found them, can pick them up and drop them.
The Ship
The Ship
Being a naturalist is very competitive. The naturalist earns a points for various actions. The ultimate goal of this assignment is to collect all animals and drop them on the ship.
Exploration:
Moving to a node for the first time, 10 points.
Retrieval:
100 points for each species dropped at the ship.
Mission Accomplished:
1000 point bonus when all species have been collected.
Movement:
Each move costs 1 point + the number of animals being carried. E.g., moving with three animals costs four points.

Writing the Code

This assignment is a departure from previous assignments, in that you will not need any of your old code. In fact, you'll turn in only one Java file, a subclass of the Naturalist class. Use inner classes if you need additional classes. Start by reading the Javadocs to learn the API for the naturalist.

The Naturalist Class

Your naturalist class will be instantiated by the simulator by calling the default constructor. To execute your program, the simulator then calls the run() method. This will be called by the simulator. Please refer to the Javadocs for cs2110.assignment5.Naturalist for documentation on the methods you will need to complete the assignmnt.

An example program:

import java.util.Random; package cs2110.assignment5.examples; import cs2110.assignment5.*; /* * Random walking naturalist example. * Specify cs2110.assignment5.Naturalist as the first command * line argument to try it out */ public class RandomWalkNaturalist extends Naturalist { public void run() { while(true) { Node[] exits = getExits(); Random rng = getRandom(); // get the random number generator Node exit = exits[rng.nextInt(exits.length)]; // Pick a random exit node moveTo(exit); // move there // If there are any animals here, pick them up for(String animalName : listAnimalsPresent()) { try { collect(animalName); } catch(CapacityExceededException e) { dropAll(); // Out of space! Drop everything and try again collect(animalName); } } // If we're carrying anything, drop it with 50% probability if(getInventory().size() > 0 && rng.nextBoolean()) { dropAll(); } } } }

The Simulator

In an attempt to re-create this historical voyage, we will provide you with a naturalist simulator. It is contained in a5.jar, a binary-only runnable JAR file. To use this JAR in Eclipse:

  1. Add a5.jar to your project's build path
  2. Run the main class, cs2110.assignment5.Simulator
    • As the first command line argument, supply the fully-qualified name of your Naturalist class.
The simulator will stop once you have successfully carried all of the animals to your ship. Other simulator options are given by the usage blurb:
Command line arguments: <player class> [flags] Optional flags: --map=mapfile.txt Load the map from a specified map file. --headless Run without a GUI. --seed=N Use a specified random seed number.
Custom maps can be created using the format in this example map.

a screenshot

Notes

Competition

There will be three prizes awarded for outstanding solutions:

The competition will be run on new maps, larger and with more animals. To enter the competition, please say so in your README.

Extra Credit

As usual, extra credit points will be available for substantive JUnit tests. Extra credit will also be awarded use of better algorithms for the task at hand (e.g., all-pairs shortest paths instead of single-source). Please mention extra credit in your README.

Downloads

Graphics acknowledgments