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