static public double Distance(Grid A, Grid B) { Vector Avec = Convert2.toVector(A); Vector Bvec = Convert2.toVector(B); Vector C = Vector.Subtract(Avec, Bvec); return(Math.Sqrt(Math.Pow(C.X, 2) + Math.Pow(C.Y, 2))); }
public void think() { double distanceFromFood, distanceFromTarget; target = AquireTarget(); FoodPosition = Convert2.toVector(target); distanceFromFood = Measure2.Distance(WhereAmI, FoodPosition); TargetPosition = FoodPosition; distanceFromTarget = distanceFromFood; LastReassurance++; switch (WhatAmIDoing) { case "WALK": if (distanceFromTarget <= 0.001) { _whatToDo = "STOP"; } else if (distanceFromTarget > WalkingSpeed) { _whatToDo = "WALK"; } break; case "STOP": if (distanceFromTarget > WalkingSpeed) { _whatToDo = "EVOLVE"; } else { _timeStopped++; } break; case "EVOLVE": if (_timeToEvolve < _timeStopped * 10) { MySize += 1 / _timeStopped / 10; BiteSize += 1 / _timeStopped / 10000; WalkingSpeed += 1 / _timeStopped / 100000; _timeToEvolve++; _whatToDo = "EVOLVE"; } else { _timeToEvolve = 0; _timeStopped = 0; _whatToDo = "WALK"; } break; default: _whatToDo = "WALK"; break; } }
public void walk(Vector Target) { var newPosition = brain.move(ActualPosition, Target, Speed); pos.X -= newPosition.X; pos.Y -= newPosition.Y; RenderTransform = pos; ActualPosition = Convert2.toVector(this); }
private Food DecideFood() { List <double> foodPos = new List <double>(); List <double> foodSize = new List <double>(); List <Food> SuperFoods = new List <Food>(); List <Food> FoodsToCheck = new List <Food>(); Food targetFood, nearestFood; foreach (Food food in Foods) { if (food.IsSuperFood) { SuperFoods.Add(food); } } if (SuperFoods.Count > 0) { FoodsToCheck = SuperFoods; _targetIsSuperFood = true; } else { FoodsToCheck = Foods; _targetIsSuperFood = false; } foreach (Food food in FoodsToCheck) { foodPos.Add(Measure2.Distance(WhereAmI, Convert2.toVector(food))); } int nearestFoodID = foodPos.IndexOf(foodPos.Min()); nearestFood = FoodsToCheck[nearestFoodID]; targetFood = nearestFood; return(targetFood); }
static public Vector RelativePosition(Grid me, System.Drawing.Point Target) { Point targetAsPoint = Convert2.toPoint(Target); return(new Vector(me.PointFromScreen(targetAsPoint).X, me.PointFromScreen(targetAsPoint).Y)); }
static public Vector RelativePosition(Grid A, Grid B) { Point BPos = Convert2.toPoint(B); return(new Vector(A.PointFromScreen(BPos).X, A.PointFromScreen(BPos).Y)); }
static public Vector RelativePosition(Grid me, Vector Target) { Point TargetAsPoint = Convert2.toPoint(Target); return(Convert2.toVector(me.PointFromScreen(TargetAsPoint))); }