Beispiel #1
0
 /// <summary>
 /// Collects goals from all agents and adds them to the goal list.
 /// </summary>
 public void ExtractGoals(WorldDynamic currentState)
 {
     foreach (var agent in currentState.GetAgents())
     {
         allGoalStates.Add(agent.Value.GetGoal());
     }
 }
Beispiel #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());
                }
            }
        }
        /// <summary>
        /// A method that creates an initial state of the world based on user preferences.
        /// </summary>
        public void CreateInitialState()
        {
            if (manualInput) // Demo story
            {
                // === LOCATIONS CREATING ===

                // We create locations, determine their names and the presence of evidence in them.
                List <string> locationNames      = CreateLocationsNamesList(locationsCounter);
                List <bool>   locationsEvidences = CreateLocationsEvidencesList(locationsCounter);
                Dictionary <LocationStatic, LocationDynamic> locations = CreateLocationSet(locationNames, locationsEvidences);

                // The first step in creating the initial state is setting up the environment, that is - locations.
                CreateEnviroment(locations);

                // === AGENTS CREATING ===

                // We create sets of attributes for agents: names, states, roles, goals, and beliefs.
                List <string>       names    = CreateAgentsNamesList(agentsCounter);
                List <bool>         statuses = CreateStatusesList(agentsCounter);
                List <AgentRole>    roles    = CreateAgentsRolesList(agentsCounter);
                List <Goal>         goals    = CreateGoalSet(roles);
                List <WorldContext> beliefs  = CreateBeliefsSet(agentsCounter);

                // The second step in creating the initial state is the creation of agents, initially with empty goals and beliefs,
                //    since they are highly dependent on the agents themselves existing in the "world". We'll finish setting this up in the next step.
                CreateAgents(names, statuses, roles, goals, beliefs, GetRandomLocationName(locationNames), agentsCounter);

                // We randomly assign an initiative value to the agents to determine the order of their turn, and sort the agents on the initiative.
                DistributionOfInitiative();
                currentStoryState.OrderAgentsByInitiative();

                // The third step in creating an initial state is assigning to agents their goals and beliefs.

                // === Goals === //

                // Go through all the agents in the world.
                foreach (var agent in currentStoryState.GetAgents())
                {
                    // If the agent's goal is to save/kill someone.
                    if (agent.Value.GetGoal().goalTypeIsStatus == true)
                    {
                        // Unless the agent has the role of the killer.
                        if (agent.Key.GetRole() != AgentRole.KILLER)
                        {
                            // Then his goal is that the killer must be neutralized.
                            agent.Value.GetGoal().GetGoalState().AddAgent(AgentRole.KILLER, false, "???");
                        }
                        // If the agent is the killer.
                        else if (agent.Key.GetRole() == AgentRole.KILLER)
                        {
                            int agentCounter  = 0;
                            int playerCounter = 1;
                            int killerCounter = NumberOfKillers();

                            // Then we go through all the agents.
                            foreach (var anotherAgent in currentStoryState.GetAgents())
                            {
                                // And for everyone who is not a killer...
                                if (anotherAgent.Key.GetRole() != AgentRole.KILLER)
                                {
                                    agentCounter++;

                                    // ...add a new "victim" to the goals.
                                    if (agentCounter == (currentStoryState.GetAgents().Count() - playerCounter - killerCounter))
                                    {
                                        agent.Value.GetGoal().GetGoalState().AddAgent(AgentRole.PLAYER, false, anotherAgent.Key.GetName());
                                    }
                                    else
                                    {
                                        agent.Value.GetGoal().GetGoalState().AddAgent(AgentRole.USUAL, false, anotherAgent.Key.GetName());
                                    }
                                }
                            }
                        }
                    }
                }

                // === Beliefs === //

                // We go through all the agents in the world.
                foreach (var agent in currentStoryState.GetAgents())
                {
                    // For each separately.
                    foreach (var anotherAgent in currentStoryState.GetAgents())
                    {
                        // If the agent meets himself.
                        if (agent.Equals(anotherAgent))
                        {
                            continue;
                        }
                        else
                        {
                            // Otherwise, copies the name of the selected agent and by default does not consider him a killer.
                            agent.Value.GetBeliefs().AddAgentInBeliefs(anotherAgent, AgentRole.USUAL);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public bool AssignVariables(ref PlanAction action, WorldDynamic currentState, KeyValuePair<AgentStateStatic, AgentStateDynamic> initiator)
        {
            if (action is Entrap || action is CounterEntrap)
            {
                foreach (var agent in currentState.GetAgents())
                {
                    if ((agent.Key.GetRole() == AgentRole.USUAL || agent.Key.GetRole() == AgentRole.PLAYER) && agent.Value.GetStatus() 
                        && !currentState.GetLocation(currentState.SearchAgentAmongLocations(agent.Key)).Value.SearchAgent(initiator.Key) 
                        && !agent.Equals(initiator))
                    {
                        action.Arguments.Add(agent);
                        action.Arguments.Add(initiator); 
                        action.Arguments.Add(currentState.GetLocationByName(currentState.SearchAgentAmongLocations(initiator.Key).GetName()));
                        return true;
                    }
                }
                return false;
            }
            else if (action is Fight || action is CounterFight)
            {
                foreach (var agent in currentState.GetAgents())
                {
                    if ((agent.Key.GetRole() == AgentRole.USUAL || agent.Key.GetRole() == AgentRole.PLAYER) && agent.Value.GetStatus() 
                        && currentState.GetLocation(currentState.SearchAgentAmongLocations(initiator.Key)).Value.SearchAgent(agent.Key))
                    {
                        action.Arguments.Add(initiator);
                        action.Arguments.Add(agent);
                        action.Arguments.Add(currentState.GetLocation(currentState.SearchAgentAmongLocations(initiator.Key)));
                        return true;
                    }
                }
                return false;
            }
            else if (action is InvestigateRoom || action is CounterInvestigateRoom)
            {
                foreach (var killer in currentState.GetAgents())
                {
                    if (killer.Key.GetRole() == AgentRole.KILLER && killer.Value.GetStatus())
                    {
                        action.Arguments.Add(initiator);
                        action.Arguments.Add(killer);
                        action.Arguments.Add(currentState.GetLocationByName(currentState.SearchAgentAmongLocations(initiator.Key).GetName()));
                        return true;
                    }
                }
                return false;
            }
            else if (action is Kill || action is CounterKill)
            {
                foreach (var agent in currentState.GetAgents())
                {
                    if ((agent.Key.GetRole() == AgentRole.USUAL || agent.Key.GetRole() == AgentRole.PLAYER) && agent.Value.GetStatus() 
                        && currentState.GetLocation(currentState.SearchAgentAmongLocations(initiator.Key)).Value.SearchAgent(agent.Key))
                    {
                        action.Arguments.Add(agent);
                        action.Arguments.Add(initiator);
                        action.Arguments.Add(currentState.GetLocation(currentState.SearchAgentAmongLocations(initiator.Key)));
                        return true;
                    }
                }
                return false;
            }
            else if (action is Move || action is CounterMove)
            {
                if (action.Arguments.Count() != 0)
                {
                    List<string> arguments = new List<string>();

                    foreach (var argument in action.Arguments)
                    {
                        arguments.Add((string)argument);
                    }

                    action.Arguments.Clear();

                    action.Arguments.Add(initiator);
                    action.Arguments.Add(currentState.GetLocationByName(arguments[1]));
                    action.Arguments.Add(currentState.GetLocationByName(arguments[2]));
                    return true;
                }
                else
                {
                    action.Arguments.Add(initiator);
                    action.Arguments.Add(currentState.GetLocationByName(currentState.SearchAgentAmongLocations(initiator.Key).GetName()));

                    if (initiator.Value.GetTargetLocation() != null && initiator.Key.GetRole() != AgentRole.PLAYER &&
                        currentState.SearchAgentAmongLocations(initiator.Key).ConnectionChecking(initiator.Value.GetTargetLocation()))
                    {
                        action.Arguments.Add(currentState.GetLocationByName(initiator.Value.GetTargetLocation().GetName()));
                        return true;
                    }
                    else
                    {
                        KeyValuePair<LocationStatic, LocationDynamic> randLoc = currentState.
                          GetRandomConnectedLocation(currentState.GetLocationByName(currentState.SearchAgentAmongLocations(initiator.Key).GetName()));

                        if (currentState.GetLocationByName(currentState.SearchAgentAmongLocations(initiator.Key).GetName()).
                            Key.ConnectionChecking(randLoc.Key))
                        {
                            action.Arguments.Add(randLoc);
                            return true;
                        }
                    }
                }
                return false;
            }
            else if (action is NeutralizeKiller || action is CounterNeutralizeKiller)
            {
                foreach (var killer in currentState.GetAgents())
                {
                    if (killer.Key.GetRole() == AgentRole.KILLER && killer.Value.GetStatus())
                    {
                        action.Arguments.Add(initiator);
                        action.Arguments.Add(killer);
                        action.Arguments.Add(currentState.GetLocation(currentState.SearchAgentAmongLocations(initiator.Key)));
                        return true;
                    }
                }
                return false;
            }
            else if (action is Reassure || action is CounterReassure)
            {
                foreach (var agent in currentState.GetAgents())
                {
                    if (agent.Key.GetRole() == AgentRole.USUAL && agent.Value.GetStatus()
                        && currentState.GetLocation(currentState.SearchAgentAmongLocations(initiator.Key)).Value.SearchAgent(agent.Key)
                        && !agent.Key.Equals(initiator.Key) && agent.Value.AngryCheck())
                    {
                        action.Arguments.Add(agent);
                        action.Arguments.Add(initiator);
                        action.Arguments.Add(currentState.GetAgentByName(agent.Value.GetObjectOfAngry().GetObjectOfAngry().GetName()));
                        break;
                    }
                }

                foreach (var killer in currentState.GetAgents())
                {
                    if (killer.Key.GetRole() == AgentRole.KILLER && killer.Value.GetStatus())
                    {
                        action.Arguments.Add(killer);
                        break;
                    }
                }

                action.Arguments.Add(currentState.GetLocation(currentState.SearchAgentAmongLocations(initiator.Key)));
                return true;
            }
            else if (action is Run || action is CounterRun)
            {
                action.Arguments.Add(initiator);
                action.Arguments.Add(currentState.GetLocation(currentState.SearchAgentAmongLocations(initiator.Key)));
                action.Arguments.Add(currentState.
                        GetRandomLocationWithout(currentState.GetLocationByName(currentState.SearchAgentAmongLocations(initiator.Key).GetName())));
                return true;
            }
            else if (action is NothingToDo)
            {
                action.Arguments.Add(initiator);
            }
            else if (action is TellAboutASuspicious || action is CounterTellAboutASuspicious)
            {
                foreach (var agent in currentState.GetAgents())
                {
                    if (agent.Key.GetRole() == AgentRole.USUAL && agent.Value.GetStatus() 
                        && currentState.GetLocation(currentState.SearchAgentAmongLocations(initiator.Key)).Value.SearchAgent(agent.Key))
                    {
                        action.Arguments.Add(agent);
                        break;
                    }
                }

                action.Arguments.Add(initiator);
                action.Arguments.Add(currentState.GetLocation(currentState.SearchAgentAmongLocations(initiator.Key)));
                action.Arguments.Add(currentState.GetRandomLocationWithout
                    (currentState.GetLocationByName(currentState.SearchAgentAmongLocations(initiator.Key).GetName())));
                return true;
            }
            else if (action is Talk || action is CounterTalk)
            {
                action.Arguments.Add(initiator);

                foreach (var agent in currentState.GetAgents())
                {
                    if (agent.Value.GetStatus()
                        && currentState.GetLocation(currentState.SearchAgentAmongLocations(initiator.Key)).Value.SearchAgent(agent.Key)
                        && agent.Key.GetName() != initiator.Key.GetName())
                    {
                        action.Arguments.Add(agent);
                        return true;
                    }
                }

                return false;
            }
            return false;
        }