public static PuzzleDvec puzzle_fill_dvec(PuzzleAvgLvls avglvls)
        {
            int lambdas = avglvls.lambdas;

            PuzzleDvec dvec = new PuzzleDvec();

            dvec.vec = new double[(lambdas * lambdas * PuzzleNative.PUZZLE_NEIGHBORS)];
            int vecur = 0;
            int lx    = 0;
            int ly;

            do
            {
                ly = 0;
                do
                {
                    puzzle_add_neighbors(dvec.vec, ref vecur, PuzzleNative.PUZZLE_NEIGHBORS, ref avglvls, lx, ly);
                } while (++ly < lambdas);
            } while (++lx < lambdas);
            dvec.sizeof_compressed_vec = vecur;

            return(dvec);
        }
Exemple #2
0
        public static sbyte[] puzzle_fill_cvec_from_dvec(PuzzleContext context, PuzzleDvec dvec)
        {
            if (dvec.sizeof_compressed_vec == 0)
            {
                throw new Exception();
            }

            int s;

            int sizeof_vec = dvec.sizeof_compressed_vec;

            sbyte[] cvec = new sbyte[sizeof_vec];

            int sizeof_lights = sizeof_vec;
            int sizeof_darks  = sizeof_vec;

            double[] lights = new double[sizeof_lights];
            double[] darks  = new double[sizeof_darks];

            int dvecptr = 0;
            int pos_lights = 0, pos_darks = 0;

            double dv;

            for (s = 0; s < sizeof_vec; ++s)
            {
                dv = dvec.vec[dvecptr++];
                if (dv >= -context.puzzle_noise_cutoff &&
                    dv <= context.puzzle_noise_cutoff)
                {
                    continue;
                }

                if (dv < context.puzzle_noise_cutoff)
                {
                    darks[pos_darks++] = dv;
                    if (pos_darks > sizeof_darks)
                    {
                        throw new Exception();
                    }
                }
                else if (dv > context.puzzle_noise_cutoff)
                {
                    lights[pos_lights++] = dv;
                    if (pos_lights > sizeof_lights)
                    {
                        throw new Exception();
                    }
                }
            }
            double lighter_cutoff = puzzle_median(lights, pos_lights);
            double darker_cutoff  = puzzle_median(darks, pos_darks);

            dvecptr = 0;
            int cvecptr = 0;

            for (s = 0; s < sizeof_vec; ++s)
            {
                dv = dvec.vec[dvecptr++];
                if (dv >= -context.puzzle_noise_cutoff &&
                    dv <= context.puzzle_noise_cutoff)
                {
                    cvec[cvecptr++] = 0;
                }
                else if (dv < 0.0)
                {
                    cvec[cvecptr++] = (sbyte)(dv < darker_cutoff  ? -2 : -1);
                }
                else
                {
                    cvec[cvecptr++] = (sbyte)(dv > lighter_cutoff ?  2 :  1);
                }
            }
            ;

            if (cvecptr != sizeof_vec)
            {
                throw new Exception();
            }

            return(cvec);
        }
        public static PuzzleDvec puzzle_fill_dvec(PuzzleAvgLvls avglvls)
        {
            int lambdas = avglvls.lambdas;

            PuzzleDvec dvec = new PuzzleDvec();
            dvec.vec = new double[(lambdas * lambdas * PuzzleNative.PUZZLE_NEIGHBORS)];
            int vecur = 0;
            int lx = 0;
            int ly;
            do
            {
                ly = 0;
                do
                {
                    puzzle_add_neighbors(dvec.vec, ref vecur, PuzzleNative.PUZZLE_NEIGHBORS, ref avglvls, lx, ly);
                } while (++ly < lambdas);
            } while (++lx < lambdas);
            dvec.sizeof_compressed_vec = vecur;

            return dvec;
        }
        public static sbyte[] puzzle_fill_cvec_from_dvec(PuzzleContext context, PuzzleDvec dvec)
        {
            if (dvec.sizeof_compressed_vec == 0)
                throw new Exception();

            int s;

            int sizeof_vec = dvec.sizeof_compressed_vec;
            sbyte[] cvec = new sbyte[sizeof_vec];

            int sizeof_lights = sizeof_vec;
            int sizeof_darks  = sizeof_vec;

            double[] lights = new double[sizeof_lights];
            double[] darks  = new double[sizeof_darks];

            int dvecptr = 0;
            int pos_lights = 0, pos_darks = 0;

            double dv;
            for (s = 0; s < sizeof_vec; ++s)
            {
                dv = dvec.vec[dvecptr++];
                if (dv >= -context.puzzle_noise_cutoff &&
                    dv <=  context.puzzle_noise_cutoff)
                    continue;

                if (dv < context.puzzle_noise_cutoff)
                {
                    darks[pos_darks++] = dv;
                    if (pos_darks > sizeof_darks)
                        throw new Exception();
                }
                else if (dv > context.puzzle_noise_cutoff)
                {
                    lights[pos_lights++] = dv;
                    if (pos_lights > sizeof_lights)
                        throw new Exception();
                }
            }
            double lighter_cutoff = puzzle_median(lights, pos_lights);
            double darker_cutoff  = puzzle_median(darks,  pos_darks);

            dvecptr = 0;
            int cvecptr = 0;
            for (s = 0; s < sizeof_vec; ++s)
            {
                dv = dvec.vec[dvecptr++];
                if (dv >= -context.puzzle_noise_cutoff &&
                    dv <=  context.puzzle_noise_cutoff)
                    cvec[cvecptr++] = 0;
                else if (dv < 0.0)
                    cvec[cvecptr++] = (sbyte)(dv < darker_cutoff  ? -2 : -1);
                else
                    cvec[cvecptr++] = (sbyte)(dv > lighter_cutoff ?  2 :  1);
            };

            if (cvecptr != sizeof_vec)
                throw new Exception();

            return cvec;
        }