Guest User

Ghost

a guest
Jun 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. abstract class Location implements Comparable<Location> {
  4.    
  5.     public int  r;
  6.     public int  c;
  7.     public boolean occupied;
  8.     public int smell;
  9.     int avgDist;
  10.     int leeValue;
  11.    
  12.      
  13. int[] xShift = {-1, 0,  0 ,1};
  14. int[] yShift = { 0, 1, -1, 0};
  15.  
  16.     public int xPixel  () {
  17.       return c * 16  + 8;
  18.     }
  19.    
  20.  
  21.     void setLee (int num) {
  22.       leeValue = num;
  23.     }
  24.    
  25.     abstract boolean isValid();
  26.    
  27.     int getLee () {
  28.       return leeValue;
  29.     }
  30.    
  31.     int computeShortestPath( Location g) {
  32.    /* LinkedList<Location> queue = new LinkedList<Location>();
  33.  
  34.     queue.add(f);
  35.     ArrayList<Location> explored = new ArrayList<Location>();
  36.     explored.add(f);
  37.     int i = 0;
  38.     while(!queue.isEmpty()){
  39.       Location current = queue.pollFirst();
  40.             if(current.equals(g)) {
  41.                 return g.getLee();
  42.             }
  43.             else{
  44.                     queue.addAll(current.getNeighbors());
  45.             }
  46.              current.setLee(i );
  47.              i ++
  48.         }
  49.     return g.getLee(); */
  50.    
  51.     return Math.abs(getR() - g.getR()) + Math.abs(getC() - g.getC());
  52.  
  53.     }
  54.  
  55.    
  56.    
  57.     void setAvgDist(int num) {
  58.       avgDist = num;
  59.     }
  60.    
  61.     int getAvgDist() { return avgDist; }
  62.  
  63.     public int yPixel () {
  64.       return r * 16 + 8;
  65.     }
  66.    
  67.     public int getR() {
  68.   return r ;
  69.     }
  70.     public int getC () {
  71.   return c ;
  72.     }
  73.    
  74.      public void setOccupied (boolean o) {
  75.         occupied = o;
  76.       }
  77.     public void setR (int newX) {
  78.   r = newX ;
  79.     }
  80.     public void setC (int y) {
  81.   this.c = y;
  82.     }
  83.    
  84.  
  85.         abstract boolean hasDot();
  86.     public boolean isOccupied () {
  87.       return occupied;
  88.     }
  89.  
  90.      
  91.     public Location (int x, int y) {
  92.         this.r = x;
  93.         this.c = y;    
  94.        
  95.         smell = 0;
  96.     }
  97.     abstract void setDot(Dot d);
  98.     public int getSmell() {
  99.       return smell;
  100.     }
  101.    
  102.     public void  setSmell(int sm) {
  103.       smell = sm;
  104.     }
  105.  
  106.    public  int compareTo (Location other) {
  107.      
  108.      return avgDist - other.avgDist;
  109.    }
  110.  
  111.  
  112. public boolean equals (Location other) {
  113.   return r == other.r && c == other.c;
  114. }
  115.  
  116.  
  117.  public String toString () {
  118.  
  119.     return "(" + r + "," +  c+ ")" ;
  120.     }
  121.  
  122. }
Add Comment
Please, Sign In to add comment