コード例 #1
0
        /// <summary>
        /// A method that returns a random location, excluding the specified one.
        /// </summary>
        /// <param name="excludedLocation"></param>
        public LocationStatic GetRandomLocationWithout(LocationStatic excludedLocation)
        {
            // Create an instance of the Random Number Generator.
            Random random = new Random();

            // Create a list in which we write down the names of all locations.
            List <string> locationsNames = new List <string>();

            // In the loop we go through all the locations.
            foreach (var location in locationsInWorld)
            {
                // If the name of the location in question does not match the name of the excluded location.
                if (location.GetName() != excludedLocation.GetName())
                {
                    // By adding their names to the previously created list.
                    locationsNames.Add(location.GetName());
                }
            }

            // We get the index - a random number, in the range from 0 to the number of locations minus one (due to the indexing of arrays from 0).
            int index = random.Next(locationsNames.Count());

            // We get the name of a randomly selected location (by a randomly generated index), search for it by name and return it.
            return(GetLocationByName(locationsNames[index]));
        }
コード例 #2
0
 public AgentStateDynamic(AgentStateDynamic clone)
 {
     agentInfo          = (AgentStateStatic)clone.agentInfo.Clone();
     myCurrentPlan      = (Plan)clone.myCurrentPlan.Clone();
     myAvailableActions = new List <PlanAction>(clone.myAvailableActions);
     alive         = clone.alive;
     myGoals       = (Goal)clone.myGoals.Clone();
     beliefs       = (WorldContext)clone.beliefs.Clone();
     initiative    = clone.initiative;
     angryAt       = (AgentAngryAt)clone.angryAt.Clone();
     scared        = clone.scared;
     foundEvidence = (AgentFoundEvidence)clone.foundEvidence.Clone();
     if (clone.wantsToGo != null)
     {
         wantsToGo = (LocationStatic)clone.wantsToGo.Clone();;
     }
     else
     {
         wantsToGo = new LocationStatic();
     }
     exploredRooms = new HashSet <LocationStatic>(clone.exploredRooms);
     wantToEntrap  = (WantToEntrap)clone.wantToEntrap.Clone();
     talkingWith   = (TalkingWith)clone.talkingWith.Clone();
     hasHashCode   = clone.hasHashCode;
     hashCode      = clone.hashCode;
     skipedTurns   = clone.skipedTurns;
     timeToMove    = clone.timeToMove;
 }
コード例 #3
0
 public WorldContext()
 {
     myLocation = new LocationStatic();
     anotherAgentsInMyLocation = new HashSet <AgentStateStatic>();
     agentsInWorld             = new HashSet <BeliefsAboutAgent>();
     locationsInWorld          = new HashSet <LocationStatic>();
 }
コード例 #4
0
 public BeliefsAboutAgent()
 {
     info       = new AgentStateStatic();
     role       = AgentRole.USUAL;
     isAlive    = true;
     inLocation = new LocationStatic();
     angryAt    = new AgentAngryAt();
 }
コード例 #5
0
 public BeliefsAboutAgent(BeliefsAboutAgent clone)
 {
     info       = (AgentStateStatic)clone.info.Clone();
     role       = clone.role;
     isAlive    = clone.isAlive;
     inLocation = (LocationStatic)clone.inLocation.Clone();
     angryAt    = (AgentAngryAt)clone.angryAt.Clone();
 }
コード例 #6
0
 /// <summary>
 /// Constructor method for the dynamic part of the location,
 /// as a parameter using the values for the flag about the presence of evidence and a link to the static part of the location.
 /// </summary>
 /// <param name="containEvidence"></param>
 /// <param name="locationInfo"></param>
 public LocationDynamic(bool containEvidence, LocationStatic locationInfo)
 {
     this.locationInfo    = locationInfo;
     agentsAtLocations    = new Dictionary <AgentStateStatic, AgentStateDynamic>();
     this.containEvidence = containEvidence;
     hasHashCode          = false;
     hashCode             = 0;
 }
コード例 #7
0
 public LocationDynamic(LocationDynamic clone)
 {
     locationInfo      = (LocationStatic)clone.locationInfo.Clone();
     agentsAtLocations = new Dictionary <AgentStateStatic, AgentStateDynamic>(clone.agentsAtLocations);
     containEvidence   = clone.containEvidence;
     hasHashCode       = clone.hasHashCode;
     hashCode          = clone.hashCode;
 }
コード例 #8
0
 /// <summary>
 /// Constructor method for the dynamic part of the location, without parameters.
 /// </summary>
 public LocationDynamic()
 {
     locationInfo      = new LocationStatic();
     agentsAtLocations = new Dictionary <AgentStateStatic, AgentStateDynamic>();
     containEvidence   = false;
     hasHashCode       = false;
     hashCode          = 0;
 }
コード例 #9
0
 public WantToEntrap(bool entraping, AgentStateStatic whom, LocationStatic where)
 {
     this.entraping = entraping;
     this.whom      = whom;
     this.where     = where;
     hasHashCode    = false;
     hashCode       = 0;
 }
コード例 #10
0
 public BeliefsAboutAgent(AgentStateStatic info, AgentRole role, bool isAlive, LocationStatic inLocation, AgentAngryAt angryAt)
 {
     this.info       = info;
     this.role       = role;
     this.isAlive    = isAlive;
     this.inLocation = inLocation;
     this.angryAt    = angryAt;
 }
コード例 #11
0
 public WantToEntrap()
 {
     entraping   = false;
     whom        = new AgentStateStatic();
     where       = new LocationStatic();
     hasHashCode = false;
     hashCode    = 0;
 }
コード例 #12
0
 public NeutralizeKiller(ref KeyValuePair <AgentStateStatic, AgentStateDynamic> agent,
                         ref KeyValuePair <AgentStateStatic, AgentStateDynamic> killer,
                         ref LocationStatic location)
 {
     Arguments.Add(agent);
     Arguments.Add(killer);
     Arguments.Add(location);
 }
コード例 #13
0
 public CounterNeutralizeKiller(ref KeyValuePair <AgentStateStatic, AgentStateDynamic> agent,
                                ref KeyValuePair <AgentStateStatic, AgentStateDynamic> killer,
                                ref LocationStatic location,
                                string originalAction)
 {
     Arguments.Add(agent);
     Arguments.Add(killer);
     Arguments.Add(location);
     Arguments.Add(originalAction);
 }
コード例 #14
0
 public bool EntrapingCheckAtLocation(LocationStatic location)
 {
     if (entraping && location == where)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #15
0
        public bool SearchAmongExploredLocations(LocationStatic location)
        {
            for (int i = 0; i < exploredRooms.Count(); i++)
            {
                if (exploredRooms.ElementAt(i) == location)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #16
0
        public bool CheckIfLocationIsExplored(LocationStatic location)
        {
            foreach (var loc in exploredRooms)
            {
                if (loc.Equals(location))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #17
0
        public void AddExploredLocation(LocationStatic location)
        {
            foreach (var loc in exploredRooms)
            {
                if (loc.GetName() == location.GetName())
                {
                    return;
                }
            }

            exploredRooms.Add(location);
            UpdateHashCode();
        }
コード例 #18
0
        public KeyValuePair <LocationStatic, LocationDynamic> GetLocation(LocationStatic locationKey)
        {
            foreach (var location in currentStateOfLocations)
            {
                if (location.Key.Equals(locationKey))
                {
                    return(location);
                }
            }

            throw new KeyNotFoundException();

            //return currentStateOfLocations[locationKey];
        }
コード例 #19
0
 public WorldContext(WorldContext clone)
 {
     if (clone.myLocation != null)
     {
         myLocation = (LocationStatic)clone.myLocation.Clone();
     }
     else
     {
         myLocation = new LocationStatic();
     }
     anotherAgentsInMyLocation = new HashSet <AgentStateStatic>(clone.anotherAgentsInMyLocation);
     agentsInWorld             = new HashSet <BeliefsAboutAgent>(clone.agentsInWorld);
     locationsInWorld          = new HashSet <LocationStatic>(clone.locationsInWorld);
 }
コード例 #20
0
        public void AddLocations(Dictionary <LocationStatic, LocationDynamic> locations)
        {
            foreach (var location in locations)
            {
                LocationStatic  sPrefab = (LocationStatic)location.Key.Clone();
                LocationDynamic dPrefab = (LocationDynamic)location.Value.Clone();
                currentStateOfLocations.Add(sPrefab, dPrefab);

                // Очистка
                sPrefab = null;
                dPrefab = null;
                GC.Collect();
            }

            UpdateHashCode();
        }
コード例 #21
0
        /// <summary>
        /// A method that verifies that all locations in the transferred set are connected (there is a way that can bypass all locations).
        /// </summary>
        public bool pathExistenceControlling(Dictionary <LocationStatic, LocationDynamic> locations)
        {
            bool result = false;

            // We create a queue and a set of visited locations.
            Queue <LocationStatic>   queue            = new Queue <LocationStatic>();
            HashSet <LocationStatic> visitedLocations = new HashSet <LocationStatic>();

            // We will use the first location from the list of locations as the root.
            LocationStatic root = locations.First().Key;

            // Add the root to the queue and the list of visited locations.
            queue.Enqueue(root);
            visitedLocations.Add(root);

            // As long as there is a location in the queue.
            while (queue.Count > 0)
            {
                // We take the location from the queue.
                LocationStatic currentLocation = queue.Dequeue();

                // We go through all the locations associated with the checked location.
                foreach (LocationStatic nextLocation in currentLocation.GetConnectedLocations())
                {
                    // If we have already visited one of these locations, then we just continue.
                    if (visitedLocations.Contains(nextLocation))
                    {
                        continue;
                    }

                    // Otherwise, add a new "unknown" location to the queue and the list of visited locations.
                    queue.Enqueue(nextLocation);
                    visitedLocations.Add(nextLocation);
                }
            }

            // If the number of locations visited during the passage is equal to the total number of locations, then the check was successful.
            if (visitedLocations.Count == locations.Count)
            {
                result = true;
            }

            return(result);
        }
コード例 #22
0
        /// <summary>
        /// Updates the agent's beliefs about the location where he is.
        /// </summary>
        public void RefreshBeliefsAboutTheWorld(WorldDynamic currentWorldState, KeyValuePair <AgentStateStatic, AgentStateDynamic> agent)
        {
            // Before clearing the information, remember the location in which the agent is located.
            //LocationStatic agentIsHereLoc = agent.Value.GetBeliefs().SearchAgentAmongLocations(agent.Key);
            LocationStatic agentIsHereLoc = currentWorldState.GetLocationByName(currentWorldState.SearchAgentAmongLocations(agent.Key).GetName()).Key;

            // We clear the information about the location in which the agent is located, in his beliefs.
            agent.Value.GetBeliefs().GetAgentByName(agent.Key.GetName()).ClearLocation();

            // We find the same location in the "real" world. We go through the agents in it. We are looking for agents
            //    with the same names in the agent's beliefs. We add them to the location (in his beliefs) where he (in his belief) is.
            foreach (var agent1 in currentWorldState.GetLocationByName(agentIsHereLoc.GetName()).Value.GetAgents())
            {
                foreach (var agent2 in agent.Value.GetBeliefs().GetAgentsInWorld())
                {
                    if (agent1.Key.GetName() == agent2.GetInfo().GetName())
                    {
                        agent.Value.GetBeliefs().GetAgentByName(agent2.GetInfo().GetName()).SetLocation(agentIsHereLoc);

                        if (!agent2.CheckStatus())
                        {
                            foreach (var a in currentWorldState.GetAgents())
                            {
                                a.Value.GetBeliefs().GetAgentByName(agent2.GetInfo().GetName()).Dead();
                            }
                        }

                        break;
                    }
                }
            }

            foreach (var agent1 in agent.Value.GetBeliefs().GetAgentsInWorld())
            {
                if (agent1.GetLocation().GetName() == agentIsHereLoc.GetName() &&
                    currentWorldState.GetAgentByName(agent1.GetInfo().GetName()).Value.GetMyLocation().GetName() != agentIsHereLoc.GetName() &&
                    agent.Key.GetName() != agent1.GetInfo().GetName())
                {
                    agent1.SetLocation(currentWorldState.GetLocationByName(agentIsHereLoc.GetName()).Key.GetRandomConnectedLocation());
                }
            }
        }
コード例 #23
0
 /// <summary>
 /// Parameterless constructor.
 /// </summary>
 public AgentStateDynamic()
 {
     agentInfo          = new AgentStateStatic();
     myCurrentPlan      = new Plan();
     myAvailableActions = new List <PlanAction>();
     alive         = true;
     myGoals       = new Goal();
     beliefs       = new WorldContext();
     initiative    = 0;
     angryAt       = new AgentAngryAt();
     scared        = false;
     foundEvidence = new AgentFoundEvidence();
     wantsToGo     = new LocationStatic();
     exploredRooms = new HashSet <LocationStatic>();
     wantToEntrap  = new WantToEntrap();
     talkingWith   = new TalkingWith();
     hasHashCode   = false;
     hashCode      = 0;
     skipedTurns   = 0;
     timeToMove    = 2;
 }
コード例 #24
0
        /// <summary>
        /// A method that creates a set of ready-made locations.
        /// </summary>
        public Dictionary <LocationStatic, LocationDynamic> CreateLocationSet(List <string> locationNames, List <bool> locationsEvidences)
        {
            // Create an empty set of locations.
            Dictionary <LocationStatic, LocationDynamic> locations = new Dictionary <LocationStatic, LocationDynamic>();

            // We create a location the required number of times, using the constructors of its static and dynamic parts, and then add it to the set.
            for (int i = 0; i < locationNames.Count; i++)
            {
                LocationStatic  newLocationStatic  = new LocationStatic(locationNames[i]);
                LocationDynamic newLocationDynamic = new LocationDynamic(locationsEvidences[i], newLocationStatic);
                locations.Add(newLocationStatic, newLocationDynamic);
            }

            // Shuffle the locations in the set in random order.
            OrderLocationsRandom(ref locations);

            // We establish connections between locations.
            locations = LocationsConnection(locations);

            // We return the ready-made set of locations.
            return(locations);
        }
コード例 #25
0
 public WantToEntrap(WantToEntrap clone)
 {
     entraping = clone.entraping;
     if (clone.whom != null)
     {
         whom = (AgentStateStatic)clone.whom.Clone();
     }
     else
     {
         whom = new AgentStateStatic();
     }
     if (clone.where != null)
     {
         where = (LocationStatic)clone.where.Clone();
     }
     else
     {
         where = new LocationStatic();
     }
     hasHashCode = clone.hasHashCode;
     hashCode    = clone.hashCode;
 }
コード例 #26
0
 public void SetMyLocation(LocationStatic location)
 {
     myLocation = location;
 }
コード例 #27
0
 public void ClearLocation()
 {
     inLocation = null;
 }
コード例 #28
0
 public void SetLocation(LocationStatic location)
 {
     inLocation = location;
 }
コード例 #29
0
 public void AddLocationInWorld(LocationStatic location)
 {
     locationsInWorld.Add(location);
 }
コード例 #30
0
 public void ClearMyLocation()
 {
     myLocation = null;
 }