예제 #1
0
 internal void PrepareValues(int seed, int terrainSize, int quantity, int evaluationFunction, int octave)
 {
     // Preparing the Random Seed and other Stuff
     this.evaluationFunction = evaluationFunction;
     this.octaveHelper       = octave * 2;
     rng             = new Random(seed);
     sizeCompensator = TerrainUtilities.GetSizeCompensator(terrainSize);
     CreateGrid(terrainSize, (float)quantity);
 }
예제 #2
0
        internal float Evaluate(int x, int z)
        {
            float value = 0;

            if (cellSize > 3)
            {
                int[] cellAndNeighbourCells = TerrainUtilities.GetPositionAndNeighbours((x + cellSize * octaveHelper) / cellSize, (z + cellSize * octaveHelper) / cellSize, cellQuantity);

                float[] distances = new float[cellAndNeighbourCells.Length];
                for (int i = 0; i < cellAndNeighbourCells.Length; i++)
                {
                    // Euclidian Distance
                    int lengthX = 0;
                    int lengthZ = 0;
                    if (x > featurePoints[cellAndNeighbourCells[i], 0])
                    {
                        lengthX = x - featurePoints[cellAndNeighbourCells[i], 0];
                    }
                    else
                    {
                        lengthX = featurePoints[cellAndNeighbourCells[i], 0] - x;
                    }
                    if (z > featurePoints[cellAndNeighbourCells[i], 1])
                    {
                        lengthZ = z - featurePoints[cellAndNeighbourCells[i], 1];
                    }
                    else
                    {
                        lengthZ = featurePoints[cellAndNeighbourCells[i], 1] - z;
                    }
                    float currentDistance = (float)Math.Sqrt((double)(lengthX * lengthX + lengthZ * lengthZ));

                    distances[i] = currentDistance;
                }
                Array.Sort(distances);

                value = distances[evaluationFunction - 1] / (sizeCompensator * 2);
            }


            return(value);
        }