예제 #1
0
        private void AddEffects(WorldModelAsset wm)
        {
            var a1 = EventHelper.ActionEnd("John", "Speak([x],[y],*,*)", "Sarah");
            var a2 = EventHelper.ActionEnd("John", "Shoot", "Sarah");
            var a3 = (Name)"Event(Action-End , [s], *, John)";
            var a4 = (Name)"Event(Action-End , [s], Surf, [t])";

            wm.addActionTemplate(a1, 1);
            wm.addActionTemplate(a2, 1);
            wm.addActionTemplate(a3, 1);
            wm.addActionTemplate(a4, 1);

            wm.AddActionEffect(a1, new EffectDTO()
            {
                PropertyName = (Name)"Has(Floor)", NewValue = (Name)"Player"
            });
            wm.AddActionEffect(a2, new EffectDTO()
            {
                PropertyName = (Name)"DialogueState(Player)", NewValue = (Name)"Start"
            });
            wm.AddActionEffect(a3, new EffectDTO()
            {
                PropertyName = (Name)"Has(Floor)", NewValue = (Name)"False"
            });
            wm.AddActionEffect(a4, new EffectDTO()
            {
                PropertyName = (Name)"DialogueState([t])", NewValue = (Name)"[s]"
            });
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e) // Duplicate Effect
        {
            var index = dataGridViewEventTemplates.SelectedRows[0].Index;

            var eventTemp = _wmAsset.GetAllActions().ElementAt(index).Item1;

            var index2 = dataGridViewEffects.SelectedRows[0].Index;

            var effect = _wmAsset.GetAllEventEffects()[eventTemp].ElementAt(index2);

            _wmAsset.AddActionEffect(eventTemp, effect.ToDTO());

            dataGridViewEventTemplates_SelectionChanged(sender, e);
        }
예제 #3
0
        private void addEffect_Click(object sender, EventArgs e)
        {
            _effectToEdit.NewValue      = newValue.Value;
            _effectToEdit.PropertyName  = propertyName.Value;
            _effectToEdit.ObserverAgent = observerName.Value;

            if (index >= 0)
            {
                _wm.EditEventEffect(_eventTemplate, _effectToEdit, index);
            }
            else
            {
                _wm.AddActionEffect(_eventTemplate, _effectToEdit);
            }
            Close();
        }
예제 #4
0
        static void Main(string[] args)
        {
            var iat = IntegratedAuthoringToolAsset.LoadFromFile("../../../Examples/CiF-Tutorial/JobInterview.iat");

            rpcList = new List <RolePlayCharacterAsset>();
            var wm = new WorldModelAsset();

            wm.AddActionEffect((Name)"Event(Action-End, *, Speak(*,*,*,*), [t])", new EffectDTO()
            {
                PropertyName  = (Name)"Has(Floor)",
                NewValue      = (Name)"[t]",
                ObserverAgent = (Name)"*"
            });

            wm.AddActionEffect((Name)"Event(Action-End, [i], Speak([cs],[ns],*,*), SELF)", new EffectDTO()
            {
                PropertyName  = (Name)"DialogueState([i])",
                NewValue      = (Name)"[ns]",
                ObserverAgent = (Name)"[t]"
            });


            wm.AddActionEffect((Name)"Event(Action-End, SELF, Speak([cs],[ns],*,*), [t])", new EffectDTO()
            {
                PropertyName  = (Name)"DialogueState([t])",
                NewValue      = (Name)"[ns]",
                ObserverAgent = (Name)"[i]"
            });

            wm.SaveToFile("../../../Examples/WM-Tutorial/WorldModel.wm");
            foreach (var source in iat.GetAllCharacterSources())
            {
                var rpc = RolePlayCharacterAsset.LoadFromFile(source.Source);


                //rpc.DynamicPropertiesRegistry.RegistDynamicProperty(Name.BuildName("Volition"),cif.VolitionPropertyCalculator);
                rpc.LoadAssociatedAssets();

                iat.BindToRegistry(rpc.DynamicPropertiesRegistry);

                rpcList.Add(rpc);
            }


            foreach (var actor in rpcList)
            {
                foreach (var anotherActor in rpcList)
                {
                    if (actor != anotherActor)
                    {
                        var changed = new[] { EventHelper.ActionEnd(anotherActor.CharacterName.ToString(), "Enters", "Room") };
                        actor.Perceive(changed);
                    }
                }
                //         actor.SaveToFile("../../../Examples/" + actor.CharacterName + "-output1" + ".rpc");
            }



            List <Name>    _events  = new List <Name>();
            List <IAction> _actions = new List <IAction>();

            IAction action = null;

            while (true)
            {
                _actions.Clear();
                foreach (var rpc in rpcList)
                {
                    rpc.Tick++;

                    Console.WriteLine("Character perceiving: " + rpc.CharacterName + " its mood: " + rpc.Mood);

                    rpc.Perceive(_events);
                    var decisions = rpc.Decide();
                    _actions.Add(decisions.FirstOrDefault());

                    foreach (var act in decisions)
                    {
                        Console.WriteLine(rpc.CharacterName + " has this action: " + act.Name);
                    }
                    rpc.SaveToFile("../../../Examples/WM-Tutorial/" + rpc.CharacterName + "-output" + ".rpc");
                }

                _events.Clear();

                var randomGen = new Random(Guid.NewGuid().GetHashCode());

                var pos = randomGen.Next(rpcList.Count);
                int i   = 0;

                var initiator = rpcList[pos];


                action = _actions.ElementAt(pos);

                Console.WriteLine();
                if (action == null)
                {
                    Console.WriteLine(initiator.CharacterName + " does not have any action to do ");
                }

                if (action != null)
                {
                    var initiatorName = initiator.CharacterName.ToString();
                    var targetName    = action.Target.ToString();
                    var nextState     = action.Parameters[1].ToString();
                    var currentState  = action.Parameters[0].ToString();

                    Console.WriteLine("Action: " + initiatorName + " does " + action.Name + " to " +
                                      targetName + "\n" + action.Parameters[1]);

                    _events.Add(EventHelper.ActionEnd(initiatorName, action.Name.ToString(),
                                                      action.Target.ToString()));



                    Console.WriteLine();
                    Console.WriteLine("Dialogue:");
                    Console.WriteLine("Current State: " + currentState);
                    if (iat.GetDialogueActions(action.Parameters[0], action.Parameters[1], action.Parameters[2], action.Parameters[3]).FirstOrDefault() != null)
                    {
                        Console.WriteLine(initiator.CharacterName + " says: ''" +
                                          iat.GetDialogueActions(action.Parameters[0], action.Parameters[1], action.Parameters[2], action.Parameters[3]).FirstOrDefault().Utterance + "'' to " + targetName);
                    }
                    else
                    {
                        Console.WriteLine(initiator.CharacterName + " says: " + "there is no dialogue suited for this action");
                    }


                    // WORLD MODEL
                    var effects = wm.Simulate(_events.ToArray());
                    foreach (var ef in effects)
                    {
                        if (ef.ObserverAgent == (Name)"*")
                        {
                            foreach (var rpc in rpcList)
                            {
                                var proChange =
                                    EventHelper.PropertyChange(ef.PropertyName.ToString(), ef.NewValue.ToString(), "World");
                                rpc.Perceive(proChange);
                            }
                        }

                        else
                        {
                            var proChange =
                                EventHelper.PropertyChange(ef.PropertyName.ToString(), ef.NewValue.ToString(), "World");
                            rpcList.Find(x => x.CharacterName == ef.ObserverAgent).Perceive(proChange);
                        }
                    }

                    Console.WriteLine("Next State: " + nextState);
                }
                Console.WriteLine();
                Console.ReadKey();
            }
        }