improve dfs
This commit is contained in:
parent
becd1b6f60
commit
eeb45106ee
23
w/w.c
23
w/w.c
|
@ -440,18 +440,22 @@ void dfs(int x, int y)
|
||||||
setatpos(x, y, TILE_ROOM);
|
setatpos(x, y, TILE_ROOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nok = false;
|
int directions[4] = { NORTH, EAST, SOUTH, WEST };
|
||||||
bool eok = false;
|
// Shuffle the directions array
|
||||||
bool sok = false;
|
for (int i = 3; i > 0; i--)
|
||||||
bool wok = false;
|
{
|
||||||
|
int j = rand() % (i + 1);
|
||||||
|
int temp = directions[i];
|
||||||
|
directions[i] = directions[j];
|
||||||
|
directions[j] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
while (! (nok && eok && sok && wok))
|
// todo refactor
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
char orientation = rand() % 4;
|
switch (directions[i])
|
||||||
switch (orientation)
|
|
||||||
{
|
{
|
||||||
case NORTH:
|
case NORTH:
|
||||||
nok = true;
|
|
||||||
if (charatpos(x, y - 2) == TILE_INIT)
|
if (charatpos(x, y - 2) == TILE_INIT)
|
||||||
{
|
{
|
||||||
setatpos(x, y - 1, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
setatpos(x, y - 1, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
||||||
|
@ -459,7 +463,6 @@ void dfs(int x, int y)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SOUTH:
|
case SOUTH:
|
||||||
sok = true;
|
|
||||||
if (charatpos(x, y + 2) == TILE_INIT)
|
if (charatpos(x, y + 2) == TILE_INIT)
|
||||||
{
|
{
|
||||||
setatpos(x, y + 1, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
setatpos(x, y + 1, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
||||||
|
@ -467,7 +470,6 @@ void dfs(int x, int y)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EAST:
|
case EAST:
|
||||||
eok = true;
|
|
||||||
if (charatpos(x - 2, y) == TILE_INIT)
|
if (charatpos(x - 2, y) == TILE_INIT)
|
||||||
{
|
{
|
||||||
setatpos(x - 1, y, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
setatpos(x - 1, y, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
||||||
|
@ -475,7 +477,6 @@ void dfs(int x, int y)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WEST:
|
case WEST:
|
||||||
wok = true;
|
|
||||||
if (charatpos(x + 2, y) == TILE_INIT)
|
if (charatpos(x + 2, y) == TILE_INIT)
|
||||||
{
|
{
|
||||||
setatpos(x + 1, y, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
setatpos(x + 1, y, dice() == 6 ? TILE_DOOR : TILE_FREE);
|
||||||
|
|
Loading…
Reference in New Issue