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