示例#1
0
        public void Initialize(Configuration theConfiguration)
        {
            initCommands();

            mySimulation = new SimulationEngine();
            mySimulation.Initialize(UniverseFactory.CreateUniverse(theConfiguration));

            configureVisualization(theConfiguration);
            displayUniverse(mySimulation.Universe);
        }
示例#2
0
 public void Universe_GetFromRleWithInvalidValue_Throws()
 {
     var _ = UniverseFactory.GetFromRleString(new[]
     {
         "#C Hello World",
         "#N Name",
         "x = a, y = 17, rule = S3/B23",
         @"o3b2o$2o3bo!"
     });
 }
示例#3
0
 private void InitializeUniversesList()
 {
     AddUniverse(UniverseFactory.StartSolarSystem());
     AddUniverse(UniverseFactory.StartJupiterSystem());
     AddUniverse(UniverseFactory.StartSquareSystem());
     AddUniverse(UniverseFactory.StartRandomSystem(100));
     AddUniverse(UniverseFactory.StartCircleSystem(20));
     AddUniverse(UniverseFactory.StartMultiCircleSystem(5e11, 2, 20));
     AddUniverse(UniverseFactory.StartGalaxySystem(100));
 }
示例#4
0
        public void GameOfLife_WithExpectedNewborn_Succeeds()
        {
            var startUniverse = UniverseFactory.GetFromMatrixString(new[]
            {
                " x ",
                " xx"
            });
            var expectedUniverse = UniverseFactory.GetFromMatrixString(new[]
            {
                " xx",
                " xx"
            });

            var result = GameOfLife.CalculateStep(startUniverse);

            result.Cells.Should().BeEquivalentTo(expectedUniverse.Cells);
        }
示例#5
0
        public void Universe_GetFromRle_Succeeds()
        {
            var universe = UniverseFactory.GetFromRleString(new []
            {
                "#C Hello World",
                "#N Name",
                "x = 12, y = 17, rule = S3/B23",
                @"o3b2o$2o3bo!"
            });

            universe.Cells.Count.Should().Be(6);
            universe.Contains(0, 0).Should().BeTrue();
            universe.Contains(4, 0).Should().BeTrue();
            universe.Contains(5, 0).Should().BeTrue();
            universe.Contains(0, 1).Should().BeTrue();
            universe.Contains(1, 1).Should().BeTrue();
            universe.Contains(5, 1).Should().BeTrue();
        }
示例#6
0
        public void GameOfLife_WithDyingConfiguration_Succeeds()
        {
            var lines = new[]
            {
                "x        x",
                "         x",
                "   x  ",
                "   x         x ",
                "             x",
                "x",
                "x"
            };
            var startUniverse = UniverseFactory.GetFromMatrixString(lines);

            var result = GameOfLife.CalculateStep(startUniverse);

            result.IsEmpty.Should().BeTrue();
        }
示例#7
0
        public void GameOfLife_WithStableConfiguration_Succeeds()
        {
            var lines = new[]
            {
                "         xx",
                "         xx",
                "   xx  ",
                "   xx         xx ",
                "              xx",
                "xx",
                "xx"
            };
            var startUniverse = UniverseFactory.GetFromMatrixString(lines);

            var result = GameOfLife.CalculateStep(startUniverse);

            result.Cells.Should().BeEquivalentTo(startUniverse.Cells);
        }
示例#8
0
        public void Universe_ZipUnzipUniverse_Succeeds()
        {
            var plainData = new[]
            {
                "xx  x ",
                "  xxxx",
                "    xx",
                " x x x",
                "x x x ",
                "  xx  ",
                "      ",
                "   x  "
            };
            var universe = UniverseFactory.GetFromMatrixString(plainData);
            var zipped   = universe.Zip();
            var result   = zipped.UnzipToUniverse();

            result.Should().BeEquivalentTo(universe);
        }
示例#9
0
        public void Universe_ToStringFormString_Succeeds()
        {
            var plainData = new[]
            {
                "xx  x ",
                "  xxxx",
                "    xx",
                " x x x",
                "x x x ",
                "  xx  ",
                "      ",
                "   x  "
            };
            var universe = UniverseFactory.GetFromMatrixString(plainData);
            var text     = universe.ToString();
            var result   = new Universe(text);

            result.Should().BeEquivalentTo(universe);
        }
示例#10
0
        public void Universe_GetFromRleGliderGun_Succeeds()
        {
            var rleData =
                @"x = 36, y = 9, rule = B3/S23
24bo$22bobo$12b2o6b2o12b2o$11bo3bo4b2o12b2o$2o8bo5bo3b2o$2o8bo3bob2o4bobo$10bo5bo7bo$11bo3bo$12b2o!";
            var plainData =
                @"                        x           
                      x x           
            xx      xx            xx
           x   x    xx            xx
xx        x     x   xx              
xx        x   x xx    x x           
          x     x       x           
           x   x                    
            xx                      ";

            var universeFromRle  = UniverseFactory.GetFromRleString(rleData);
            var universeFromText = UniverseFactory.GetFromMatrixString(plainData);

            universeFromRle.Should().BeEquivalentTo(universeFromText);
        }
        public void SetupSimulation(SimulationParameters simulationParameters)
        {
            PersonCache = _container.GetInstance<IPersonCache>();

            _simulationParameters = simulationParameters;
            _universeFactory = new UniverseFactory(_container);

            _universeFactory.SetRandom(_container.GetInstance<Random>());
            _universeFactory.SetPersonCache(PersonCache);
            _universeFactory.SetPersonBuilder(
                new PersonBuilder(
                    _container.GetInstance<FirstNameGenerator>(),
                    _container.GetInstance<LastNameGenerator>(),
                    _container.GetInstance<Random>()));
            _universeFactory.GenerateRootTerritory();

            _universeFactory.AddLifeEvent<GetMarriedLifeEvent>()
                .AddLifeEvent<StartDatingLifeEvent>()
                .AddLifeEvent<OrphanChildLifeEvent>()
                .AddLifeEvent<GetEngagedLifeEvent>()
                .AddLifeEvent<BreakupLifeEvent>()
                .AddLifeEvent<SwitchJobLifeEvent>()
                .AddLifeEvent<HaveChildrenLifeEvent>()
                .AddLifeEvent<DeathLifeEvent>()
                .AddLifeEvent<SexReassignmentLifeEvent>()
                .AddLifeEvent<GenderChangeLifeEvent>()
                .AddLifeEvent<MoveLifeEvent>()
                .AddLifeEvent<SettleLifeEvent>()
                .AddLifeEvent<GetJobLifeEvent>()
                .AddLifeEvent<FiredLifeEvent>();

            _universe = _universeFactory.Build();

            RootTerritory = _universeFactory.GetRootTerritory();

            // TODO: Move this eventually:
            _universe.Start();
        }
示例#12
0
        public void UniverseFactory_WithLineArray_ReturnsValidUniverse()
        {
            var lines = new[]
            {
                "  x xx x",
                "xxxxxxxx",
                "x       ",
                "        ",
                "       x"
            };
            var universe = UniverseFactory.GetFromMatrixString(lines);

            for (var y = 0; y < lines.Length; y++)
            {
                var line = lines[y];
                for (var x = 0; x < line.Length; x++)
                {
                    var shouldBeAlive = line[x] != ' ';
                    var isAlive       = universe.IsCellAlive(x, y);
                    shouldBeAlive.Should().Be(isAlive);
                }
            }
        }
示例#13
0
        public void Universe_GetFromRleWithLargeFile_Succeeds()
        {
            var data = @"#N diehard1760.rle
#C http://conwaylife.com/wiki/Die_hard
#C http://www.conwaylife.com/patterns/diehard1760.rle
x = 32, y = 32, rule = B3/S23
bo4bo3bo2bob6obo3b2obo$b2o2bobo3b2o3bobo2bob5o2b2o$obo3bob4o2bo2bobob
4obo2b2o$4bobob2o2b3o4bob2obob2o$2obo2bob2obo2b2o5b3ob2obo$6obo4bo4bob
obobo2bo3bo$bo2bo4b4o2b2obobo6b3obo$b3o3bo2b4o4bobob3obo3bo$b2ob2obobo
2bobo2b2o2b2o4b3o$ob3o2b4o3b2o2b6obob3o$b5o2b4o2bo2bobob2ob2o3bobo$o5b
2obo4bob2o3bo2b2obob2o$ob2obo3b2ob5o2bo3b4obobo$2o4b4o3b2o2b3o4bo3bo2b
o$obo2bo2bob2obob2ob6o3b3o$2o4bo4b2ob4obo2bo2bobo3bo$o3bobo2bo2bob4ob
2o4bo4b2o$2b3o3b6ob2obob2obo2bo2bobo$o2bo3bo4b3o2b2o3b4o4b2o$bobob4o3b
o2b5ob2o3bob2obo$b2obob2o2bo3b2obo4bob2o5bo$obo3b2ob2obobo2bo2b4o2b5o$
2b3obob6o2b2o3b4o2b3obo$2b3o4b2o2b2o2bobo2bobob2ob2o$bo3bob3obobo4b4o
2bo3b3o$ob3o6bobob2o2b4o4bo2bo$bo3bo2bobobobo4bo4bob6o$3bob2ob3o5b2o2b
ob2obo2bob2o$4b2obob2obo4b3o2b2obobo$b2o2bob4obobo2bo2b4obo3bobo$2o2b
5obo2bobo3b2o3bobo2b2o$2bob2o3bob6obo2bo3bo4bo!";

            var universe = UniverseFactory.GetFromRleString(data);

            universe.Cells.Count.Should().Be(496);
            universe.IsCellAlive(1, 0).Should().BeTrue();
        }
示例#14
0
        public void LoadSubsystems()
        {
            // Find the main model node from the XML model input file
            var modelInputXMLNode = XmlParser.GetModelNode(modelInputFilePath);



            // Set up Subsystem Nodes, first loop through the assets in the XML model input file
            foreach (XmlNode modelChildNode in modelInputXMLNode.ChildNodes)
            {
                if (modelChildNode.Name.Equals("ENVIRONMENT"))
                {
                    // Create the Environment based on the XMLNode
                    SystemUniverse = UniverseFactory.GetUniverseClass(modelChildNode);
                }
                else if (SystemUniverse == null)
                {
                    SystemUniverse = new SpaceEnvironment();
                }

                if (modelChildNode.Name.Equals("ASSET"))
                {
                    Asset asset = new Asset(modelChildNode);
                    asset.AssetDynamicState.Eoms.SetEnvironment(SystemUniverse);

                    assetList.Add(asset);
                    // Loop through all the of the ChildNodess for this Asset
                    foreach (XmlNode childNode in modelChildNode.ChildNodes)
                    {
                        // Get the current Subsystem XML Node, and create it using the SubsystemFactory
                        if (childNode.Name.Equals("SUBSYSTEM"))
                        {  //is this how we want to do this?
                           // Check if the type of the Subsystem is scripted, networked, or other
                            string subName = SubsystemFactory.GetSubsystem(childNode, dependencies, asset, subsystemMap);
                            foreach (XmlNode ICorDepNode in childNode.ChildNodes)
                            {
                                if (ICorDepNode.Name.Equals("IC"))
                                {
                                    ICNodes.Add(ICorDepNode);
                                }
                                if (ICorDepNode.Name.Equals("DEPENDENCY"))
                                {
                                    string depSubName = "", depFunc = "";
                                    depSubName = Subsystem.parseNameFromXmlNode(ICorDepNode, asset.Name);
                                    dependencyMap.Add(new KeyValuePair <string, string>(subName, depSubName));

                                    if (ICorDepNode.Attributes["fcnName"] != null)
                                    {
                                        depFunc = ICorDepNode.Attributes["fcnName"].Value.ToString();
                                        dependencyFcnMap.Add(new KeyValuePair <string, string>(subName, depFunc));
                                    }
                                }
                            }
                        }
                        //Create a new Constraint
                        if (childNode.Name.Equals("CONSTRAINT"))
                        {
                            constraintsList.Add(ConstraintFactory.GetConstraint(childNode, subsystemMap, asset));
                        }
                    }
                    if (ICNodes.Count > 0)
                    {
                        initialSysState.Add(SystemState.setInitialSystemState(ICNodes, asset));
                    }
                    ICNodes.Clear();
                }
            }

            foreach (KeyValuePair <string, Subsystem> sub in subsystemMap)
            {
                if (!sub.Value.GetType().Equals(typeof(ScriptedSubsystem)))//let the scripted subsystems add their own dependency collector
                {
                    sub.Value.AddDependencyCollector();
                }
                subList.Add(sub.Value);
            }
            log.Info("Subsystems and Constraints Loaded");
        }
示例#15
0
 private void resetSimulation()
 {
     mySimulation.Initialize(UniverseFactory.CreateUniverse(mySimulation.Universe.Configuration));
     updateCommandAvailability();
     displayUniverse(mySimulation.Universe);
 }
示例#16
0
 private Universe LoadRandomUniverse(bool showDialog)
 {
     return(ShowRandomSettingsDialog(showDialog)
         ? UniverseFactory.GetRandom(_randomSettingsForm.Density, _randomSettingsForm.FieldSize)
         : _universe);
 }