Example #1
0
        color FragmentShader(VertexOut vertex, Field<cell> Current)
        {
            color output = color.TransparentBlack;

            cell here  = Current[Here];

            return here.state == State.Alive ? rgba(1,1,1,1) : rgba(0,0,0,1);
        }
Example #2
0
 public void CopyFieldToAnother(ref Field secondField)
 {
     for (int i = 0; i < GetHeight(); i++)
     {
         for (int j = 0; j < GetWidth(); j++)
         {
             secondField.SetCell(i, j, GetCell(i, j));
         }
     }
 }
Example #3
0
 public CellarAutomat(CellarAutomatRules rule, Field createdField)
 {
     PastField = createdField;
     CurrentField = new Field(createdField.GetWidth(), createdField.GetHeight());
     createdField.CopyFieldToAnother(ref CurrentField);
     this.Rule = rule;
     timeDelay = 250;
     Transformation = new Dictionary<CellarAutomatRules, ITransform>();
     StatesNumber = 4;
     InitializeTransormationPairs();
 }
Example #4
0
        static void Main(string[] args)
        {
            Field f = new Field(10, 10);
            CellarAutomat Automat = new CellarAutomat(CellarAutomatRules.BaseLife, f);
            Automat.Rule = CellarAutomatRules.MooreCyclic;
            Automat.NewCellarAutomat();
            Automat.TimeDelay = 2000;
            Automat.SetDensityForField(90);
            //Automat.PastField.CreateFigure();

            Automat.CellarAutomatProcess();
            Console.ReadLine();
        }
Example #5
0
        cell FragmentShader(VertexOut vertex, Field<cell> Current)
        {
            cell here = Current[Here];

            float neighbors = 
                Current[RightOne].state + Current[UpOne] .state + Current[LeftOne]  .state + Current[DownOne] .state +
                Current[UpRight] .state + Current[UpLeft].state + Current[DownRight].state + Current[DownLeft].state;

            if (neighbors < _2 || neighbors > _3)
                here.state = State.Dead;

            if (neighbors == _3)
                here.state = State.Alive;

            return here;
        }
Example #6
0
 public bool CheckIdentity(Field lastStateField)
 {
     int currentCell, pastCell;
     for (int i = 0; i < GetHeight(); i++)
     {
         for (int j = 0; j < GetWidth(); j++)
         {
             currentCell = GetCell(i, j);
             pastCell = lastStateField.GetCell(i, j);
             if (currentCell == pastCell)
                 continue;
             else
                 return false;
         }
     }
     return true;
 }
 public int TransformCell(Field pastF, int x, int y)
 {
     int centerCell = pastF.GetCell(x, y);
     int[] ExistingNeighbors = pastF.GetNeighborsInAllDirections(x, y);
     int sum = 0;
     for (int i = 0; i < ExistingNeighbors.Length; i++)
         sum += ExistingNeighbors[i];
     if (centerCell == 0)
     {
         if (sum < 5)
             return 0;
         else if (sum < 100)
             return 2;
         else
             return 3;
     }
     else if (centerCell == pastF.GetCell(x, y) - 1)
         return 0;
     else
         return Math.Min(sum / 8 + 5, pastF.GetCell(x, y) - 1);
 }
Example #8
0
        public static void _Apply(Texture2D Current, RenderTarget2D Output)
        {
            GridHelper.GraphicsDevice.SetRenderTarget(null);
            for (int i = 0; i < 10; i++)
                GridHelper.GraphicsDevice.Textures[i] = null;

            vec2 OutputSize = new vec2(Output.Width, Output.Height);

            var instance = new UpdateLife();
            var _Current = new Field<cell>(Current); _Current.GetDataFromTexture();
            var _Output  = new Field<cell>(Output);  _Output.GetDataFromTexture();

            for (int i = 0; i < Output.Width ; i++) {
            for (int j = 0; j < Output.Height; j++) {
                VertexOut v = VertexOut.Zero;
                v.TexCoords = new vec2(i, j) / OutputSize;
                __SamplerHelper.TextureCoord = v.TexCoords;
                var color = (color)instance.FragmentShader(v, _Current).ConvertTo();
                //color = rgba(State.Alive, 0,0,0);
                _Output.clr[i * _Output.Height + j] = new Color(FragSharpMarshal.Marshal(color));
            }}

            _Output.CopyDataToTexture();
        }
Example #9
0
        static void Main(string[] args)
        {
            Console.WindowHeight = 50;
            Console.WindowWidth = 50;
            var fields = new[]
            {
                Life.Field.CreatStartField(1, 1, 2, 2, 2, 3, 3, 1, 3, 2),
                Life.Field.CreatStartField(1, 1, 1, 2, 1, 3),
                Life.Field.CreatStartField(1, 2, 2, 1, 2, 2, 2, 3),
                Life.Field.CreatStartField(1, 1, 1, 2, 1, 3, 1, 4),
                Life.Field.CreatStartField(1, 4, 1, 5, 1, 6, 2, 4, 2, 5, 2, 6, 3, 4, 3, 5, 3, 6, 4, 1, 4, 2, 4, 3, 5, 1,
                    5, 2, 5, 3, 6, 1, 6, 2, 6, 3),
                Life.Field.CreatStartField(1, 5, 1, 6, 2, 5, 2, 6, 4, 5, 4, 6, 4, 7, 4, 8, 5, 1, 5, 2, 5, 4, 5, 9, 6, 1,
                    6, 2, 6, 4, 6, 5, 6, 9, 7, 4, 7, 6, 7, 7, 7, 9, 7, 11, 7, 12, 8, 4, 8, 9, 8, 11, 8, 12, 9, 5, 9, 6,
                    9, 7, 9, 8, 11, 7, 11, 8, 12, 7, 12, 8),
                Life.Field.CreatStartField(1, 2, 1, 3, 2, 1, 2, 2, 2, 3, 2, 4, 3, 1, 3, 2, 3, 4, 3, 5, 4, 3, 4, 4, 9, 1,
                    9, 2, 10, 2, 10, 3, 11, 1, 11, 2, 12, 1, 15, 2, 15, 3, 16, 1, 16, 2, 16, 3, 16, 4, 17, 1, 17, 2, 17,
                    4, 17, 5, 18, 3, 18, 4),
                Life.Field.CreatStartField(6, 1, 6, 2, 7, 1, 7, 2, 3, 14, 4, 13, 4, 15, 5, 12, 5, 16, 5, 17, 6, 12, 6,
                    16, 6, 17, 7, 12, 7, 16, 7, 17, 8, 13, 8, 15, 9, 14, 1, 26, 2, 23, 2, 24, 2, 25, 2, 26, 3, 22, 3, 23,
                    3, 24, 3, 25, 4, 22, 4, 25, 5, 22, 5, 23, 5, 24, 5, 25, 6, 23, 6, 24, 6, 25, 6, 26, 7, 26, 10, 23,
                    10, 25, 11, 24, 11, 25, 12, 24, 2, 31, 3, 31, 4, 35, 4, 36, 5, 35, 5, 36, 17, 31, 18, 32, 18, 33, 19,
                    31, 19, 32, 24, 41, 24, 46, 25, 39, 25, 40, 25, 42, 25, 43, 25, 44, 25, 45, 25, 47, 25, 48, 26, 41,
                    26, 46),
                Life.Field.CreatStartField(6, 1, 6, 2, 7, 1, 7, 2, 3, 14, 4, 13, 4, 15, 5, 12, 5, 16, 5, 17, 6, 12, 6,
                    16, 6, 17, 7, 12, 7, 16, 7, 17, 8, 13, 8, 15, 9, 14, 1, 26, 2, 23, 2, 24, 2, 25, 2, 26, 3, 22, 3, 23,
                    3, 24, 3, 25, 4, 22, 4, 25, 5, 22, 5, 23, 5, 24, 5, 25, 6, 23, 6, 24, 6, 25, 6, 26, 7, 26, 10, 23,
                    10, 25, 11, 24, 11, 25, 12, 24, 2, 31, 3, 31, 4, 35, 4, 36, 5, 35, 5, 36, 17, 31, 18, 32, 18, 33, 19,
                    31, 19, 32, 24, 41, 24, 46),
                 Life.Field.CreatStartField(1, 3, 2, 1, 2, 4, 3, 1, 3, 4, 4, 2),
                 Life.Field.CreatStartField(1, 1, 1, 4, 2, 5, 3, 1, 3, 5, 4, 2, 4, 3, 4, 4, 4, 5),
                 Life.Field.CreatStartField(1, 2, 1, 4, 1, 5, 1, 9, 1, 10, 1, 11, 3, 1, 4, 1, 5, 1, 3, 6, 4, 6, 5, 6, 3, 8, 4, 8, 5, 8, 3, 13, 4, 13, 5, 13, 6, 3, 6, 4, 6, 5, 6, 9, 6, 10, 6, 11, 8, 3, 8, 4, 8, 5, 8, 9, 8, 10, 8, 11, 9, 1, 10, 1, 11, 1, 9, 6, 10, 6, 11, 6, 9, 8, 10, 8, 11, 8, 9, 13, 10, 13, 11, 13, 13, 3, 13, 4, 13, 5, 13, 9, 13, 10, 13, 11)
            };

            
            for (var i = 0; i < fields.Length; ++i)
            {
                Console.WriteLine("{0} :", i + 1);
                fields[i].Show();
            }

            

            var isValidKey = false;
            Field field = new Field();
            var x = 0;
            while (!isValidKey)
            {
                Console.WriteLine("Choose start field :");
                x = Int32.Parse(Console.ReadLine());
                if (x > 0 && x <= fields.Length)
                {
                    field = fields[x - 1];
                    isValidKey = true;
                }

                Console.WriteLine("Wrong!Repeat please!");
            }

            while (true)
            {
                Console.Clear();
                field.Show();
                if (x != 7 && x != 8 && x != 9 && x != 12)
                    Thread.Sleep(200);
                field.NextStep();
            }


        }