2010 Grid Checker

<< 2010Trail | APQuestionsTrailIndex | 2009NumberCube >>

question

GridChecker.java

import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.util.ArrayList;
import java.util.List;
public class GridChecker
{
   private BoundedGrid<Actor> gr;
   public GridChecker(BoundedGrid gr)
   {
       this.gr=gr;
   }
   public Actor actorWithMostNeighbors()
  {
   // part (a)
    return null;
  }
  public List<Location> getOccupiedWithinTwo(Location loc)
  {

    //part (b)

    return null;
  } 
}

The next 4 are for Checking your answer to part (a)

GridCheckerTester1.java

import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.awt.Color;
public class GridCheckerTester1
{
    public static void main(String[] args)
    {
        ActorWorld world = new ActorWorld();
        Rock r=new Rock();
        world.add(new Location(2, 1), r);
        world.add(new Location(2, 3), new Rock());
        world.add(new Location(2, 2), new Bug());
        world.show();
        GridChecker gc=new GridChecker((BoundedGrid)world.getGrid());
        System.out.println("Actor with most should be Bug at 2,2:"+gc.actorWithMostNeighbors() ); 

    }
}

GridCheckerTester2.java

import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.awt.Color;
public class GridCheckerTester2
{
    public static void main(String[] args)
    {
        ActorWorld world = new ActorWorld();
        Rock r=new Rock();
        world.add(new Location(1, 1), r);
        world.add(new Location(2, 4), new Rock());
        world.add(new Location(2, 2), new Bug());
        world.add(new Location(2, 1), new Critter());
        world.show();
        GridChecker gc=new GridChecker((BoundedGrid)world.getGrid());
        System.out.println("Actor with most should be Rock at 1,1:"+gc.actorWithMostNeighbors() ); 

    }
}

GridCheckerTester3.java

import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.awt.Color;
public class GridCheckerTester3
{
    public static void main(String[] args)
    {
        ActorWorld world = new ActorWorld();
        Flower f=new Flower();
        world.add(new Location(1, 1), f);
        world.add(new Location(2, 3), new Bug());
        world.show();
        GridChecker gc=new GridChecker((BoundedGrid)world.getGrid());
        System.out.println("Actor with most could be the Flower at 1,1 or the Bug at 2,3:"+gc.actorWithMostNeighbors() ); 

    }
}

GridCheckerTester4.java

import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.awt.Color;
public class GridCheckerTester4
{
    public static void main(String[] args)
    {
        ActorWorld world = new ActorWorld();      
        world.show();
        GridChecker gc=new GridChecker((BoundedGrid)world.getGrid());
        System.out.println("No Actors, so actorWithMost Neighbors shuld be null:"+gc.actorWithMostNeighbors() ); 

    }
}

the next two are for testing your answer to part (b):

GridCheckerTester5.java

import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.awt.Color;
public class GridCheckerTester5
{
    public static void main(String[] args)
    {
        ActorWorld world = new ActorWorld();
        world.add(new Location(1, 1), new Rock());
        world.add(new Location(2, 3), new Bug());
        world.show();
        GridChecker gc=new GridChecker((BoundedGrid)world.getGrid());
        System.out.println("The list of occupied locations within 4,3 should be the location of the Bug at 2,3 only:\n"+gc.getOccupiedWithinTwo(new Location(4,3)) ); 

    }
}

GridCheckerTester6.java

import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.awt.Color;
public class GridCheckerTester6
{
    public static void main(String[] args)
    {
        ActorWorld world = new ActorWorld();
        world.add(new Location(0, 0), new Rock());
        world.add(new Location(3, 3), new Rock());
        world.add(new Location(3, 2), new Bug());
        world.add(new Location(5, 4), new Critter());
        world.add(new Location(5, 6), new Critter());
        world.show();
        GridChecker gc=new GridChecker((BoundedGrid)world.getGrid());
        System.out.println("The list of occupied locations within 1,1 should be [(0, 0), (3, 2), (3, 3)] :\n"+gc.getOccupiedWithinTwo(new Location(1,1)) ); 
        System.out.println("The list of occupied locations within 0,0 should be an empty list :\n"+gc.getOccupiedWithinTwo(new Location(0,0)) ); 
         System.out.println("The list of occupied locations within 3,3 should be [(3, 2), (5, 4)] :\n"+gc.getOccupiedWithinTwo(new Location(3,3)) ); 
         System.out.println("The list of occupied locations within 5,4 should be [(3, 2), (3, 3), (5,6)] :\n"+gc.getOccupiedWithinTwo(new Location(5,4)) ); 
         System.out.println("The list of occupied locations within 5,6 should be [(5, 4)] :\n"+gc.getOccupiedWithinTwo(new Location(5,6)) ); 

    }
}