Ejemplo n.º 1
0
        private bool[,] GetRulePipelineResults()
        {
            bool[,] results = new bool[_board.Size, _board.Size];
            CellRule rule = new CellRule();

            rule.PipelineObject = rule.GetType();
            rule.PipelineObjectNamespaceName = true.GetType().FullName;
            var processes = new RuleFactory <IPipelineObject>().GetProcessors(rule).ToList();  //cast to avoid multiple enumerations

            for (int y = 0; y < _board.Size; y++)
            {
                for (int x = 0; x < _board.Size; x++)
                {
                    rule.Initialize(_board, x, y);

                    var result = Pipeline <IPipelineObject> .Execute(processes, rule) as CellRule;

                    if (result == null)
                    {
                        throw new Exception("The pipeline being executed for cell rules must return a cell rule object.");
                    }

                    results[x, y] = result.Status;
                }
            }
            return(results);
        }
Ejemplo n.º 2
0
 public BCMCellRule(CellRule cellRule)
 {
     Name            = cellRule.Name;
     CavesMinMax     = new BCMVector2(cellRule.CavesMinMax);
     PathType        = cellRule.PathMaterial.type;
     PathRadius      = cellRule.PathRadius;
     HubRules        = cellRule.HubRules.ToDictionary(f => f.Key, f => Math.Round(f.Value, 2));
     WildernessRules = cellRule.WildernessRules.ToDictionary(f => f.Key, f => Math.Round(f.Value, 2));
 }
Ejemplo n.º 3
0
        public void IterateAutomataSingle7(CellRule rule, bool expected)
        {
            // test to verify all neighbors are influencing decision correctly
            string[] inGrid =
            {
                "X..",
                "...",
                "...",
            };

            bool[][] map = GridTest.InitBoolGrid(inGrid);

            bool[][] result = NoiseGen.IterateAutomata(map, CellRule.None, rule, 1);
            Assert.That(result[1][1], Is.EqualTo(expected));
        }
Ejemplo n.º 4
0
        public static bool[][] IterateAutomata(bool[][] startGrid, CellRule birth, CellRule survive, int iterations)
        {
            int width  = startGrid.Length;
            int height = startGrid[0].Length;

            bool[][] endGrid = new bool[width][];
            for (int ii = 0; ii < width; ii++)
            {
                endGrid[ii] = new bool[height];
            }

            for (int ii = 0; ii < iterations; ii++)
            {
                for (int xx = 0; xx < width; xx++)
                {
                    for (int yy = 0; yy < height; yy++)
                    {
                        int rating = 0;
                        if (CheckGrid(xx - 1, yy - 1, startGrid))
                        {
                            rating++;
                        }
                        if (CheckGrid(xx + 1, yy - 1, startGrid))
                        {
                            rating++;
                        }
                        if (CheckGrid(xx - 1, yy + 1, startGrid))
                        {
                            rating++;
                        }
                        if (CheckGrid(xx + 1, yy + 1, startGrid))
                        {
                            rating++;
                        }
                        if (CheckGrid(xx - 1, yy, startGrid))
                        {
                            rating++;
                        }
                        if (CheckGrid(xx + 1, yy, startGrid))
                        {
                            rating++;
                        }
                        if (CheckGrid(xx, yy - 1, startGrid))
                        {
                            rating++;
                        }
                        if (CheckGrid(xx, yy + 1, startGrid))
                        {
                            rating++;
                        }

                        rating = 0x1 << rating;

                        bool live = startGrid[xx][yy];
                        if (live)
                        {
                            // this is a live cell, use survival rules
                            if ((rating & (int)survive) > 0)
                            {
                                endGrid[xx][yy] = true;
                            }
                        }
                        else
                        {
                            // this is a dead cell, use birth rules
                            if ((rating & (int)birth) > 0)
                            {
                                endGrid[xx][yy] = true;
                            }
                        }
                    }
                }

                bool[][] midGrid = startGrid;
                startGrid = endGrid;
                endGrid   = midGrid;

                for (int xx = 0; xx < width; xx++)
                {
                    for (int yy = 0; yy < height; yy++)
                    {
                        endGrid[xx][yy] = false;
                    }
                }
            }

            return(startGrid);
        }