Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Map map;


            //build the map
            MapManager mapManager = new MapManager(10, 5);

            map = mapManager.Create();
            Console.WriteLine(map.ToString());

            Console.ReadLine();

            //PathSearcher ps = new PathSearcher(EHeuristicTypes.InfatedPythagorean, ALLOW_DIAGONAL);
            PathSearcher psPythagDiag    = new PathSearcher(EHeuristicTypes.Pythagorean, ALLOW_DIAGONAL);
            PathSearcher psManhattanDiag = new PathSearcher(EHeuristicTypes.Manhattan, ALLOW_DIAGONAL);
            PathSearcher psManhattanSQ   = new PathSearcher(EHeuristicTypes.Manhattan, !ALLOW_DIAGONAL);

            Map pythagPathMap        = psPythagDiag.SearchPath(map);
            Map manhattanDiagPathMap = psManhattanSQ.SearchPath(map);
            Map manhattanSQPathMap   = psManhattanSQ.SearchPath(map);

            Console.WriteLine(pythagPathMap.ToString());
            Console.WriteLine(manhattanDiagPathMap.ToString());
            Console.WriteLine(manhattanSQPathMap.ToString());

            Console.ReadLine();
        }
Exemplo n.º 2
0
        private IEnumerable <Command> RepairStarship()
        {
            var nearSocket = Map.Walls.Where(x => x.Type.ToLower().Contains(color)).OrderBy(GetDistance).FirstOrDefault();

            if (nearSocket == null)
            {
                return(new Command[0]);
            }
            var path = PathSearcher.FindPath(Map, OurCoordinates, nearSocket.DiscreteCoordinate);

            if (path.Length == 0)
            {
                if (Map.CurrentPosition.X - nearSocket.AbsoluteCoordinate.X > Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Left));
                }
                if (Map.CurrentPosition.X - nearSocket.AbsoluteCoordinate.X < -Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Right));
                }
                if (Map.CurrentPosition.Y - nearSocket.AbsoluteCoordinate.Y > Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Down));
                }
                if (Map.CurrentPosition.Y - nearSocket.AbsoluteCoordinate.Y < -Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Up));
                }
                hasDetail = false;
                return(new[] { Command.Act(CommandAction.Release) });
            }
            return(RobotLocator.GetCommandsByDirection(path.First()));
        }
Exemplo n.º 3
0
        protected override IEnumerable <Command> FindNextCommands()
        {
            var path     = PathSearcher.FindPath(Map, OurCoordinates, OpponentCoordinates);
            var commands = path.Length == 0 ? GoBack() : RobotLocator.GetCommandsByDirection(path.First());

            lastCommand = path.FirstOrDefault();
            return(commands);
        }
Exemplo n.º 4
0
        public void TwoVerticeGraphWithPath()
        {
            var graph = new AdjacencyGraph(2)
                        .AddArrow(0, 1);

            var path = new PathSearcher(graph).FindPath(0, 1);

            Assert.That(path, Is.EqualTo(new[] { 0, 1 }));
        }
Exemplo n.º 5
0
        public void TwoVerticeGraphWithoutPath()
        {
            var graph = new AdjacencyGraph(2)
                        .AddArrow(0, 1);

            var path = new PathSearcher(graph).FindPath(1, 0);

            Assert.That(path, Is.Null);
        }
Exemplo n.º 6
0
 protected override IEnumerable <Command> FindNextCommands()
 {
     while (currentCommand >= currentPath.Length)
     {
         var x = random.Next(1, 7);
         var y = random.Next(1, 5);
         currentPath    = PathSearcher.FindPath(Map, OurCoordinates, new Point(x, y));
         currentCommand = 0;
     }
     return(RobotLocator.GetCommandsByDirection(currentPath[currentCommand++]));
 }
Exemplo n.º 7
0
        public void FourVerticeGraphWhereNotExistsPath()
        {
            var graph = new AdjacencyGraph(4)
                        .AddArrow(1, 0)
                        .AddArrow(2, 0)
                        .AddArrow(2, 1)
                        .AddArrow(2, 3);

            var path = new PathSearcher(graph).FindPath(3, 0);

            Assert.That(path, Is.Null);
        }
Exemplo n.º 8
0
        public void FourVerticeGraphWithPathBetweenZeroAndThird()
        {
            var graph = new AdjacencyGraph(4)
                        .AddArrow(1, 0)
                        .AddArrow(2, 0)
                        .AddArrow(1, 2)
                        .AddArrow(2, 1)
                        .AddArrow(3, 2);

            var path = new PathSearcher(graph).FindPath(3, 0);

            Assert.That(path, Is.EqualTo(new[] { 3, 2, 0 }));
        }
Exemplo n.º 9
0
        private IEnumerable <Command> GripDetail()
        {
            var nearDetail = Map.Details.OrderBy(GetDistance).FirstOrDefault();

            if (nearDetail == null)
            {
                return(new Command[0]);
            }
            color = nearDetail.Type.Split(new[] { "Detail" }, StringSplitOptions.None).First().ToLower();
            var path = PathSearcher.FindPath(Map, OurCoordinates, nearDetail.DiscreteCoordinate);

            hasDetail = path.Length == 0;
            return(hasDetail ? new[] { Command.Act(CommandAction.Grip) } : RobotLocator.GetCommandsByDirection(path.First()));
        }
Exemplo n.º 10
0
 public void Update()
 {
     if (Input.GetKeyDown(KeyCode.R))
     {
         printMap();
     }
     if (Input.GetKeyDown(KeyCode.T))
     {
         Movement mov  = ((Movement)FindObjectOfType(typeof(Movement)));
         Unit     unit = mov.gameObject.GetComponent <Unit> ();
         if (!mov.hasPath())
         {
             PathSearcher             searcher = new PathSearcher(this, unit);
             Queue <Pair <int, int> > path     = searcher.findPath(-1, -1, 0, 0);
             mov.addPath(path);
         }
     }
 }
Exemplo n.º 11
0
        public IEnumerable <Point> GetPath(Point from, Point to)
        {
            if (from == to)
            {
                return(null);
            }

            var key = Tuple.Create(from, to);

            if (buffer.ContainsKey(key))
            {
                return(buffer[key]);
            }


            var path = PathSearcher.Search(@from, to, IsCellFree);

            AddToBuffer(key, path);
            return(path);
        }
Exemplo n.º 12
0
        private static void Main(string[] args)
        {
            var server       = new CvarcClient(args, Settings).GetServer <PositionSensorsData>();
            var sensorData   = server.Run().SensorsData;
            var map          = sensorData.BuildMap();
            var robotLocator = new RobotLocator(map);
            var path         = PathSearcher.FindPath(map, map.GetDiscretePosition(map.CurrentPosition), new Point(2, 1));//(2, 1) - just random point

            foreach (var direction in path)
            {
                foreach (var command in robotLocator.GetCommandsByDirection(direction))
                {
                    sensorData = server.SendCommand(command);
                    robotLocator.Update(sensorData);
                }
            }
            server.SendCommand(new Command {
                Action = CommandAction.WaitForExit
            });
        }
Exemplo n.º 13
0
    IEnumerator GenerateGround()
    {
        TextAsset    mapText = Resources.Load("map") as TextAsset;
        StringReader reader  = new StringReader(mapText.text);

        Vector2 playerPos = new Vector3(0, 0);

        //list for search path
        int rowCount = 0;

        string[] lines = mapText.text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
        rowCount = lines.Length;
        int colCount = 0;

        string[] firstLine = lines[0].Split(',');
        colCount     = firstLine.Length;
        pathSearcher = new PathSearcher(colCount, rowCount);

        int row = 0;

        while (reader.Peek() > -1)
        {
            string     line   = reader.ReadLine();
            string[]   values = line.Split(',');
            int        col    = 0;
            GameObject g;
            int        num;

            /*
             * //for search path
             * if(groundNodeList == null){
             *      groundNodeList = new GroundNode[lineCount, values.Length];
             * }
             */

            foreach (string i in values)
            {
                num = int.Parse(i);
                if (num > 0)
                {
                    //GameObject.Instantiate (Resources.Load ("Prefabs/Ground"), new Vector3(5 + -1 * col, -1, -5 + 1 * row), Quaternion.Euler (new Vector3(0.0f, 180.0f, 0.0f)));
                    g = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/Ground"), new Vector3(5 + -1 * col, 0, -5 + 1 * row), Quaternion.identity);
                    g.SendMessage("SetPos", new Vector2(col, row));
                    g.SendMessage("SetLife", num);
                    iTween.ColorFrom(g, iTween.Hash("a", 0, "time", 0.5f, "easetype", iTween.EaseType.easeInOutCubic));
                    iTween.MoveFrom(g, iTween.Hash("y", g.transform.position.y - 1, "time", 0.5f, "easetype", iTween.EaseType.easeInOutCubic));                                   yield return(new WaitForSeconds(0.02f));

                    switch (num)
                    {
                    case 5:
                        //playerPos = new Vector3(5 + -1 * col, 6, -5 + 1 * row);
                        playerPos = new Vector2(col, row);
                        break;

                    case 6:
                        GameObject.Instantiate(jewelPrefab, new Vector3(5 + -1 * col, 1.5f, -5 + 1 * row), Quaternion.identity);
                        break;

                    default:
                        break;
                    }

                    //groundNodeList[col, row] = new GroundNode(col, row, g);
                    pathSearcher.AddNode(col, row, g);
                }
                col++;
            }    //foreach
            row++;
        }        //while

        player = (GameObject)GameObject.Instantiate(playerPrefab, new Vector3(5 + -1 * playerPos.x, 6, -5 + 1 * playerPos.y), Quaternion.identity);
        player.SendMessage("SetInitCoordinates", playerPos);
        player.SendMessage("SetCurrentCoordinates", playerPos);

        //set neighbor int ground nodes for search path
        pathSearcher.init();
    }
Exemplo n.º 14
0
        protected override IEnumerable <Command> FindNextCommands()
        {
            var path = PathSearcher.FindPath(Map, OurCoordinates, OpponentCoordinates);

            return(path.Length == 0 || path.Length == 1 ? new Command[0] : RobotLocator.GetCommandsByDirection(path.First()));
        }