Advertisement
SuperJedi224

SimplePathfinder- Sample Bot

Apr 11th, 2015
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4. public class SimplePathfinder extends Bot{
  5.     public SimplePathfinder(){
  6.         this.name="Pathfinder";
  7.     }
  8.     public Action action(int[][] map) {
  9.         List<Position> enemies=new ArrayList<Position>();
  10.         for(int x=1;x<map.length;x++){
  11.             for(int y=1;y<map[x].length;y++){
  12.                 if(map[x][y]!=0&&map[x][y]!=this.id()&&map[x][y]!=-1){
  13.                     enemies.add(new Position(x,y));
  14.                 }
  15.             }
  16.         }
  17.         double d=200;
  18.         Position x=null;
  19.         for(Position pos:enemies){
  20.             if(p.distance(pos)<d){
  21.                 x=pos;
  22.                 d=p.distance(pos);
  23.             }
  24.         }
  25.         if(x==null)return Action.PASS;
  26.         if(x.x<p.x&&map[p.x-1][p.y]!=-1)return Action.LEFT;
  27.         if(x.x>p.x&&map[p.x+1][p.y]!=-1)return Action.RIGHT;
  28.         if(x.y>p.y&&map[p.x][p.y+1]!=-1)return Action.DOWN;
  29.         if(x.y<p.y&&map[p.x][p.y-1]!=-1)return Action.UP;
  30.         List<Action> v=new ArrayList<Action>();
  31.         if(p.y>0&&map[p.x][p.y-1]!=-1)v.add(Action.UP);
  32.         if(p.y<63&&map[p.x][p.y+1]!=-1)v.add(Action.DOWN);
  33.         if(p.x>0&&map[p.x-1][p.y]!=-1)v.add(Action.LEFT);
  34.         if(p.x<63&&map[p.x+1][p.y]!=-1)v.add(Action.RIGHT);
  35.         v.add(Action.PASS);
  36.         if(v.size()==5)v.add(Action.MINE);
  37.         return v.get((new Random()).nextInt(v.size()));
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement