Пример #1
0
        private List <string> createMovementPath()
        {
            List <string> path = new List <string>();

            for (int i = 0; i < knownPositions.Count() - 1; i++)
            {
                Position current = knownPositions.ElementAt(i);
                Position next    = knownPositions.ElementAt(i + 1);

                if (current.getLeft().Equals(next))
                {
                    path.Add("Left");
                }
                if (current.getRight().Equals(next))
                {
                    path.Add("Right");
                }
                if (current.getUp().Equals(next))
                {
                    path.Add("Up");
                }
                if (current.getDown().Equals(next))
                {
                    path.Add("Down");
                }
            }
            return(path);
        }
Пример #2
0
        public override string[] calculatePath()
        {
            List <string> path   = new List <string>();
            Random        random = new Random(DateTime.Now.Millisecond);

            while (goalPos.Count > 0)
            {
                int agentPosX = agent.getPosition().getX();
                int agentPosY = agent.getPosition().getY();

                if (valueMap[agentPosX][agentPosY]++ > 10000)
                {
                    break;
                }

                int left, right, up, down;

                Position checkingPosition = agent.getPosition();
                if (!isWall(checkingPosition.getLeft()))
                {
                    left = random.Next(1, 1000);
                }
                else
                {
                    left = 0;
                }
                if (!isWall(checkingPosition.getRight()))
                {
                    right = random.Next(1, 1000);
                }
                else
                {
                    right = 0;
                }
                if (!isWall(checkingPosition.getUp()))
                {
                    up = random.Next(1, 1000);
                }
                else
                {
                    up = 0;
                }
                if (!isWall(checkingPosition.getDown()))
                {
                    down = random.Next(1, 1000);
                }
                else
                {
                    down = 0;
                }

                switch (getBestDirection(right, left, up, down))
                {
                case RIGHT:
                    agent.goRight();
                    break;

                case LEFT:
                    agent.goLeft();
                    break;

                case UP:
                    agent.goUp();
                    break;

                case DOWN:
                    agent.goDown();
                    break;

                default:
                    break;
                }

                if (goalPos.Contains(agent.getPosition()))
                {
                    path.AddRange(agent.getPath());
                    agent.reset(agent.getPosition());
                    goalPos.Remove(agent.getPosition());
                }
            }
            return(path.ToArray());
        }
Пример #3
0
 public void goDown()
 {
     position = position.getDown();
     clearUselessPathOptions();
     knownPositions.Add(position);
 }