public IEnumerable <RobotAction> GetNextActions(Robot robot) { if (ActionsCache == null || ActionsCache.Count == 0) { ActionsCache = new Queue <RobotAction>(NextController.GetNextActions(robot).ToList()); } var currentAction = ActionsCache.Dequeue(); var currentScore = Problem.ScoreAction(robot, currentAction); // get scores for turn actions var actions = new[] { RobotAction.TurnLeft, RobotAction.TurnRight }; var bestScore = currentScore; var bestAction = currentAction; for (int i = 0; i < actions.Length; i++) { var score = Problem.ScoreAction(robot, actions[i]); if (score > 0 && score >= bestScore) { bestScore = score; bestAction = actions[i]; ActionsCache.Clear(); } } return(new[] { bestAction }); }
public IEnumerable <RobotAction> GetNextActions(Robot robot) { var currentAction = NextController.GetNextActions(robot).First(); var currentScore = Problem.ScoreAction(robot, currentAction); // get scores for turn actions var actions = new[] { RobotAction.TurnLeft, RobotAction.TurnRight }; var bestScore = currentScore; var bestAction = currentAction; for (int i = 0; i < actions.Length; i++) { var score = Problem.ScoreAction(robot, actions[i]); if (score > 0 && score >= bestScore) { bestScore = score; bestAction = actions[i]; } } return(new[] { bestAction }); }
public IEnumerable <RobotAction> GetNextActions(Robot robot) { robot.Targets = null; robot.Target = null; // gimme all the empty cells within x moves var empties = DijkstraPathfinder.FindUnwrappedCellsWithin(robot.Position, Problem.Map, int.MaxValue, false); if (empties.Count == 0) { return new[] { RobotAction.Done, } } ; var islands = new List <HashSet <Point> >(); foreach (var t in empties) { // point is already in an island bool found = false; foreach (var island in islands) { if (island.Contains(t)) { found = true; break; } } if (found) { continue; } var np = DijkstraPathfinder.FindUnwrappedCellsWithin(t, Problem.Map, int.MaxValue, true); islands.Add(new HashSet <Point>(np)); } // no islands, do something else if (islands.Count == 0) { return(NextController.GetNextActions(robot)); } // find smallest island var smallestIsland = islands.OrderBy(x => x.Count).First(); robot.Targets = smallestIsland; // dij a path to it var route = DijkstraPathfinder.RouteToClosestCell(robot.Position, smallestIsland, Problem.Map); robot.Target = route.Item1; // go to there return(route.Item2); } }
public IEnumerable <RobotAction> GetNextActions(Robot robot) { var bestScore = 0; var bestActions = (List <RobotAction>)null; var routeActions = NextController.GetNextActions(robot); foreach (var actions in ActionList) { var score = Problem.ScoreActions(robot, actions, robot.Targets); if ((score - actions.Count) > 1 && (score - actions.Count) > bestScore) { bestScore = (score - actions.Count); bestActions = actions; } } if (bestScore > 0) { return(bestActions.Take(1)); } return(routeActions.Take(1)); }