From 28ebe872bf422e0a4c2ebc251d0a83536e9e8a43 Mon Sep 17 00:00:00 2001 From: malloc-nbytes Date: Fri, 26 Jan 2024 19:33:42 -0600 Subject: [PATCH] psuedo-maze generation is done --- src/graphics.cpp | 19 ++++++++++++ src/include/graphics.h | 9 +++--- src/include/utils.h | 1 + src/main.cpp | 9 +----- src/puzzle.cpp | 37 ++++++++++++++++++++--- src/puzzle1/instructions.html | 57 ----------------------------------- src/utils.cpp | 7 +++++ 7 files changed, 64 insertions(+), 75 deletions(-) delete mode 100644 src/puzzle1/instructions.html diff --git a/src/graphics.cpp b/src/graphics.cpp index f34fbeb..1118dc3 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -37,4 +38,22 @@ void graphics_create_ppm(Image &img, const char *filepath) } std::fclose(fp); +} + +Image graphics_scale_ppm(Image &img, size_t scale) +{ + assert(scale != 0); + Image scaled_img = Image {img.height*scale, img.width*scale}; + + for (size_t i = 0; i < img.height; i++) { + for (size_t j = 0; j < img.width; j++) { + Pixel &color = img(i, j); + for (size_t k = 0; k < scale; k++) { + for (size_t l = 0; l < scale; l++) { + scaled_img(i*scale+k, j*scale+l) = color; + } + } + } + } + return scaled_img; } \ No newline at end of file diff --git a/src/include/graphics.h b/src/include/graphics.h index 674a741..cf41db3 100644 --- a/src/include/graphics.h +++ b/src/include/graphics.h @@ -16,10 +16,9 @@ struct Image { size_t width; size_t height; std::vector pixels; - - inline Image(size_t width, size_t height) - : width(width), height(height), pixels(width*height) {} - + + inline Image(size_t w, size_t h) : width(w), height(h), pixels(w*h) {} + inline Pixel &operator()(size_t i, size_t j) { return pixels[i*width+j]; @@ -27,6 +26,6 @@ struct Image { }; void graphics_create_ppm(Image &img, const char *filepath); - +Image graphics_scale_ppm(Image &img, size_t scale); #endif // GRAPHICS_H \ No newline at end of file diff --git a/src/include/utils.h b/src/include/utils.h index 820268c..95e6bd6 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -9,6 +9,7 @@ typedef std::vector strvec_t; std::string utils_generate_html(std::string title, std::string description, long seed); void utils_generate_file(std::string output_filepath, std::string output_body); int utils_rng_roll(int min, int max, long seed); +int utils_roll_seed(void); strvec_t utils_walkdir(const std::string& path); void utils_zip_files(std::string out_file_name, strvec_t file_names, std::string password=""); std::string utils_file_to_str(const std::string filepath); diff --git a/src/main.cpp b/src/main.cpp index 476f26f..ad606c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,13 +13,6 @@ #include "./include/utils.h" #include "./include/puzzle.h" -int roll_seed(void) -{ - long seed = (uint)time(nullptr); - srand(seed); - return seed; -} - void create_nested_zipfiles(std::vector &puzzles) { const char *zipdir = "zipfiles/puzzle"; @@ -39,7 +32,7 @@ void create_nested_zipfiles(std::vector &puzzles) int main(void) { - long seed = roll_seed(); + long seed = utils_roll_seed(); std::vector puzzles = { puzzle_create1(seed), diff --git a/src/puzzle.cpp b/src/puzzle.cpp index d9aacd3..436befc 100644 --- a/src/puzzle.cpp +++ b/src/puzzle.cpp @@ -1,6 +1,8 @@ +#include #include #include #include +#include #include "./include/utils.h" #include "./include/puzzle.h" @@ -32,17 +34,42 @@ Puzzle puzzle_create2(long seed) return Puzzle{"puzzle2", "331E54F4AA00"}; } +#define MAZE_WALL ({0,0,0}) +#define MAZE_PATH ({255,255,255}) +#define MAZE_SIZE 16 + +void force_unique_shortest_path(Image &img) +{ + (void)img; + assert(false && "unimplemented"); +} + Puzzle puzzle_create3(long seed) { std::string description = utils_file_to_str("./puzzle3/.desc.txt"); std::string html_content = utils_generate_html("Maze Puzzle", description, seed); utils_generate_file("./puzzle3/instructions.html", html_content); - Image img = Image {2,2}; - img(0, 0) = Pixel {0, 0, 0}; - img(0, 1) = Pixel {0, 0, 0}; - img(1, 0) = Pixel {255, 255, 255}; - img(1, 1) = Pixel {255, 255, 255}; + + int s = MAZE_SIZE; + Image img = Image {(size_t)s, (size_t)s}; + for(int i = 0; i < s; i++) { + for(int j = 0; j < s; j++) { + img(i, j) = i%2 ? Pixel MAZE_PATH : Pixel MAZE_WALL; + } + } + + for(int i = 0; i < s; i++) { + img(i, utils_rng_roll(0,s-1,seed+i)) = Pixel MAZE_PATH; + img(i, utils_rng_roll(0,s-1,seed+i*s)) = Pixel MAZE_PATH; + } + + img(0, 0) = Pixel {255, 0, 255}; + img(s-1, s-1) = Pixel {255, 255, 0}; + + img = graphics_scale_ppm(img, 70); + graphics_create_ppm(img, "./puzzle3/maze.ppm"); + return Puzzle{"puzzle3", "uru6r3u3ld"}; } diff --git a/src/puzzle1/instructions.html b/src/puzzle1/instructions.html deleted file mode 100644 index fc4d77c..0000000 --- a/src/puzzle1/instructions.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - -Document - - - -
-
-
-

Lipscomb University | College of Computing

-
-

Pointless
Challenge

-

Pointless
Challenge

-
-
- -
-
-
- - -

Hello Pointless

Welcome to the Pointless Computing Challenge! - -This Mission Briefing contains everything you need to complete your personal challenge, however you should feel free to use additional resources, including the whole Internet. -

-Your mission, should you choose to accept it, is a classic Fetch Quest involving several Plot Coupons and ultimately the coveted MacGuffin. While It's the Journey That Counts, you may periodically claim pointless Victory Points by recording your progress at lipscomb.challenge.edu. You can even do it right now using this Free Sample Coupon "H3fisE7jkQ0W". -https://latimesblogs.latimes.com/technology/2011/08/google-vic-gundotra-steve-jobs.html -Computers are good at following instructions, but not at reading your mind. -- Donald Knuth -

-As you might expect, you need a Plot Coupon to unlock the next Level. For the first challenge... what is 4+8?

- -
-