Esempio n. 1
0
 public override bool Equals(object obj)
 {
     if (obj != null && GetType() == obj.GetType())
     {
         AgentPosition other = (AgentPosition)obj;
         return((getX() == other.getX()) && (getY() == other.getY()) &&
                (orientation == other.getOrientation()));
     }
     return(false);
 }
Esempio n. 2
0
        public ICollection <AgentPosition> getLocationsLinkedTo(AgentPosition fromLocation)
        {
            int x = fromLocation.getX();
            int y = fromLocation.getY();

            AgentPosition.Orientation orientation = fromLocation.getOrientation();

            ICollection <AgentPosition> result = CollectionFactory.CreateQueue <AgentPosition>();

            AgentPosition currentForwardNorth = new AgentPosition(x, y + 1,
                                                                  AgentPosition.Orientation.FACING_NORTH);
            AgentPosition currentForwardSouth = new AgentPosition(x, y - 1,
                                                                  AgentPosition.Orientation.FACING_SOUTH);
            AgentPosition currentForwardEast = new AgentPosition(x + 1, y,
                                                                 AgentPosition.Orientation.FACING_EAST);
            AgentPosition currentForwardWest = new AgentPosition(x - 1, y,
                                                                 AgentPosition.Orientation.FACING_WEST);
            AgentPosition currentNorth = new AgentPosition(x, y,
                                                           AgentPosition.Orientation.FACING_NORTH);
            AgentPosition currentSouth = new AgentPosition(x, y,
                                                           AgentPosition.Orientation.FACING_SOUTH);
            AgentPosition currentEast = new AgentPosition(x, y,
                                                          AgentPosition.Orientation.FACING_EAST);
            AgentPosition currentWest = new AgentPosition(x, y,
                                                          AgentPosition.Orientation.FACING_WEST);

            if (orientation.Equals(AgentPosition.Orientation.FACING_NORTH))
            {
                addIfAllowed(currentForwardNorth, result);
                addIfAllowed(currentEast, result);
                addIfAllowed(currentWest, result);
            }
            else if (orientation.Equals(AgentPosition.Orientation.FACING_SOUTH))
            {
                addIfAllowed(currentForwardSouth, result);
                addIfAllowed(currentEast, result);
                addIfAllowed(currentWest, result);
            }
            else if (orientation.Equals(AgentPosition.Orientation.FACING_EAST))
            {
                addIfAllowed(currentNorth, result);
                addIfAllowed(currentSouth, result);
                addIfAllowed(currentForwardEast, result);
            }
            else if (orientation.Equals(AgentPosition.Orientation.FACING_WEST))
            {
                addIfAllowed(currentNorth, result);
                addIfAllowed(currentSouth, result);
                addIfAllowed(currentForwardWest, result);
            }

            return(result);
        }
Esempio n. 3
0
        /**
         *
         * @param current
         *            the agent's current position
         * @param possibleWumpus
         *            a set of squares where we don't know that there isn't the
         *            wumpus.
         * @param allowed
         *            a set of squares that can form part of the route
         *
         * @return the sequence of actions to reach the nearest square that is in
         *         line with a possible wumpus position. The last action is a shot.
         */
        public ICollection <IAction> planShot(AgentPosition current, ISet <Room> possibleWumpus, ISet <Room> allowed)
        {
            ISet <AgentPosition> shootingPositions = CollectionFactory.CreateSet <AgentPosition>();

            foreach (Room p in possibleWumpus)
            {
                int x = p.getX();
                int y = p.getY();

                for (int i = 1; i <= kb.getCaveXDimension(); i++)
                {
                    if (i < x)
                    {
                        shootingPositions.Add(new AgentPosition(i, y, AgentPosition.Orientation.FACING_EAST));
                    }
                    if (i > x)
                    {
                        shootingPositions.Add(new AgentPosition(i, y, AgentPosition.Orientation.FACING_WEST));
                    }
                    if (i < y)
                    {
                        shootingPositions.Add(new AgentPosition(x, i, AgentPosition.Orientation.FACING_NORTH));
                    }
                    if (i > y)
                    {
                        shootingPositions.Add(new AgentPosition(x, i, AgentPosition.Orientation.FACING_SOUTH));
                    }
                }
            }

            // Can't have a shooting position from any of the rooms the wumpus could
            // reside
            foreach (Room p in possibleWumpus)
            {
                foreach (AgentPosition.Orientation orientation in AgentPosition.Orientation.values())
                {
                    shootingPositions.Remove(new AgentPosition(p.getX(), p.getY(), orientation));
                }
            }

            ISet <Room> shootingPositionsArray = CollectionFactory.CreateSet <Room>();

            foreach (AgentPosition tmp in shootingPositions)
            {
                shootingPositionsArray.Add(new Room(tmp.getX(), tmp.getY()));
            }

            ICollection <IAction> actions = planRoute(current, shootingPositionsArray, allowed);

            AgentPosition newPos = current;

            if (actions.Size() > 0)
            {
                newPos = ((Forward)actions.Get(actions.Size() - 1)).getToPosition();
            }

            while (!shootingPositions.Contains(newPos))
            {
                TurnLeft tLeft = new TurnLeft(newPos.getOrientation());
                newPos = new AgentPosition(newPos.getX(), newPos.getY(), tLeft.getToOrientation());
                actions.Add(tLeft);
            }

            actions.Add(new Shoot());
            return(actions);
        }