#include #include #include #include #include #include #include // octothorpe #include "rand.h" #include "stuff.h" #define HEIGHT 8 #define WIDTH 16 enum type { type0, type_dangling, type2a, // ┃, ━ 2 rotations possible type2b, // ┏, ┓, ┛, ┗ all 4 rotations possible type3, // ┣, ┳, ┫, ┻ all 4 rotations possible type4 // ╉ no rotation are possible }; // bitmask enum cell_joints { right= (1<<0), left= (1<<1), top= (1<<2), bottom= (1<<3) }; // top, right, bottom, left enum type types[]={ /*0000*/ type0, /*0001*/ type_dangling, /*0010*/ type_dangling, /*0011*/ type2b, // "┓" /*0100*/ type_dangling, /*0101*/ type2a, // "━" /*0110*/ type2b, // "┏" /*0111*/ type3, // "┳" /*1000*/ type_dangling, /*1001*/ type2b, // "┛" /*1010*/ type2a, // "┃" /*1011*/ type3, // "┫" /*1100*/ type2b, // "┗" /*1101*/ type3, // "┻" /*1110*/ type3, // "┣" /*1111*/ type4, // "╋" }; // array of strings instead of string, because pseudo-graphical symbols are encoded in UTF-8 // top, right, bottom, left char* symbols[]={ /*0000*/ " ", /*0001*/ "○", // dangling /*0010*/ "○", // dangling /*0011*/ "┓", /*0100*/ "○", // dangling /*0101*/ "━", /*0110*/ "┏", /*0111*/ "┳", /*1000*/ "○", // dangling /*1001*/ "┛", /*1010*/ "┃", /*1011*/ "┫", /*1100*/ "┗", /*1101*/ "┻", /*1110*/ "┣", /*1111*/ "╋" }; // vertical and horizontal joints bool vjoints[HEIGHT+1][WIDTH]; bool hjoints[HEIGHT][WIDTH+1]; int get_joints_of_cell (int r, int c) { bool top=vjoints[r][c]; bool bottom=vjoints[r+1][c]; bool left=hjoints[r][c]; bool right=hjoints[r][c+1]; return (top<<3) | (right<<2) | (bottom<<1) | left; }; int count_empty_cells() { int empty_cells=0; // enumerate cells for (int r=0; r20); // make it slightly more denser //printf ("empty_cells=%d\n", empty_cells); print_cells(/* shuffle_rotations */ false); print_cells(/* shuffle_rotations */ true); print_cell_types(); }; int main() { sgenrand (time(NULL)); gen_puzzle(); };