drop live generation and improve dfs

This commit is contained in:
quenousimporte 2025-04-16 16:08:26 +02:00
parent d094973e6b
commit 0265c3a8d0
1 changed files with 47 additions and 101 deletions

148
w/w.c
View File

@ -91,7 +91,7 @@ Round* firstround = NULL;
Round* currentround = NULL; Round* currentround = NULL;
char map[MAP_SIZE * MAP_SIZE]; char map[MAP_SIZE * MAP_SIZE];
int ddl;
Character monsters[2] = { Character monsters[2] = {
{ "alien bleu", 2, 2, 1, 1 }, { "alien bleu", 2, 2, 1, 1 },
{ "vilaine araignée", 5, 8, 2, 1 } { "vilaine araignée", 5, 8, 2, 1 }
@ -133,6 +133,7 @@ void setatpos(int x, int y, char c)
void drawmap() void drawmap()
{ {
for (int y = 0; y < MAP_SIZE; y++) { for (int y = 0; y < MAP_SIZE; y++) {
printf("%02d ", y);
for (int x = 0; x < MAP_SIZE; x++) { for (int x = 0; x < MAP_SIZE; x++) {
char toprint = charatpos(x,y); char toprint = charatpos(x,y);
if (y == state.position.y && x == state.position.x) if (y == state.position.y && x == state.position.x)
@ -146,7 +147,11 @@ void drawmap()
} }
printf("\n"); printf("\n");
} }
printf("ddl=%d\n", ddl); printf(" ");
for (int x = 0; x < MAP_SIZE; x++) {
printf("%d", x % 10);
}
printf("\n\n");
} }
void drawpov3d() void drawpov3d()
@ -577,7 +582,7 @@ char gentile(int x, int y)
{ {
c = TILE_DOOR; c = TILE_DOOR;
} }
else if (d < 5 && ddl > 1) else if (d < 5)
{ {
c = TILE_WALL; c = TILE_WALL;
} }
@ -591,85 +596,12 @@ char gentile(int x, int y)
return TILE_UNUSED; return TILE_UNUSED;
} }
void updatemap()
{
//ddl--;
int x = state.position.x;
int y = state.position.y;
// north
char c = gentile(x, y - 1);
if (c == TILE_FREE)
{
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++;
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++;
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++;
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)
{ {
if (charatpos(x,y) != TILE_START)
{
setatpos(x, y, TILE_FREE); setatpos(x, y, TILE_FREE);
}
bool nok = false; bool nok = false;
bool eok = false; bool eok = false;
@ -719,34 +651,50 @@ 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_UNKNOWN, MAP_SIZE * MAP_SIZE); // dfs: put walls everywhere
// dfs: add random room
for (int x = 0; x < MAP_SIZE; x ++) for (int x = 0; x < MAP_SIZE; x ++)
{
for (int y = 0; y < MAP_SIZE; y++) for (int y = 0; y < MAP_SIZE; y++)
if (dice() > 4)
// setatpos(x, y, TILE_FREE);
for (int x = 0; x < MAP_SIZE; x += 2)
{ {
for (int y = 14; y >=0; y -= 2) if (x == 0 || y == 0 || x == MAP_SIZE - 1 || y == MAP_SIZE - 1)
{ {
setatpos(0, y - 1, TILE_WALL); // boundaries
setatpos(14, y - 1, TILE_WALL); setatpos(x, y, TILE_WALL);
}
setatpos(x, y, TILE_WALL); // => instead of TILE_UNUSED, for readibility else if (x % 2 && y % 2)
{
setatpos(x + 1, y + 1, TILE_FREE); // free tiles (or unvisited for dfs)
//setatpos(x + 1, y + 1, TILE_UNVISITED); // dfs setatpos(x, y, TILE_UNVISITED);
}
else if (!(x % 2 ) && !(y % 2))
{
// unused tiles aka "poles"
//setatpos(x, y, TILE_UNUSED);
//... or walls for readibility on map
setatpos(x, y, TILE_WALL);
}
else
{
// init all intersections with walls
setatpos(x, y, TILE_WALL);
//... and put a few free tiles here and there to create bigger rooms
if (dice() == 1)
{
setatpos(x, y, TILE_FREE);
}
}
} }
setatpos(x + 1, 0, TILE_WALL);
setatpos(x + 1, 14, TILE_WALL);
} }
// setatpos(1, 13, TILE_FREE); // starting point
//dfs(1,13); setatpos(1, 13, TILE_START);
ddl = 0;
// create map
dfs(1,13);
} }
void update(char* command) void update(char* command)
@ -761,7 +709,6 @@ 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();
if ( (x != state.position.x || y != state.position.y) && dice() > 4) if ( (x != state.position.x || y != state.position.y) && dice() > 4)
{ {
// gotomonster(); // gotomonster();
@ -809,7 +756,6 @@ void update(char* command)
state.position.orientation = NORTH; state.position.orientation = NORTH;
initmap(); initmap();
updatemap();
updatepov(); updatepov();
} }
else if (c == CMD_GOTOMARKET) else if (c == CMD_GOTOMARKET)