Exemplo n.º 1
0
        public Piece Run(PieceGrid currentGen, Point point, Piece piece)
        {
            int aliveNeighbors = PointHelpers.GetAdjacentPointsToroid(point, currentGen, PointHelpers.NeighborhoodOrder.Moore).Count(p => currentGen.PointPieces[p].StateValue > 0);

            switch (piece.StateValue)
            {
            case 1:
                if (SurvivalNeighborCounts.Contains(aliveNeighbors))
                {
                    return(Piece.Get(1));
                }
                else
                {
                    return(Piece.Get(0));
                }

            case 0:
                if (BirthNeighborCounts.Contains(aliveNeighbors))
                {
                    return(Piece.Get(1));
                }
                else
                {
                    return(Piece.Get(0));
                }

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 2
0
        private void ParseRuleStringRegex(string ruleString)
        {
            var matchColl = _ruleStringRegex.Matches(ruleString);

            foreach (char c in matchColl[0].Groups[1].Value)
            {
                BirthNeighborCounts.Add(int.Parse(c.ToString()));
            }
            foreach (char c in matchColl[0].Groups[2].Value)
            {
                SurvivalNeighborCounts.Add(int.Parse(c.ToString()));
            }
            foreach (char c in matchColl[0].Groups[3].Value)
            {
                BirthNeighborCounts.Add(int.Parse(c.ToString()));
            }
        }