コード例 #1
0
        static int CheckBlock(CA4Field cellField, FourthDInt s)
        {
            var w     = s.wAxis;
            var x     = s.xAxis;
            var y     = s.yAxis;
            var z     = s.zAxis;
            var State = new int[81];            //State[39]が中心になるはず

            foreach (var elm in Enumerable.Range(0, 81))
            {
                int _w = w + (elm / 27) % 3 - 1;
                int _x = x + (elm / 9) % 3 - 1;
                int _y = y + (elm / 3) % 3 - 1;
                int _z = z + (elm / 1) % 3 - 1;
                State [elm] = cellField [_w, _x, _y, _z];
            }
            return(CheckRule(State));
        }
コード例 #2
0
        public CA4Field Copy()
        {
            var res = new CA4Field();

            for (var i = 0; _cellField.GetLength(0) > i; i++)
            {
                for (var j = 0; _cellField.GetLength(1) > j; j++)
                {
                    for (var k = 0; _cellField.GetLength(2) > k; k++)
                    {
                        for (var l = 0; _cellField.GetLength(3) > l; l++)
                        {
                            res [i, j, k, l] = _cellField [i, j, k, l];
                        }
                    }
                }
            }
            return(res);
        }
コード例 #3
0
        public static async Task CAMain()
        {
            var CellField = new CA4Field();
            var NextField = new CA4Field();

            CellField.InitializeWithRamdom();
            var swatch = new System.Diagnostics.Stopwatch();

            while (true)
            {
                swatch.Start();
                await Task.Run(() => {
                    Parallel.ForEach(CellField, s => {
                        NextField [s.wAxis, s.xAxis, s.yAxis, s.zAxis] = CheckBlock(CellField, s);
                    });
                });

                CellField = NextField.Copy();
                swatch.Stop();
                Console.Write(swatch.ElapsedMilliseconds + " : ");
                Console.WriteLine(CellField.Sum(x => x.Value) / (double)CA4Field.FieldSize * 100);
                swatch.Reset();
            }
        }