public void DynamicState_CreateEmpty_DoesNotThrowUponReadCalls()
        {
            DynamicState empty = DynamicState.CreateEmpty(10);  // Arbitrary number

            Assert.DoesNotThrow(() => empty.GetEdge(2, 5));
            Assert.DoesNotThrow(() => empty.GetEdge(1, 2));
            Assert.DoesNotThrow(() => empty.GetEdge(7, 3));

            DynamicState.AreaEdge e1 = empty.GetEdge(2, 5);
            DynamicState.AreaEdge e2 = empty.GetEdge(1, 2);
            DynamicState.AreaEdge e3 = empty.GetEdge(7, 3);

            Assert.DoesNotThrow(() => { bool b = e1.IsCausingClearEffect; });
            Assert.DoesNotThrow(() => { bool b = e2.IsCausingPotentialEnemiesEffect; });
            Assert.DoesNotThrow(() => { int i = e1.ToNodeId; });

            for (int i = 0; i < 10; i++)
            {
                Assert.DoesNotThrow(() => empty.IsEnemyAreaReader()(i));
                Assert.DoesNotThrow(() => empty.IsControlledByTeamReader()(i));
                Assert.DoesNotThrow(() => empty.IsContestedAreaReader()(i));
                Assert.DoesNotThrow(() => empty.TakingFireMagnitudeLevelReader()(i));

                DynamicState.AreaNode n;
                Assert.DoesNotThrow(() => empty.GetNodeData(i));
                n = empty.GetNodeData(i);
                Assert.DoesNotThrow(() => { int d = n.TakingFireMagnitudeLevel; });
                Assert.DoesNotThrow(() => { bool b = n.IsControlledByTeam; });

                Assert.DoesNotThrow(() => { Dictionary <FactType, Fact> f = DynamicStateInternalReader.GetNodeFact(i, empty); });
                Assert.DoesNotThrow(() => { Dictionary <EffectType, EffectSum> f = DynamicStateInternalReader.GetNodeEffectSum(i, empty); });
            }
        }
Ejemplo n.º 2
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)));
        }