struggling with dof ("ddl")

This commit is contained in:
quenousimporte 2025-04-15 14:21:45 +02:00
parent 1dbfd68878
commit d094973e6b
1 changed files with 48 additions and 15 deletions

61
w/w.c
View File

@ -576,25 +576,24 @@ char gentile(int x, int y)
if (d == 1)
{
c = TILE_DOOR;
ddl++;
}
else if (d < 5 && ddl > 1)
{
c = TILE_WALL;
ddl--;
}
else
{
c = TILE_FREE;
ddl++;
}
setatpos(x, y, c);
return c;
}
return TILE_UNUSED;
}
void updatemap()
{
//ddl--;
int x = state.position.x;
int y = state.position.y;
@ -602,37 +601,70 @@ void updatemap()
char c = gentile(x, y - 1);
if (c == TILE_FREE)
{
ddl--;
ddl++;
gentile(x - 1, y - 2);
gentile(x + 1, y - 2);
}
else if (c == TILE_DOOR)
{
ddl++;
}
else if (c != TILE_UNUSED)
{
ddl--;
}
// south
c = gentile(x, y + 1);
if (c == TILE_FREE)
{
ddl--;
ddl++;
gentile(x - 1, y + 2);
gentile(x + 1, y + 2);
}
else if (c == TILE_DOOR)
{
ddl++;
}
else if (c != TILE_UNUSED)
{
ddl--;
}
// east
c = gentile(x + 1, y);
if (c == TILE_FREE)
{
ddl--;
ddl++;
gentile(x + 2, y - 1);
gentile(x + 2, y + 1);
}
else if (c == TILE_DOOR)
{
ddl++;
}
else if (c != TILE_UNUSED)
{
ddl--;
}
// west
c = gentile(x - 1, y);
if (c == TILE_FREE)
{
ddl--;
ddl++;
gentile(x - 2, y - 1);
gentile(x - 2, y + 1);
}
else if (c == TILE_DOOR)
{
ddl++;
}
else if (c != TILE_UNUSED)
{
ddl--;
}
}
void dfs(int x, int y)
@ -687,8 +719,8 @@ void dfs(int x, int y)
void initmap()
{
//memset(&map, TILE_UNKNOWN, MAP_SIZE * MAP_SIZE);
memset(&map, TILE_WALL, MAP_SIZE * MAP_SIZE); // dfs: put walls everywhere
memset(&map, TILE_UNKNOWN, MAP_SIZE * MAP_SIZE);
//memset(&map, TILE_WALL, MAP_SIZE * MAP_SIZE); // dfs: put walls everywhere
// dfs: add random room
for (int x = 0; x < MAP_SIZE; x ++)
@ -705,15 +737,16 @@ void initmap()
setatpos(x, y, TILE_WALL); // => instead of TILE_UNUSED, for readibility
//setatpos(x + 1, y + 1, TILE_FREE);
setatpos(x + 1, y + 1, TILE_UNVISITED); // dfs
setatpos(x + 1, y + 1, TILE_FREE);
//setatpos(x + 1, y + 1, TILE_UNVISITED); // dfs
}
setatpos(x + 1, 0, TILE_WALL);
setatpos(x + 1, 14, TILE_WALL);
}
// setatpos(1, 13, TILE_FREE);
dfs(1,13);
//dfs(1,13);
ddl = 0;
}
void update(char* command)
@ -728,7 +761,7 @@ void update(char* command)
int x = state.position.x;
int y = state.position.y;
forward();
//updatemap();
updatemap();
if ( (x != state.position.x || y != state.position.y) && dice() > 4)
{
// gotomonster();
@ -776,7 +809,7 @@ void update(char* command)
state.position.orientation = NORTH;
initmap();
//updatemap();
updatemap();
updatepov();
}
else if (c == CMD_GOTOMARKET)