public bool BeenToTarget(Location currentLocation, TurnAction action) { var loc = MovementTool.ApplyMovement(currentLocation, action); var value = LocationsTracker.Count(s => s.X == loc.X && s.Y == loc.Y) > 0; return(value); }
public TurnAction GetNextDirection(IList <TurnAction> movements, Location loc) { LocationsTracker.Push(loc);//Register location as visited if (movements.Count == 1) { try { var now = MovementTool.Reverse(ActionTracker.Pop()); StepTracker.Push(new TrackedLocation(loc, now)); return(now); }catch (Exception e) { var now = movements[0]; StepTracker.Push(new TrackedLocation(loc, now)); ActionTracker.Push(now); return(now); } } var trimHasBeen = movements.Where(s => !BeenToTarget(loc, s)).ToList(); if (trimHasBeen.Count == 0) { var now = MovementTool.Reverse(ActionTracker.Pop()); StepTracker.Push(new TrackedLocation(loc, now)); return(now); } TurnAction dirToGoBias; try { dirToGoBias = MovementTool.Leftify(ActionTracker.Peek()); } catch (Exception) { dirToGoBias = movements[new Random().Next(movements.Count)]; } var value = trimHasBeen.Contains(dirToGoBias) ? dirToGoBias : trimHasBeen[new Random().Next(trimHasBeen.Count)]; StepTracker.Push(new TrackedLocation(loc, value)); ActionTracker.Push(value); return(value); }