Assignment 3


This assignment has two parts, one of which is relatively minor and easy - learning HTML (something you may already know).

  1. Part I: HTML
    The purpose of this part of Assignment 3 is to help you learn HTML quickly, if you aren't already familiar. HTML will be necessary for the later part of the course in which we will learn how to use Java servlets for website (server-side) programming. Accordingly, for this part of the assignment, you will need to:
    • Learn HTML. You should know: the essential tags, how to create links, tables, lists, form elements. You can learn HTML from any number of websites or this one.
    • Create a homepage for yourself, with at least a picture, a bio, and some fun facts. Show that you are using at least a few HTML tags.
    • The zip for for this submission should contain your HTML file, along with any additional images that you use. Call it mypage.html. When this file is opened in a browser (with Open-File) the result should be your homepage.



  2. Part II: Java assignment.

    In this assignment, we will take the forest fire theme to a new and interesting level by introducing a "game" aspect to the simulation. Your assignment will consist of writing a "strategy" for players in the game. We will provide a simulator and GUI (included in the download) to run the game and view the results - you will only need to implement strategy. Your strategies will be evaluated by playing every other student in the class.

    Two players play the game, each with one or more "pieces". Here are the details of the game:

    • The "board" for the game is an 8 x 8 landscape (grid). The X and Y coordinates of the cells are in the range 0,1,...,7.
    • There are two players (opponents) in the game, called Offense and Defense.
    • Player Offense has only one piece (like a chesspiece), called the Pyromaniac. The starting position for the Pyromaniac is cell (0,0).
    • Player Defense has two pieces, each of which is called a FireFighter. The starting positions for these FireFighters are cells (6,7) and (7,7).
    • As in any 2-person game, each player takes turns in moving pieces. At every turn (step), the Offense gets to move first, followed by the Defense. Unlike many 2-person games (such as chess), the Defense gets to move each of the two FireFighters during the Defense's turn.
    • A piece can be moved from its current cell in the landscape to any of the four neighboring cells (except when on the border of the grid, in which case there are fewer neighboring cells).
    • A piece may be moved into a cell occupied by another piece, resulting in one the pieces being "captured" (We'll explain this later).
    • The landscape will be populated with trees.
    • The goal of the Offense is to use the Pyromaniac to destroy as many trees as possible (by igniting trees).
    • The goal of the Defense is to minimize the damage, if any.
    • About the Pyromaniac:
      • At every step, when it's the turn of the Offense, there are three choices: (1) do not move at all; (2) move to a neighboring cell (one of at most four); (3) ignite the tree in the current cell, if there is an unburnt tree in the current cell.
    • About a FireFighter:
      • At every step, each FireFighter can be moved. There are four choices: (1) do not move at all; (2) move to a neighboring cell (one of at most four); (3) douse the tree (burning or not) in the current cell; (4) move to a neighboring cell containing the Pyromaniac and capture it.
      • A tree can be doused by a FireFighter if the tree is unburnt, ignited or currently burning. If the tree is unburnt, the dousing ensures it will never burn for the rest of the simulation; if it's burning or ignited, the fire is successfully extinguished.
    • Thus, the Pyromaniac must try to evade capture and ignite as many trees as possible, whereas the FireFighters combined must try to capture the Pyromaniac and douse as many fires as possible.
    • Tree fires spread as before: a burning tree ignites neighbors.
    • The game will be played for some undetermined number of steps, possibly 100 or 200 steps (turns), regardless of whether the Pyromaniac is captured (This will allow the FireFighters to douse more fires).
    • Here's how scoring works:
      • You will implement both an Offense player and a Defense player.
      • Each student in the class will play every other student in the class. For every such match-up, your Offense will be played against your opponent's Defense and vice-versa.
      • You win if your tree-score is higher than your opponent's in the match-up.
      • To score a match-up: when you play as Offense in a particular match-up, the number of trees burned is added to your score (more is better); when you play as Defense, the number of trees burned in that game is subtracted from your score (fewer is better). The resulting number is your tree-score in the match-up. You win the match-up (game) if your tree-score is higher than your opponent's tree-score.
      • The final objective is to win as many games as possible.

    In terms of programming, the following points will help you get started:

    • You will implement both Offense and Defense separately. As mentioned above, your "Offense" implementation will be selected to battle someone else's "Defense" implementation (or the other way around). For testing, you can get your implementations to play each other.
    • To test your code, we will provide you with a simulator and GUI so you can observe the results of your individual effort.
    • The simulator has default implementations of Offense and Defense, called "House" versions (casino terminology). Thus, you can select to play your Offense against the House version of Defense, in which case the simulator will upload your Offense and run the game.
    • Download assign3.zip.
    • After you unpack, you will see a number of Java source files (for you to read, but not modify) and many class files (Be careful not to delete any of these).
    • Most important among these files are the files Offense.java and Defense.java. Notice that each of these is an interface. Your class for Offense must must implement the Offense.java interface (but can have other methods). Likewise, your class for Defense must must implement the Defense.java interface (but can have other methods).
    • Important: DO NOT MODIFY AND DO NOT ADD TO ANY OF THE FILES INCLUDED IN THE zip that you download. You will write your part from scratch as specified below.
    • It will help to understand what the simulator does when processing a "step" or "turn". At each step, the simulator does the following in sequence: all burning trees are set to "burnt"; all ignited trees are set to "burning"; all burning trees ignite their neighbors; the Pyromaniac gets to move; FireFighter 1 gets to move; and lastly, FireFighter 2 gets to move.

    To get started:

    1. Download the above zip file, unpack it and compile the source files.
    2. Run GameGui. This will bring up a frame with a menu. One of these lets you run a "demo" in which you can observe the default (demo) implementations battle it out.
    3. Now see what happens if you play the house as Offense (That is, you are Offense, and the house is Defense). You will get prompted for the name of your class file, so type "beavisOffense" without the quotes (if your username is beavis.)
    4. Important: You need to name your Java files carefully. If your username is beavis then your Offense source file should be called beavisOffense.java and your Defense source file should be called beavisDefense.java.
    5. Next, your files need to contain public classes by those names and only one class in each file. Thus, the file beavisOffense.java will have a public class called beavisOffense and no other classes. Similarly, the file beavisDefense.java will have a public class called beavisDefense and no other classes. So, all your code needs to be in these classes.
    6. Important: your Offense class must implement the interface Offense provided to you in the file Offense.java. Similarly, your Defense class must implement the interface Defense provided to you in the file Defense.java.
    7. All you really need to do is implement the methods (with the exact same signatures!) in each interface. Via the methods, you will get a chance to decide where you want to place your pieces on the landscape and, when the game proceeds, you get a chance to decide where to move pieces.
    8. About your Offense class:
      • Your Offense class will implement the interface Offense provided to you in the file Offense.java.
      • Here is what the interface looks like:
        public interface Offense {
        
          public PyroMove getInitialPosition ();
        
          public PyroMove move ();
        
        }
            
      • Both methods return an instance of PyroMove.
      • Here is (part of) the definition of PyroMove.java:
        public class PyroMove {
        
          private int x, y;
          private boolean ignite;
        
          public PyroMove(int x, int y, boolean ignite)
          {
            this.x = x;
            this.y = y;
            this.ignite = ignite;
          }
        
          // ...
        
        }
            
      • The simulator will call your getInitialPosition() method once to ask you where you want your Pyromaniac initially placed. By creating an instance of PyroMove and setting the x,y values (via sending them to the constructor), you will indicate the position.
        You MUST return (0,0) since that is the required starting position for the Pyromaniac. (We are designing it this way to allow for arbitrary starting positions in the future).
      • After the game starts, the simulator will call the move() method and expect to get back an instance of PyroMove in which are contained: (1) The X value of the desired position; and (2) the Y value of the desired position, and (3) a decision whether or not to ignite the tree in the current cell (without moving).
      • Note: you cannot move and ignite at the same time; thus, igniting takes up a turn.
      • The simulator will check to make sure your moves are legal. Any illegal move will cause you to lose the game immediately!
      • It is illegal for a Pyromaniac to: (1) move to a non-neighboring cell, or (1) to move into a cell occupied by another piece, or (3) to try to ignite a non-existent tree, or (4) to try to ignite a burnt tree, (5) to try to ignite a doused tree.
      • If you discover you cannot move, you should return null.
    9. About your Defense class:
      • Your Defense class will implement the interface Defense provided to you in the file Defense.java.
      • Here is what the interface looks like:
        public interface Defense {
        
          public FighterMove getInitialPosition (int i);
        
          public FighterMove move (int i);
        
        }
            
      • Both methods return an instance of FighterMove.
      • Here is (part of) the definition of FighterMove.java:
        public class FighterMove {
        
          private int x, y;
          private boolean douse;
        
          public FighterMove(int x, int y, boolean douse)
          {
            this.x = x;
            this.y = y;
            this.douse = douse;
          }
        
          // ...
        
        }
            
      • The simulator will call your getInitialPosition() method twice, first time with the integer parameter "1" and second time with integer parameter "2", to ask you where you want your firefighters initially placed. By creating an instance of FighterMove and setting the x,y values (via feeding them to the constructor), you will indicate the position.
        You MUST return (6,7) and (7,7) successively since those are the required starting positions for the FireFighters.
      • After the game starts, the simulator will call the move() method and expect to get back an instance of FighterMove in which are contained: (1) The X value of the desired position; and (2) the Y value of the desired position, and decision whether or not to douse the tree in the current cell, if there's one.
        Important: to capture the Pyromaniac, you need to have a firefighter be in a neighboring cell and simply move into the cell occupied by the Pyromaniac.
      • Note: you cannot move and douse at the same time.
      • The simulator will check to make sure your moves are legal. Any illegal move will cause you to lose the game immediately!
      • It is illegal for a FireFighter to: (1) move to a non-neighboring cell, or (1) to move into a cell occupied by another firefighter, or (3) to try to douse a non-existent tree, or (4) to try to douse a burnt tree.
      • If you discover you cannot move, you should return null.
    10. Important: Any illegal move will cost you the game.
    11. It is hard to do anything intelligent without knowing the current status of the landscape. You can query the simulator by calling two static methods in the class Game which you have downloaded:
      public class Game {
      
        public static final int NO_TREE = 0;
        public static final int UNBURNT_TREE = 1;
        public static final int IGNITED_TREE = -1
        public static final int BURNING_TREE = -2;
        public static final int BURNT_TREE = -3;
        public static final int DOUSED_TREE = -4;
      
        public static final int UNOCCUPIED = 0;
        public static final int FIGHTER1 = 1;
        public static final int FIGHTER2 = 2;
        public static final int PYRO = 3;
        
        public static int getTreeStatus (int x, int y);
      
        public static int getOccupancyStatus (int x, int y);
      
      }
        
      So, the method
        public static int getTreeStatus (int x, int y);
        
      tells you whether a cell contains a tree, and what the status of the tree is. Similarly, the method
        public static int getOccupancyStatus (int x, int y);
        
      tells you who is in a particular cell. The int value returned is one of the constants shown.
    12. Important: Do NOT create an instance of Game: only call one the static methods.
    13. You are free to write whatever code you want to compute your next move for both Offense and Defense. However, your code cannot take longer than 3 seconds to compute a move. We will terminate a move after 3 seconds and declare the game over. If you are doing simple things, this should not be a concern at all.
    14. The standard javadoc documentation for all the relevant classes can be found here.
    15. OK, now implement your strategies!

    Deliverables and submission:

    • The source code for your two programs. NOTE: FOR CONVENIENCE OF GRADING PLEASE WRITE ALL YOUR CODE IN THE TWO FILES named in the way described above. If you must write any additional classes inside those files, please name them uniquely by embedding your username in the name of the class. For example, if your username is gwashington and you create a "sort" class, then call it GwashingtonSort. This way, the simulator will be sure to load only your classes. (We will have everybody's classes in the same directory for the competition).
    • Your code will be graded on correctness, documentation AND game score.
    • Important: Include only files that YOU have written in your zip-file when you upload into Blackboard.