Skip to content

Commit

Permalink
updated file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
malloc-nbytes committed Jan 27, 2024
1 parent 28ebe87 commit c1cfd5f
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 167 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Prerequisites
*.d

*.ppm
*.html

# Compiled Object files
*.slo
*.lo
Expand Down Expand Up @@ -37,4 +40,4 @@ testdata/
secrets/
.DS_Store
makefile
Makefile
Makefile
11 changes: 8 additions & 3 deletions plans.org
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@
- Randomly mess it up and have the user fix it

* Maze Puzzle
- TODO [25%]
- [X] PPM Generation
- [ ] Only 1 shortest path
- [ ] Multiple paths
- [ ] Final solution
- Generate 8x8 (or maybe 10x10) maze
- Constraints:
1. Must have multiple paths, but only 1 shortest path.
2. The start and end must be at opposite corners.
3. The solution must contains compression (all duplicate letters must be in compressed)
1. Must have multiple paths, but only 1 shortest path.
2. The start and end must be at opposite corners.
3. The solution must contains compression (all duplicate letters must be in compressed)

* Meta Final Puzzle
- Hidden messages/symbols in previous instructions.
Expand Down
6 changes: 3 additions & 3 deletions src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ set -xe

CXXFLAGS="-ggdb -pedantic -std=c++20 -Wextra -Wall -o main"
CXXLINKS="-lboost_iostreams -lzip -lboost_unit_test_framework"
CXXDEPS="./utils.cpp ./puzzle.cpp ./graphics.cpp"
CXXDEPS="./*.cpp"

if [ "$1" == "c" ];
then
rm -rf main *.zip ./zipfiles/*
elif [ "$1" == "a" ];
then
./build.sh c
g++ $CXXFLAGS $CXXDEPS main.cpp $CXXLINKS
g++ $CXXFLAGS $CXXDEPS $CXXLINKS
else
g++ $CXXFLAGS $CXXDEPS main.cpp $CXXLINKS
g++ $CXXFLAGS $CXXDEPS $CXXLINKS
fi
10 changes: 10 additions & 0 deletions src/color-puzzle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "./include/utils.h"
#include "./include/color-puzzle.h"

Puzzle color_puzzle_create(long seed)
{
std::string description = utils_file_to_str("./files-color/.desc.txt");
std::string html_content = utils_generate_html("Color Puzzle", description, seed);
utils_generate_file("./files-color/instructions.html", html_content);
return Puzzle{"files-color", "331E54F4AA00"};
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions src/fin-puzzle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "./include/fin-puzzle.h"

Puzzle fin_puzzle_create(long seed)
{
(void)seed;
return Puzzle{"files-fin", ""};
}
8 changes: 8 additions & 0 deletions src/include/color-puzzle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef COLOR_PUZZLE_H
#define COLOR_PUZZLE_H

#include "./puzzle.h"

Puzzle color_puzzle_create(long seed);

#endif // COLOR_PUZZLE_H
8 changes: 8 additions & 0 deletions src/include/fin-puzzle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef FIN_PUZZLE_H
#define FIN_PUZZLE_H

#include "./puzzle.h"

Puzzle fin_puzzle_create(long seed);

#endif // FIN_PUZZLE_H
8 changes: 8 additions & 0 deletions src/include/math-puzzle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef MATH_PUZZLE_H
#define MATH_PUZZLE_H

#include "./puzzle.h"

Puzzle math_puzzle_create(long seed);

#endif // MATH_PUZZLE_H
12 changes: 12 additions & 0 deletions src/include/maze-puzzle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef MAZE_PUZZLE_H
#define MAZE_PUZZLE_H

#include "./puzzle.h"

#define MAZE_WALL ({0,0,0})
#define MAZE_PATH ({255,255,255})
#define MAZE_SIZE 16

Puzzle maze_puzzle_create(long seed);

#endif // MAZE_PUZZLE_H
2 changes: 2 additions & 0 deletions src/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <vector>
#include <string>

#define BOLD(s) "<b>" + (s) + "</b>"

typedef std::vector<std::string> strvec_t;

std::string utils_generate_html(std::string title, std::string description, long seed);
Expand Down
20 changes: 0 additions & 20 deletions src/include/zipper.h

This file was deleted.

20 changes: 16 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include "./include/html-generator.h"
#include "./include/utils.h"
#include "./include/puzzle.h"
#include "./include/math-puzzle.h"
#include "./include/color-puzzle.h"
#include "./include/maze-puzzle.h"
#include "./include/fin-puzzle.h"

void create_nested_zipfiles(std::vector<Puzzle> &puzzles)
{
Expand All @@ -30,15 +34,23 @@ void create_nested_zipfiles(std::vector<Puzzle> &puzzles)
}
}

void usage(const char *prog_name)
{
std::printf("Usage: %s [OPTIONS]...\n", prog_name);
std::printf(" -h, --help Print this help message and exit.\n");
std::printf(" -c, --clean Cleans the generated files.\n");
std::exit(EXIT_FAILURE);
}

int main(void)
{
long seed = utils_roll_seed();

std::vector<Puzzle> puzzles = {
puzzle_create1(seed),
puzzle_create2(seed),
puzzle_create3(seed),
puzzle_create4(seed),
math_puzzle_create(seed),
color_puzzle_create(seed),
maze_puzzle_create(seed),
fin_puzzle_create(seed),
};

create_nested_zipfiles(puzzles);
Expand Down
18 changes: 18 additions & 0 deletions src/math-puzzle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "./include/math-puzzle.h"
#include "./include/utils.h"

Puzzle math_puzzle_create(long seed)
{
// TODO: Change in final version to bigger numbers.
int a = utils_rng_roll(1, 5, seed);
int b = utils_rng_roll(6, 9, seed);
int s = a+b;
std::string description = utils_file_to_str("./files-math/.desc.txt");
std::string question = BOLD("what is " + std::to_string(a) + "+" + std::to_string(b) + "?");
description.append(question);

std::string html_content = utils_generate_html("Hello Pointless", description, seed);

utils_generate_file("./files-math/instructions.html", html_content);
return Puzzle{"files-math", std::to_string(s)};
}
41 changes: 41 additions & 0 deletions src/maze-puzzle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <cassert>

#include "./include/maze-puzzle.h"
#include "./include/puzzle.h"
#include "./include/utils.h"
#include "./include/graphics.h"

// void force_unique_shortest_path(Image &img)
// {
// (void)img;
// assert(false && "unimplemented");
// }

Puzzle maze_puzzle_create(long seed)
{
std::string description = utils_file_to_str("./files-maze/.desc.txt");
std::string html_content = utils_generate_html("Maze Puzzle", description, seed);
utils_generate_file("./files-maze/instructions.html", html_content);

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, "./files-maze/maze.ppm");

return Puzzle{"files-maze", "uru6r3u3ld"};
}
32 changes: 7 additions & 25 deletions src/puzzle.cpp → src/puzzle.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,12 @@
#include "./include/puzzle.h"
#include "./include/graphics.h"

#define BOLD(s) "<b>" + (s) + "</b>"

Puzzle puzzle_create1(long seed)
{
// TODO: Change in final version to bigger numbers.
int a = utils_rng_roll(1, 5, seed);
int b = utils_rng_roll(6, 9, seed);
int s = a+b;
std::string description = utils_file_to_str("./puzzle1/.desc.txt");
std::string question = BOLD("what is " + std::to_string(a) + "+" + std::to_string(b) + "?");
description.append(question);

std::string html_content = utils_generate_html("Hello Pointless", description, seed);

utils_generate_file("./puzzle1/instructions.html", html_content);
return Puzzle{"puzzle1", std::to_string(s)};
}

Puzzle puzzle_create2(long seed)
{
std::string description = utils_file_to_str("./puzzle2/.desc.txt");
std::string description = utils_file_to_str("./files-color/.desc.txt");
std::string html_content = utils_generate_html("Color Puzzle", description, seed);
utils_generate_file("./puzzle2/instructions.html", html_content);
return Puzzle{"puzzle2", "331E54F4AA00"};
utils_generate_file("./files-color/instructions.html", html_content);
return Puzzle{"./files-color", "331E54F4AA00"};
}

#define MAZE_WALL ({0,0,0})
Expand All @@ -46,9 +28,9 @@ void force_unique_shortest_path(Image &img)

Puzzle puzzle_create3(long seed)
{
std::string description = utils_file_to_str("./puzzle3/.desc.txt");
std::string description = utils_file_to_str("./files-maze/.desc.txt");
std::string html_content = utils_generate_html("Maze Puzzle", description, seed);
utils_generate_file("./puzzle3/instructions.html", html_content);
utils_generate_file("./files-maze/instructions.html", html_content);

int s = MAZE_SIZE;
Image img = Image {(size_t)s, (size_t)s};
Expand All @@ -68,9 +50,9 @@ Puzzle puzzle_create3(long seed)

img = graphics_scale_ppm(img, 70);

graphics_create_ppm(img, "./puzzle3/maze.ppm");
graphics_create_ppm(img, "./files-maze/maze.ppm");

return Puzzle{"puzzle3", "uru6r3u3ld"};
return Puzzle{"files-maze", "uru6r3u3ld"};
}

Puzzle puzzle_create4(long seed)
Expand Down
59 changes: 0 additions & 59 deletions src/puzzle2/instructions.html

This file was deleted.

Loading

0 comments on commit c1cfd5f

Please sign in to comment.