Example #1
0
        public override void Initialize()
        {
            base.Initialize();
            AllRules.Add(RuleFactory.GetRuleByName("Seeds"));
            _ruleChooser.SetRuleRank(RuleFactory.GetRuleByName("Seeds"), 2);

            CAPattern pattern     = PatternFactory.GetPieceGridFromPatternFile("RuleFiles/SeedsJustFriendsStrangeBlinker.rle", false);
            Point     insertPoint = new Point(25, 25);

            InsertPattern(pattern, insertPoint, 0);
            _rulePoints[new Point(26, 26)] = RuleFactory.GetRuleByName("Seeds");
            _rulePoints[new Point(27, 27)] = RuleFactory.GetRuleByName("Seeds");
        }
        public override void Initialize()
        {
            base.Initialize();

            CAPattern pattern     = PatternFactory.GetPieceGridFromPatternFile("RuleFiles/JustFriendsBox50.rle");
            Point     insertPoint = new Point(25, 25);

            InsertPattern(pattern, insertPoint, 0);

            pattern     = PatternFactory.GetPieceGridFromPatternFile("RuleFiles/SeedsSmall.rle");
            insertPoint = new Point(2, 2);
            InsertPattern(pattern, insertPoint, 2);
        }
Example #3
0
        public void InsertPattern(CAPattern pattern, Point insertPoint, int rank = -1)
        {
            if (!_allRules.Contains(pattern.Rule))
            {
                _allRules.Add(pattern.Rule);
            }
            if (!_ruleChooser.TryGetRuleRank(pattern.Rule, out int existingRank))
            {
                if (rank >= 0)
                {
                    _ruleChooser.SetRuleRank(pattern.Rule, rank);
                }
                else
                {
                    _ruleChooser.SetRuleRank(pattern.Rule, _allRules.IndexOf(pattern.Rule));
                }
            }

            if (_currentGen.IsOutOfBounds(insertPoint))
            {
                throw new ArgumentException($"Insert point {insertPoint} is outside given PieceGrid (size {_currentGen.Size})");
            }
            if (pattern.Pattern.Size > _currentGen.Size)
            {
                throw new ArgumentException($"Pattern too big for given PieceGrid: {_currentGen.Size} < {pattern.Pattern.Size}");
            }
            foreach (var kvp in pattern.Pattern.PointPieces)
            {
                IEnumerable <Point> nPoints = kvp.Key.GetAdjacentPointsNotOutOfBounds(pattern.Pattern, PointHelpers.NeighborhoodOrder.Moore);
                bool aliveNeighbors         = nPoints.Any(pt => pattern.Pattern.PointPieces[pt].StateValue > 0);
                if (aliveNeighbors)
                {
                    Point p = insertPoint.AddPointsToroid(kvp.Key, _currentGen);
                    _currentGen.PointPieces[p] = kvp.Value;
                    _rulePoints[p]             = pattern.Rule;
                }
            }
        }