Salut, je codé l'ago diamondSquare mais le rendu est parfois bizarre. J'aimerai savoir ce que vous pensez du code :

Code C : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void genere(int tab[][TAILLE], int x, int y, int distance)
{
 
    if(x+distance>=TAILLE || x-distance<0 || y+distance>=TAILLE || y-distance<0)
        distance--;
 
    int a = tab[y-distance][x-distance], b = tab[y-distance][x+distance], c = tab[y+distance][x+distance], d = tab[y+distance][x-distance],
        e = (a+b+c+d)/4 + random(0, distance);
 
    tab[y][x] = e;
    tab[y-distance][x] = (a+b+e)/3 + random(0, distance); // G
    tab[y][x+distance] = (b+d+e)/3 + random(0, distance); // H
    tab[y+distance][x] = (c+d+e)/3 + random(0, distance); // I
    tab[y][x-distance] = (a+c+e)/3 + random(0, distance); // F
 
    if(distance > 1)
    {
        genere(tab, x-distance/2, y-distance/2, distance/2);
        genere(tab, x+distance/2, y-distance/2, distance/2);
        genere(tab, x+distance/2, y+distance/2, distance/2);
        genere(tab, x-distance/2, y+distance/2, distance/2);
    }
}

Je ne vois pas où pourrait étre le beug, mais j'ai parfois de très (très) haut sommets.

EDIT: Il faut des terrain de taille 2^n + 1, mais pensez-vous que la manière récursive est une bonne chose ? L'algo n'est-il pas faux du coup ?