Skip to content

Commit

Permalink
Keep BIT_PATH after maze generation
Browse files Browse the repository at this point in the history
It's the more intuitive thing to do and it comes at no cost.
  • Loading branch information
TurkeyMcMac committed Mar 15, 2021
1 parent cf5a8d8 commit 3120664
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/maze.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void remove_intermediate_bits(struct maze *maze)
int x, y;
for (y = 0; y < maze->height; y += 2) {
for (x = 0; x < maze->width; x += 2) {
MAZE_GET(maze, x, y) &= ~(BIT_ADDED | BIT_PATH);
MAZE_GET(maze, x, y) &= ~BIT_ADDED;
}
}
}
Expand All @@ -123,9 +123,11 @@ static void connect_paths(struct maze *maze)
for (x = 0; x < maze->width; x += 2) {
TILE_TYPE t = MAZE_GET(maze, x, y);
if (t & BIT_RIGHT)
MAZE_GET(maze, x + 1, y) = BIT_LEFT | BIT_RIGHT;
MAZE_GET(maze, x + 1, y) =
BIT_PATH | BIT_LEFT | BIT_RIGHT;
if (t & BIT_DOWN)
MAZE_GET(maze, x, y + 1) = BIT_UP | BIT_DOWN;
MAZE_GET(maze, x, y + 1) =
BIT_PATH | BIT_UP | BIT_DOWN;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/maze.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* and consequently the bottom right tile will be a node just as the top left
* will be. Going from the top left to the bottom right, following the path
* directions specified by the tile bits will never lead one to out-of-bounds
* coordinates, and all nodes will be reachable along the way. */
* coordinates, and all nodes will be reachable along the way. All tiles part of
* the path are marked with BIT_PATH. */
struct maze {
int width, height;
TILE_TYPE *tiles;
Expand Down
18 changes: 9 additions & 9 deletions src/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ typedef unsigned char TILE_TYPE;
#define BIT_LEFT 0x04
#define BIT_DOWN 0x08

/* These bits used while making the maze and are cleared afterward. They can be
* reused later. */
/* The tile has been added to the list of heads. */
#define BIT_ADDED 0x10
/* A path has been placed in the tile. */
#define BIT_PATH 0x20
#define BIT_PATH 0x10

/* The tile has been added to the list of heads. This bit is used while making
* the maze and is cleared afterward. It can be reused later.*/
#define BIT_ADDED 0x20

/* This bit shows that the player sees the tile. (Reused BIT_ADDED.) */
#define BIT_PLAYER_SEEN 0x10
#define BIT_PLAYER_SEEN 0x20

/* This bit shows that a monster is obstructing the tile. (Reused BIT_PATH.) */
#define BIT_MONSTER 0x20
/* This bit shows that a monster is obstructing the tile. */
#define BIT_MONSTER 0x40

/* This bit shows that there's cash in the tile. */
#define BIT_CASH 0x40
#define BIT_CASH 0x80

#endif /* TILE_H_ */
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* The version of the program: */
#define VERSION "0.5.10"
#define VERSION "0.5.11"

0 comments on commit 3120664

Please sign in to comment.