public static void printDijkstraMap(Map <int> distMap, Wrappy wrappy)
        {
            if (Program.noPrint)
            {
                return;
            }
            System.Console.Out.WriteLine("================ Distance map for wrappy at position (" + wrappy.Loc.x + ", " + wrappy.Loc.y + ") ================");
            if (distMap == null)
            {
                System.Console.Out.WriteLine("================ Could not print dijkstra map ================");
                return;
            }
            for (int i = distMap.H - 1; i >= 0; i--)
            {
                for (int j = 0; j < distMap.W; j++)
                {
                    string tileText;
                    if (distMap[j, i] == Dijkstra.Graph.UNREACHABLE)
                    {
                        tileText = "█";
                    }
                    else
                    {
                        tileText = distMap[j, i].ToString();
                    }

                    System.Console.Out.Write(tileText);
                }
                System.Console.Out.WriteLine("");
            }
            System.Console.Out.WriteLine("");
        }
示例#2
0
        private void Move(Action a, Wrappy w)
        {
            var newLoc = w.Loc + new Point(a);

            if (map.isMovable(newLoc, Tile.Obstacle))  // TOCHECK throwException? // NO, in case of fast wheel
            {
                w.Loc = newLoc;
            }
        }
示例#3
0
 private void updateMap(Wrappy w)
 {
     if (map[w.Loc] == Tile.Obstacle && w.remainingDrill <= 0)
     {
         throw new Exception("Obstacle collision");
     }
     map[w.Loc] = Tile.Filled;
     foreach (Point p in w.Manips)
     {
         Point mp = w.absolutePosition(p);
         if (map.validCoordinate(mp) && map[mp] == Tile.Empty && isVisible(w.Loc, mp))
         {
             map[mp] = Tile.Filled;
         }
     }
 }
示例#4
0
        private void updateStatus(Wrappy w)
        {
            updateMap(w);
            // colleziona il booster se wrappy ci sta sopra
            int i = boosters.FindIndex((kvp) => kvp.Value.Equals(w.Loc));

            if (i >= 0)
            {
                var b = boosters[i];
                collectedBoosters.Add(b.Key);
                if (!(b.Key == Booster.CloningPlatform))
                {
                    boosters.RemoveAt(i);
                }
            }
            // TODO: usare subito i booster semplici: fastwheel e manip
        }
示例#5
0
 private static Action calculateNextAction(Wrappy w, Action a, Point d)
 {
     if (d.x == w.Loc.x - 1 && d.y == w.Loc.y)
     {
         a = Action.A;
     }
     if (d.x == w.Loc.x + 1 && d.y == w.Loc.y)
     {
         a = Action.D;
     }
     if (d.y == w.Loc.y - 1 && d.x == w.Loc.x)
     {
         a = Action.S;
     }
     if (d.y == w.Loc.y + 1 && d.x == w.Loc.x)
     {
         a = Action.W;
     }
     return(a);
 }
        public static void printDijkstraMap(Status status, Wrappy wrappy)
        {
            if (Program.noPrint)
            {
                return;
            }
            Map <Tile> parsedMap = status.map;
            Dictionary <int, Dictionary <int, string> > mappedBoosters = new Dictionary <int, Dictionary <int, string> >();
            List <KeyValuePair <Booster, Point> >       boosters       = status.boosters;

            foreach (var booster in boosters)
            {
                Point boosterLocation = booster.Value;
                if (!mappedBoosters.ContainsKey(boosterLocation.x))
                {
                    mappedBoosters.Add(boosterLocation.x, new Dictionary <int, string>());
                }

                mappedBoosters[boosterLocation.x].Add(boosterLocation.y, getMappedStringValue(booster.Key));
            }
            System.Console.Out.WriteLine("================ POSIZIONE WRAPPY (" + wrappy.Loc.x + ", " + wrappy.Loc.y + ") ================");
            string usingBooster = "WRAPPY STA USANDO: ";

            if (wrappy.remainingFastWheel > 0)
            {
                usingBooster += "FASTWHEEL, ";
            }

            if (wrappy.remainingDrill > 0)
            {
                usingBooster += "DRILL";
            }
            System.Console.Out.WriteLine(usingBooster);
            if (wrappy.DistMap == null)
            {
                System.Console.Out.WriteLine("================ Could not print dijkstra map ================");
                return;
            }
            for (int i = parsedMap.H - 1; i >= 0; i--)
            {
                System.Console.Write(i % 10 + " ");
                for (int j = 0; j < parsedMap.W; j++)
                {
                    string s = ".";
                    if (wrappy.Loc.x == j && wrappy.Loc.y == i)
                    {
                        s = "?";
                    }
                    else
                    {
                        switch (parsedMap[j, i])
                        {
                        case Tile.Empty:
                            if (mappedBoosters.ContainsKey(j) && mappedBoosters[j].ContainsKey(i))
                            {
                                s = mappedBoosters[j][i];
                            }
                            else
                            {
                                int x = wrappy.DistMap[j, i];
                                if (x < 10)
                                {
                                    s = x.ToString();
                                }
                                else if (x == int.MaxValue)
                                {
                                    s = "I";
                                }
                                else
                                {
                                    s = "+";
                                }
                            }
                            break;

                        case Tile.Filled:
                            s = "@";
                            break;

                        case Tile.Obstacle:
                            s = "█";
                            break;
                        }
                    }
                    System.Console.Out.Write(s);
                }
                System.Console.Out.WriteLine("");
            }
            System.Console.Out.Write("  ");
            for (int i = 0; i < parsedMap.W; ++i)
            {
                System.Console.Out.Write(i % 10);
            }
            System.Console.Out.WriteLine("");
            System.Console.Out.Write("ActionHistory: ");
            foreach (var a in wrappy.ActionHistory)
            {
                System.Console.Out.Write(a);
            }
            System.Console.Out.WriteLine("");
        }
示例#7
0
        public void execute(Action a, Wrappy w)
        {
            Move(a, w);
            if (w.remainingFastWheel > 0)
            {
                w.remainingFastWheel--;
                updateStatus(w);
                Move(a, w);
            }
            if (w.remainingDrill > 0)
            {
                w.remainingDrill--;
                //map[w.Loc.x, w.loc.y] = Tile.Filled; // already done by updatemap
            }

            if (a.IsE)
            {
                w.rotateClockwise();
            }
            if (a.IsQ)
            {
                w.rotateAntiClockwise();
            }

            if (a.IsB)
            {
                if (!collectedBoosters.Remove(Booster.Manipulator))
                {
                    throw new Exception("Missing manipulator boost");
                }
                Action.B b = (Action.B)a;
                w.Manips.Add(new Point(b.Item1, b.Item2));
                // TODO: checkare che il punto sia davvero adiacente
            }
            if (a.IsF)
            {
                if (!collectedBoosters.Remove(Booster.FastWheels))
                {
                    throw new Exception("Missing fast wheel boost");
                }
                w.remainingFastWheel += 50;
            }
            if (a.IsL)
            {
                if (!collectedBoosters.Remove(Booster.Drill))
                {
                    throw new Exception("Missing Drill boost");
                }
                w.remainingDrill += 30;
            }
            if (a.IsR)//telepor
            {
                throw new Exception("Teleport not implemented yet");
            }
            if (a.IsC)
            {
                if (!collectedBoosters.Remove(Booster.Cloning))
                {
                    throw new Exception("Missing Cloning boost");
                }
                if (boosters.Find((kvp) => kvp.Value.Equals(w.Loc)).Key != Booster.CloningPlatform)
                {
                    throw new Exception("Cloning not in a platform");
                }
                wrappies.Add(new Wrappy(w.Loc));
            }
            w.ActionHistory.Add(a);
            updateStatus(w);
        }