Exemplo n.º 1
0
 private void PickUpIngredient(Ingredient fieldIngredient)
 {
     Debug.Log(fieldIngredient.ingredientType);
     _currentWorldRepresentation = GetCurrentWorldRepresentation();
     _currentIngredient          = fieldIngredient;
     _currentWorldRepresentation.ChangeSprite(IngredientSprite(fieldIngredient.ingredientType));
     GetCurrentField.SetIngredient(null);
     _lastField = GetCurrentField;
 }
Exemplo n.º 2
0
 public void AddEffects(WorldRepresentation world, int factNode, Fact.MutableFact factObject, IEnumerable <int> relatedNodes)
 {
     // All this simple kind of effect adder does, is add the effect to all the specified related nodes, if they are passed to us!
     if (relatedNodes != null)
     {
         foreach (int n in relatedNodes)
         {
             factObject.AccessEffectsCausedList().Add(new Effect(effectType, 1, n, factNode));
         }
     }
 }
        public void Constructor_CreateWorldRepresentationWithEmptyDynamicStateAndEmptyInterpretation()
        {
            // Arrange
            Mock <StaticState> s = new Mock <StaticState>(arr, arr2);

            // Act
            WorldRepresentation rep1 = new WorldRepresentation(s.Object);

            // Assert
            Assert.AreEqual(rep1.StaticState, s.Object);
            Assert.IsTrue(rep1.DynamicState != null);       // Not allowed to be null! Instead, the world rep should have created a simple empty state.
            Assert.IsTrue(rep1.Interpretation != null);
        }
Exemplo n.º 4
0
        public void Move(Offset offset)
        {
            if (WinLossConditionsMet())
            {
                return;
            }

            YoloTeamAction(offset);
            _room.RemoveDeadMonsters(_logger);
            _room.Monsters.ForEach(MonsterAction);

            _worldRepresentation = new WorldRepresentation(_room, _yoloTeam);
            _presentation.Draw(_worldRepresentation);
        }
        public void FactAdder_AddFactToANodeWhenNodeHasNoFactOfThatType_SuccessfullyAddsFact()
        {
            // Arrange some mock IEffectAdders. The IEffectAdders expect to be called ONCE and only ONCE, with the correct node id that the fact is being added to,
            // and the correct World object (which also must be mocked).
            int NODE  = 3;
            int VALUE = 2;
            int TIME  = 125;
            Mock <IEffectAdder> e1           = new Mock <IEffectAdder>();
            Mock <IEffectAdder> e2           = new Mock <IEffectAdder>();
            IEnumerable <int>   relatedNodes = new int[] { }; // To pass in.

            Fact.MutableFact    existingFact = new Fact.MutableFact(FactType.EnemyPresence, 1, TIME, null);
            WorldRepresentation fakeWorld    = WorldRep_ValueObjectMocker.NewWorldRepresentationMock();
            Dictionary <FactType, Fact.MutableFact> toPopulate = new Dictionary <FactType, Fact.MutableFact> {
                { FactType.EnemyPresence, existingFact }
            };                                                                                                                                             // This should become populated by the fact adder

            FactAdder toTest = new FactAdder(FactType.FriendlyPresence, new IEffectAdder[] { e1.Object, e2.Object });

            // ACT
            toTest.AddFact(fakeWorld, NODE, VALUE, TIME, toPopulate, relatedNodes);

            // ASSERT
            Assert.IsTrue(existingFact.Value == 1);    // Verify that the fact was not mutated.
            Assert.IsTrue(existingFact.FactType == FactType.EnemyPresence);

            // assert that other facttype was added correctly
            foreach (FactType t in Enum.GetValues(typeof(FactType)))
            {
                if (t == FactType.FriendlyPresence)
                {
                    Assert.IsTrue(toPopulate.ContainsKey(t));
                    Assert.IsTrue(toPopulate[t].Value == VALUE);
                }
                else if (t == FactType.EnemyPresence)
                {
                    Assert.IsTrue(toPopulate.ContainsKey(t));
                    Assert.IsTrue(toPopulate[t].Value == 1);
                }
                else
                {
                    Assert.IsFalse(toPopulate.ContainsKey(t));
                }
            }

            // verify each adder was called once, with the correct node id and world object
            e1.Verify(e => e.AddEffects(fakeWorld, NODE, It.IsAny <Fact.MutableFact>(), relatedNodes), Times.Once());
            e2.Verify(e => e.AddEffects(fakeWorld, NODE, It.IsAny <Fact.MutableFact>(), relatedNodes), Times.Once());
        }
Exemplo n.º 6
0
 // Public Interface.
 public void AddFact(WorldRepresentation world, int node, int value, int timeLearned, Dictionary <FactType, Fact.MutableFact> nodeFacts, IEnumerable <int> relatedNodes)
 {
     if (nodeFacts.ContainsKey(factType))
     {
         // Modify existing fact object's value, and that's it! The relevant effects should already exist, because the fact already exists.
         nodeFacts[factType].SetValue(value);
         nodeFacts[factType].SetTime(timeLearned);
     }
     else
     {
         // New fact!
         Fact.MutableFact f = new Fact.MutableFact(factType, value, timeLearned, new List <Effect>());
         // Delegate Effect adding logic to all our IEffectAdder objects. We don't care!
         foreach (IEffectAdder adder in effectAdders)
         {
             adder.AddEffects(world, node, f, relatedNodes);
         }
         nodeFacts.Add(factType, f);
     }
 }
Exemplo n.º 7
0
        public WorldRepresentation RevertDynamicStateChange(WorldRepresentation world, IDynamicStateChange eventData)
        {
            // Initialise data container for the 'changes' object which we will pass into the DynamicState constructor.
            Dictionary <int, Dictionary <FactType, Fact.MutableFact> > changeData = new Dictionary <int, Dictionary <FactType, Fact.MutableFact> >();

            // Collect the 'current' fact sets for the nodes which are to be affected by this State change being applied.
            foreach (int n in eventData.AffectedNodes)
            {
                Dictionary <FactType, Fact>             nFacts = DynamicStateInternalReader.GetNodeFact(n, world.DynamicState);
                Dictionary <FactType, Fact.MutableFact> nFactsMutableCopies = nFacts.ToDictionary(kvp => kvp.Key, kvp => new Fact.MutableFact(kvp.Value));
                changeData.Add(n, nFactsMutableCopies);
            }

            Remove(eventData.GetFactsAfter(), changeData, world);
            Add(eventData.GetFactsBefore(), changeData, eventData.TimeLearned, world);

            // TODO 5 - Make this LINQ dictionary 'cast' less retarded.
            Dictionary <int, Dictionary <FactType, Fact> > immutableCast = changeData.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToDictionary(kvp2 => kvp2.Key, kvp2 => (Fact)kvp2.Value));

            return(new WorldRepresentation(world.StaticState, new DynamicState(world.DynamicState, immutableCast)));
        }
Exemplo n.º 8
0
 private void Remove(Dictionary <int, IEnumerable <ValueTuple <FactType, int, IEnumerable <int> > > > factsToRemove, Dictionary <int, Dictionary <FactType, Fact.MutableFact> > nodeFactData, WorldRepresentation world)
 {
     // Cycle each node to have something removed
     foreach (var n in factsToRemove)
     {
         // n.Key   == NodeId
         // n.Value == Enumerable list of fact types and their associated values, to be removed.
         foreach ((FactType typeToBeRemoved, int factVal, IEnumerable <int> relatedNodes) in n.Value)
         {
             // Use our mapped adder logic to remove this fact!
             adderLogic[typeToBeRemoved].RemoveFact(world, n.Key, nodeFactData[n.Key]);
         }
     }
 }
 public void AddEffects(WorldRepresentation world, int factNode, Fact.MutableFact factObject, IEnumerable <int> relatedNodes)
 {
     SingleEdgeBasedEffectAdder.AddEffects(factNode, 1, world.NumberOfNodes, factObject, (from, to) => world.StaticState.FullVisibilityReader()(to, from), effectType);
 }
 public void AddEffects(WorldRepresentation world, int factNode, Fact.MutableFact factObject, IEnumerable <int> relatedNodes)
 {
     SingleEdgeBasedEffectAdder.AddEffects(factNode, 1, world.NumberOfNodes, factObject, world.StaticState.HasControlOverReader(), effectType);
 }
Exemplo n.º 11
0
    //WorldRepresentation

    public void AddWorldRepresenation(WorldRepresentation newWorldRepresentation)
    {
        _worldRepresentations.Add(newWorldRepresentation);
    }