/** * Hunter-Prey simulator version 1.1 * Copyright 2011 Kenneth Mackin */ public class PreyAgent extends Agent{ int VIEWRANGE = 4; PreyAgent(Field field, int x, int y, int index){ super(field, x, y, index); } public void move(){ int xdir=0; int ydir=0; for(int i=1; i< field.getAgents(); i++){ if((Math.abs(field.getX(i) - this.x) <= VIEWRANGE) && (Math.abs(field.getY(i) - this.y) <= VIEWRANGE) ){ if(field.getX(i)<(this.x)){ xdir++; }else if(field.getX(i)>(this.x)){ xdir--; } if(field.getY(i)<(this.y)){ ydir++; }else if(field.getY(i)>(this.y)){ ydir--; } } } if(xdir<0){ this.x--; }else if(xdir>0){ this.x++; } if(ydir<0){ this.y--; }else if(ydir>0){ this.y++; } } }