Exemple #1
0
    void Start()
    {
        _prots = PrototypeDB.Instance.GetPrototypes();

        //_cells = new ushort[_islandGrid.x, _islandGrid.y, _islandGrid.z, (ushort)CELL.COUNT];
        _prototypes = new ushort[_prots.Count, (int)PROT.COUNT];
        _wave       = new ushort[_islandGrid.x, _islandGrid.y, _islandGrid.z, _prots.Count];
        _final      = new int[_islandGrid.x, _islandGrid.y, _islandGrid.z];
        _collapsed  = new bool[_islandGrid.x, _islandGrid.y, _islandGrid.z];
        _entropy    = new double[_islandGrid.x, _islandGrid.y, _islandGrid.z];
        _stack      = new List <Vector3Int>();

        // create prototype array
        for (int i = 0; i < _prots.Count; i++)
        {
            PrototypeDB.ProtInternal prot = _prots[i];

            _prototypes[i, (ushort)PROT.PROT_BOT_NX_NZ] = (ushort)prot._cornersBot[0];
            _prototypes[i, (ushort)PROT.PROT_BOT_PX_NZ] = (ushort)prot._cornersBot[1];
            _prototypes[i, (ushort)PROT.PROT_BOT_PX_PZ] = (ushort)prot._cornersBot[2];
            _prototypes[i, (ushort)PROT.PROT_BOT_NX_PZ] = (ushort)prot._cornersBot[3];
            _prototypes[i, (ushort)PROT.PROT_TOP_NX_NZ] = (ushort)prot._cornersTop[0];
            _prototypes[i, (ushort)PROT.PROT_TOP_PX_NZ] = (ushort)prot._cornersTop[1];
            _prototypes[i, (ushort)PROT.PROT_TOP_PX_PZ] = (ushort)prot._cornersTop[2];
            _prototypes[i, (ushort)PROT.PROT_TOP_NX_PZ] = (ushort)prot._cornersTop[3];

            _prototypes[i, (ushort)PROT.PROT_WEIGHT] = 1;
        }

        // create cell arrays
        for (int x = 0; x < _islandGrid.x; x++)
        {
            for (int y = 0; y < _islandGrid.y; y++)
            {
                for (int z = 0; z < _islandGrid.z; z++)
                {
                    int count = 0;
                    for (int p = 0; p < _prots.Count; p++)
                    {
                        _wave[x, y, z, p] = 1;

                        if (y == 0) // constrain all bottom layer cells to be inside on the bottom.
                        {
                            if (_prototypes[p, (int)PROT.PROT_BOT_NX_NZ] != 1 ||
                                _prototypes[p, (int)PROT.PROT_BOT_PX_NZ] != 1 ||
                                _prototypes[p, (int)PROT.PROT_BOT_PX_PZ] != 1 ||
                                _prototypes[p, (int)PROT.PROT_BOT_NX_PZ] != 1)
                            {
                                _wave[x, y, z, p] = 0;
                            }

                            if (x == 0)
                            {
                                if (_prototypes[p, (int)PROT.PROT_TOP_NX_NZ] != 0 ||
                                    _prototypes[p, (int)PROT.PROT_TOP_NX_PZ] != 0)
                                {
                                    _wave[x, y, z, p] = 0;
                                }
                            }

                            if (x == _islandGrid.x - 1)
                            {
                                if (_prototypes[p, (int)PROT.PROT_TOP_PX_NZ] != 0 ||
                                    _prototypes[p, (int)PROT.PROT_TOP_PX_PZ] != 0)
                                {
                                    _wave[x, y, z, p] = 0;
                                }
                            }

                            if (z == 0)
                            {
                                if (_prototypes[p, (int)PROT.PROT_TOP_PX_NZ] != 0 ||
                                    _prototypes[p, (int)PROT.PROT_TOP_NX_NZ] != 0)
                                {
                                    _wave[x, y, z, p] = 0;
                                }
                            }

                            if (z == _islandGrid.z - 1)
                            {
                                if (_prototypes[p, (int)PROT.PROT_TOP_PX_PZ] != 0 ||
                                    _prototypes[p, (int)PROT.PROT_TOP_NX_PZ] != 0)
                                {
                                    _wave[x, y, z, p] = 0;
                                }
                            }
                            if (!_stack.Contains(new Vector3Int(x, y, z)))
                            {
                                _stack.Add(new Vector3Int(x, y, z));
                            }
                        }

                        if (y == _islandGrid.y - 1) // constrain all top layer cells to be empty.
                        {
                            if (_prototypes[p, (int)PROT.PROT_TOP_NX_NZ] != 0 ||
                                _prototypes[p, (int)PROT.PROT_TOP_PX_NZ] != 0 ||
                                _prototypes[p, (int)PROT.PROT_TOP_PX_PZ] != 0 ||
                                _prototypes[p, (int)PROT.PROT_TOP_NX_PZ] != 0)
                            {
                                _wave[x, y, z, p] = 0;
                                if (!_stack.Contains(new Vector3Int(x, y, z)))
                                {
                                    _stack.Add(new Vector3Int(x, y, z));
                                }
                            }
                        }

                        if (y == 0)
                        {
                            if (x > 1 && x < _islandGrid.x - 2 && z > 1 && z < _islandGrid.z - 2)
                            {
                                if (_prototypes[p, (int)PROT.PROT_TOP_NX_NZ] != 1 ||
                                    _prototypes[p, (int)PROT.PROT_TOP_PX_NZ] != 1 ||
                                    _prototypes[p, (int)PROT.PROT_TOP_PX_PZ] != 1 ||
                                    _prototypes[p, (int)PROT.PROT_TOP_NX_PZ] != 1)
                                {
                                    _wave[x, y, z, p] = 0;
                                }
                            }
                        }

                        if (y == 1)
                        {
                            if (x > 2 && x < _islandGrid.x - 3 && z > 2 && z < _islandGrid.z - 3)
                            {
                                if (_prototypes[p, (int)PROT.PROT_TOP_NX_NZ] != 1 ||
                                    _prototypes[p, (int)PROT.PROT_TOP_PX_NZ] != 1 ||
                                    _prototypes[p, (int)PROT.PROT_TOP_PX_PZ] != 1 ||
                                    _prototypes[p, (int)PROT.PROT_TOP_NX_PZ] != 1)
                                {
                                    _wave[x, y, z, p] = 0;
                                    if (!_stack.Contains(new Vector3Int(x, y, z)))
                                    {
                                        _stack.Add(new Vector3Int(x, y, z));
                                    }
                                }
                            }
                        }

                        if (_wave[x, y, z, p] == 1)
                        {
                            count++;
                        }
                    }

                    _entropy[x, y, z]   = 99999.0;
                    _collapsed[x, y, z] = false;
                    _final[x, y, z]     = -1;
                }
            }
        }

        _entropy[0, 0, 0] = 1.0;
        Random.InitState(System.DateTime.UtcNow.Millisecond);
    }
 public static SuperArray Create(ushort[,,,] data) => Data.CreateArray(data);
Exemple #3
0
 public static extern af_err af_write_array(IntPtr array_arr, [In] ushort[,,,] data, UIntPtr size_bytes, af_source src);
Exemple #4
0
 public static extern af_err af_get_data_ptr([Out] ushort[,,,] data, IntPtr array_arr);
Exemple #5
0
 public static extern af_err af_create_strided_array(out IntPtr array_arr, [In] ushort[,,,] data, long dim_offset, uint ndims, [In] long[] dim_dims, [In] long[] dim_strides, af_dtype ty, af_source location);
Exemple #6
0
 public static extern af_err af_create_array(out IntPtr array_arr, [In] ushort[,,,] data, uint ndims, [In] long[] dim_dims, af_dtype type);
 public static extern af_err af_get_scalar([Out] ushort[,,,] output_value, IntPtr array_arr);
Exemple #8
0
 public static extern af_err af_free_host([Out] ushort[,,,] ptr);
Exemple #9
0
 public static extern af_err af_free_pinned([Out] ushort[,,,] ptr);
Exemple #10
0
 public static extern af_err af_free_device([Out] ushort[,,,] ptr);
Exemple #11
0
        private void InitTableALU()
        {
            TableALU = new ushort[8, 256, 256, 2];             // Class, OP1, OP2, Carry

            for (int i = 0; i < 8; ++i)
            {
                for (int op1 = 0; op1 < 256; ++op1)
                {
                    for (int op2 = 0; op2 < 256; ++op2)
                    {
                        for (int c = 0; c < 2; ++c)
                        {
                            int ac = (i == 1 || i == 3) ? c : 0;

                            bool S = false;
                            bool Z = false;
                            bool C = false;
                            bool H = false;
                            bool N = false;
                            bool P = false;

                            byte result_b  = 0;
                            int  result_si = 0;
                            int  result_ui = 0;

                            // Fetch result
                            switch (i)
                            {
                            case 0:
                            case 1:
                                result_si = (sbyte)op1 + (sbyte)op2 + ac;
                                result_ui = op1 + op2 + ac;
                                break;

                            case 2:
                            case 3:
                            case 7:
                                result_si = (sbyte)op1 - (sbyte)op2 - ac;
                                result_ui = op1 - op2 - ac;
                                break;

                            case 4:
                                result_si = op1 & op2;
                                break;

                            case 5:
                                result_si = op1 ^ op2;
                                break;

                            case 6:
                                result_si = op1 | op2;
                                break;
                            }

                            result_b = (byte)result_si;

                            // Parity/Carry

                            switch (i)
                            {
                            case 0:
                            case 1:
                            case 2:
                            case 3:
                            case 7:
                                P = result_si < -128 || result_si > 127;
                                C = result_ui < 0 || result_ui > 255;
                                break;

                            case 4:
                            case 5:
                            case 6:
                                P = TableParity[result_b];
                                C = false;
                                break;
                            }

                            // Subtraction
                            N = i == 2 || i == 3 || i == 7;

                            // Half carry
                            switch (i)
                            {
                            case 0:
                            case 1:
                                H = ((op1 & 0xF) + (op2 & 0xF) + (ac & 0xF)) > 0xF;
                                break;

                            case 2:
                            case 3:
                            case 7:
                                H = ((op1 & 0xF) - (op2 & 0xF) - (ac & 0xF)) < 0x0;
                                break;

                            case 4:
                                H = true;
                                break;

                            case 5:
                            case 6:
                                H = false;
                                break;
                            }

                            // Undocumented
                            byte UndocumentedFlags = (byte)(result_b & 0x28);
                            if (i == 7)
                            {
                                UndocumentedFlags = (byte)(op2 & 0x28);
                            }

                            S = result_b > 127;
                            Z = result_b == 0;

                            if (i == 7)
                            {
                                result_b = (byte)op1;
                            }

                            TableALU[i, op1, op2, c] = (ushort)(
                                result_b * 256 +
                                ((C ? 0x01 : 0) + (N ? 0x02 : 0) + (P ? 0x04 : 0) + (H ? 0x10 : 0) + (Z ? 0x40 : 0) + (S ? 0x80 : 0)) +
                                (UndocumentedFlags));
                        }
                    }
                }
            }
        }