aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c53
1 files changed, 33 insertions, 20 deletions
diff --git a/main.c b/main.c
index 1142134..747254d 100644
--- a/main.c
+++ b/main.c
@@ -3,16 +3,20 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
+
#include "map.h"
#include "structs.h"
#include "config.h"
#include "error.h"
#include "priority_queue.h"
+#include "path.h"
/* So, TODO for now:
- - Implement Dijkstra and greedy-best-first search algorithms
+ - Implement Dijkstra algorithm
- Implement the A* algorithm
- Implement it with 4 and 8 directions
+ - Add ability to see visited squares
+ - MORE MAPS FOR THE MAP PEOPLE
- Implement adding maps from files (with rle, preferably)
- Implement controls (to change maps, move start/goal, etc.)
- Clean up unused `#include`s */
@@ -28,47 +32,56 @@ void initialize_colors(void) {
start_color();
use_default_colors();
init_pair(EMPTY_COLOR, COLOR_BLACK, -1);
- init_pair(GOAL_COLOR, COLOR_RED, -1);
+ init_pair(GOAL_COLOR, -1, COLOR_RED);
init_pair(WALL_COLOR, COLOR_WHITE, COLOR_WHITE); /* Using white as bg makes
them seem solid */
- init_pair(START_COLOR, COLOR_RED, -1);
+ init_pair(START_COLOR, -1, COLOR_RED);
+ init_pair(PATH_COLOR, COLOR_RED, COLOR_RED);
}
-int main(void) {
- signal(SIGINT, sigint_handler);
-
+void init_ncurses(void) {
initscr(); /* Initialize the ncurses screen */
cbreak(); /* Process input one char at a time */
curs_set(0); /* Hide the cursor */
noecho(); /* Don't echo characters */
initialize_colors();
+}
- /* FIXME: shitty. sometimes leaves enough space on the right for a bigger map */
- /* size_t height = LINES/2 - DRAW_MAP_OFFSET_Y,
- width = COLS/4 - 1;
- Map map = rbt_maze_map(width, height, (unsigned int) time(NULL));
- Position fake_start_position_to_pass_into_draw_map = {0, 0};
- Position fake_goal_position_to_pass_into_draw_map = {width*2-2, height*2-2}; */
+int main(void) {
+ signal(SIGINT, sigint_handler);
- size_t width, height;
- Position start_pos, end_pos;
- Map map = file_plaintext_map("maps/test", &width, &height, &start_pos, &end_pos);
+ init_ncurses();
+ size_t mwidth = 20;
+ size_t mheight = 10;
+ Map map = rbt_maze_map(mwidth, mheight, (unsigned int) time(NULL));
+ Position start_pos = {0, 0};
+ Position end_pos = {mwidth*2-2, mheight*2-2};
+ size_t height = mheight * 2 - 1;
+ size_t width = mwidth * 2 - 1;
int offset_x = 0, offset_y = 0;
+
+ //size_t width, height;
+ //Position start_pos, end_pos;
+ //Map map = file_plaintext_map("maps/test", &width, &height, &start_pos, &end_pos);
+ //print_map_out(map, width, height);
+ draw_map(map, width, height, offset_x, offset_y, start_pos, end_pos, NULL);
+
+ Path path = breadth_first_search_path_4dir(map, width, height, start_pos, end_pos);
+
while (1) {
- draw_map(map, width, height, offset_x, offset_y, start_pos, end_pos);
+ draw_map(map, width, height, offset_x, offset_y, start_pos, end_pos, path);
char c = getch();
switch (c) {
case 'h': offset_x -= 2; break;
case 'l': offset_x += 2; break;
case 'j': offset_y += 1; break;
case 'k': offset_y -= 1; break;
- /*
case 'n':
- FIXME: free it before generating a new one
- map = rbt_maze_map(width, height, (unsigned int) time(NULL));
+ //FIXME: free it all before generating a new one
+ map = rbt_maze_map(mwidth, mheight, (unsigned int) time(NULL));
+ path = breadth_first_search_path_4dir(map, width, height, start_pos, end_pos);
break;
- */
case 'q': endwin(); return 0;
}
}