public void reset() { if (start == null) return; circle = new Circle2D(start); caught = false; dynamic = true; }
public void init(int id, double nx, double ny, double dir, AgentBrain agentBrain, Environment environment, float sensorNoise, float effectorNoise, float headingNoise, float timeStep) { steps = 0; this.id = id; radius = defaultRobotSize(); location = new Point2D(nx, ny); circle = new Circle2D(location, radius); old_location = new Point2D(location); heading = dir; velocity = 0.0; collide_last = false; this.timeStep = timeStep; this.environment = environment; this.agentBrain = agentBrain; this.sensorNoise = sensorNoise; this.effectorNoise = effectorNoise; this.headingNoise = headingNoise; populateSensors(); if(environment.seed != -1) rng=environment.rng; //new SharpNeatLib.Maths.FastRandom(environment.seed); //Utilities.random; else rng=environment.rng; //new SharpNeatLib.Maths.FastRandom(); }
//test if circle collides with other circle //used in robot collision detection public bool collide(Circle2D other) { double dx = other.p.x - p.x; double dy = other.p.y - p.y; dx*=dx; dy*=dy; double rad_sum = other.radius+radius; rad_sum*=rad_sum; if ((dx+dy)<rad_sum) return true; return false; }
public Prey(double x, double y, double rad, double range, double speed, bool vis, string n) { this.name = n; this.colored = false; this.dynamic = true; this.caught = false; this.visible = vis; this.speed = speed; this.range = range; Point2D p = new Point2D(x, y); this.circle = new Circle2D(p, rad); this.location = circle.p; }
public Prey(Prey k) { name = k.name; colored = false; circle = new Circle2D(k.circle); caught = k.caught; location = circle.p; range = k.range; speed = k.speed; dynamic = !caught; visible = k.visible; }
public void update(List<Robot> rbts, double timestep) { if (start == null) start = new Circle2D(circle); Robot closest = null; double closestDist = range; foreach (Robot r in rbts) { double dist = circle.p.distance(r.location); //Console.WriteLine("dist: " + dist); if (dist <= closestDist) { closestDist = dist; closest = r; } } if (closestDist <= (circle.radius + rbts[0].radius)) { caught = true; dynamic = false; return; } if (closest != null) { double dA = circle.p.x - closest.location.x; double dB = circle.p.y - closest.location.y; double c = closest.location.distance(circle.p); double z = speed * timestep; double dX = (dA * z) / c; double dY = (dB * z) / c; Point2D newP = new Point2D(dX + circle.p.x, dY + circle.p.y); circle.p = newP; } }
//calculate the nearest intersection of this line //with a circle -- if the line is interpreted as a ray //going from its first endpoint to the second public double nearest_intersection(Circle2D C,out bool found) { double dx,dy; dx=p2.x-p1.x; dy=p2.y-p1.y; double px=p1.x-C.p.x; double py=p1.y-C.p.y; double a= dx*dx + dy*dy; double b= 2*px*dx+2*py*dy; double c= px*px + py*py - C.radius*C.radius; double det = b*b-4.0*a*c; if(det<0.0) { found=false; return -1.0; } double sqrt_det = Math.Sqrt(det); double t1 = (-b+sqrt_det)/(2*a); double t2 = (-b-sqrt_det)/(2*a); found=false; double t=0.0; if(t2<0) { if(t1>0) { found=true; t=t1; } } else { found=true; t=t2; } if(!found) return -1.0; return t*Math.Sqrt(dx*dx+dy*dy); }
public Circle2D(Circle2D other) { p=other.p; radius=other.radius; }
public Circle2D(Circle2D other) { p = other.p; radius = other.radius; }