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 });
        }
Ejemplo n.º 2
0
 void Start()
 {
     findGauge        = GameObject.Find("FindGauge");
     devLog           = GetComponent <DevLog>();
     pickUpController = GetComponent <PickUpController>();
     nextController   = GetComponent <NextController>();
 }
Ejemplo n.º 3
0
    string targetTag; // 拾う対象のタグ

    void Start()
    {
        pickUpButton = GameObject.Find("PickUpButton");
        pickUpButton.SetActive(false);

        nextController = GetComponent <NextController>();
    }
        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 });
        }
Ejemplo n.º 5
0
        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);
        }
    }
Ejemplo n.º 6
0
        public async Task NextControllerGetPassesRequestToService()
        {
            var request    = new StationBoardRequest();
            var service    = A.Fake <IStationBoardService>();
            var controller = new NextController(A.Fake <ILogger <NextController> >(), service);

            await controller.Get(request);

            A.CallTo(() => service.GetNextDeparturesAsync(request)).MustHaveHappenedOnceExactly();
        }
Ejemplo n.º 7
0
        public async Task NextControllerGetReturnsResponseFromService()
        {
            var request  = new StationBoardRequest();
            var response = new BaseStationBoard();
            var service  = A.Fake <IStationBoardService>();

            A.CallTo(() => service.GetNextDeparturesAsync(request)).Returns(response);
            var controller = new NextController(A.Fake <ILogger <NextController> >(), service);

            var board = await controller.Get(request);

            Assert.Equal(response, board);
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
 void Start()
 {
     devLog         = GetComponent <DevLog>();
     fadeController = GetComponent <FadeController>();
     nextController = GetComponent <NextController>();
 }
Ejemplo n.º 10
0
 void Start()
 {
     nextController = GetComponent <NextController>();
     centerRay      = GetComponent <CenterRay>();
     devLog         = GetComponent <DevLog>();
 }