#include <stdio.h>
#include <stdint.h>
#include "temperatureLib.h"

int isValid(DoublePerlinNoise* dpn, uint64_t seed)
{
    for(int z = 0; z < 32; z++)
    {
        for(int x = 0; x < 32; x++)
        {
            float sample = sampleDoublePerlin(dpn, 8, (float)x, 0.0, (float)z);
            if( !(-0.0125 < sample && sample < 0.0125)) return 0;
        }
    }
    return 1;
}

void printSlice(DoublePerlinNoise* dpn, int x, int y, int z)
{
    for(int j = -32; j < 32; j++)
    {
        for(int i = -32; i < 32; i++)
        {
            float sample = sampleDoublePerlin(dpn, 8, (float)(x + i)*4, (float)y, (float)(z + j)*4 );
            if( -0.0125 < sample && sample < 0.0125)
            {
                printf("# ");
            }
            else
            {
                printf("_ ");
            }
        }
        printf("\n");
    }
}

//this will reverse engineer the way standard perlin noise works
int main()
{

    NoiseParameters np = (NoiseParameters){
        .name = "minecraft:iceberg_surface",
        .firstOctave = -6,
        .firstAmplitude = 1.0,
        .ampCount = 2,
        .amplitudes = (float[]){1.0, 1.0},
    };

    md5NoiseCalc(&np);

    //printSlice(927732ULL, 0, 0, 0);
    DoublePerlinNoise dpn;
    for(uint64_t i = 0; i < 1000000000; i++)
    {
        init_climate_seed(&dpn, &np, i, 8);
        //printSlice(&dpn, 0, 0, 0);
        if(isValid(&dpn, i)) 
        {
            printSlice(&dpn, 0, 0, 0);
            printf("%ld\n\n", i);
        }
    }
}