Exemplo n.º 1
0
        public void Loop()
        {
            while (!status.isSolved())
            {
                StatisticalPrettyPrinter.printStats(status);
                foreach (var w in status.wrappies)
                {
                    DijkstraPrettyPrinter.printDijkstraMap(status, w);
                    Action a = null;
                    if (w.LastAction != Action.C)
                    {
                        if (status.collectedBoosters.Contains(Booster.Cloning) &&
                            status.boosters.Exists((kvp) => kvp.Key == Booster.CloningPlatform && kvp.Value.Equals(w.Loc)))
                        {
                            a = Action.C;
                        }
                        else if (status.collectedBoosters.Contains(Booster.FastWheels))
                        {
                            a = Action.F;
                        }
                        else if (status.collectedBoosters.Contains(Booster.Manipulator))
                        {
                            w.Manips.Sort((p1, p2) => - (p1.y - p2.y));
                            a = Action.NewB(w.Manips[0].x, w.Manips[0].y + 1);
                        }
                    }
                    if (a == null)
                    {
                        w.updateDistMap(status);
                        //DijkstraPrettyPrinter.printDijkstraMap(status, w);
                        Wrappy.PriPath pp = w.BestShortestPath();
                        int            i  = 0;
                        Point          d  = pp.path[i];

                        if (d.x == w.Loc.x - 1 && d.y == w.Loc.y)
                        {
                            a = Action.A;
                        }
                        else if (d.x == w.Loc.x + 1 && d.y == w.Loc.y)
                        {
                            a = Action.D;
                        }
                        else if (d.y == w.Loc.y - 1 && d.x == w.Loc.x)
                        {
                            a = Action.S;
                        }
                        else if (d.y == w.Loc.y + 1 && d.x == w.Loc.x)
                        {
                            a = Action.W;
                        }
                        else
                        {
                            throw new Exception("unexpected: non puo' non esserci una action");
                        }

                        //a = calculateNextAction(w, a, d);
                        //++i;
                        //while (this.invertAction(a) == w.LastAction && i < pp.path.Count)
                        //{

                        //    a = calculateNextAction(w, a, pp.path[i]);
                        //    i++;
                        //}
                    }
                    status.execute(a, w);
                    status.CalculateGoals();
                }
            }
            StatisticalPrettyPrinter.printStats(status);
            DijkstraPrettyPrinter.printDijkstraMap(status, status.wrappies[0]);
        }