示例#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
        /// <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());
                }
            }
        }
示例#3
0
        public void AddExploredLocation(LocationStatic location)
        {
            foreach (var loc in exploredRooms)
            {
                if (loc.GetName() == location.GetName())
                {
                    return;
                }
            }

            exploredRooms.Add(location);
            UpdateHashCode();
        }