diff options
Diffstat (limited to 'ext/wittle_generator/Generate.cpp')
| -rw-r--r-- | ext/wittle_generator/Generate.cpp | 57 |
1 files changed, 44 insertions, 13 deletions
| diff --git a/ext/wittle_generator/Generate.cpp b/ext/wittle_generator/Generate.cpp index 22c211f..5776386 100644 --- a/ext/wittle_generator/Generate.cpp +++ b/ext/wittle_generator/Generate.cpp | |||
| @@ -55,6 +55,33 @@ void Generate::initPanel() { | |||
| 55 | init_treehouse_layout(); | 55 | init_treehouse_layout(); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | if (_custom_grid.size() > | ||
| 59 | 0) { // If we want to start with a certain default grid when generating | ||
| 60 | if (_custom_grid.size() < _panel->width()) { | ||
| 61 | _custom_grid.resize(_panel->width()); | ||
| 62 | } | ||
| 63 | if (_custom_grid[_custom_grid.size() - 1].size() < _panel->height()) { | ||
| 64 | for (auto& row : _custom_grid) { | ||
| 65 | row.resize(_panel->height()); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | for (int x = 0; x < _panel->width(); x++) { | ||
| 69 | for (int y = 0; y < _panel->height(); y++) { | ||
| 70 | set(x, y, _custom_grid[x][y]); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | // Sync up start/exit points between panel and generator. If both are | ||
| 75 | // different, the generator's start/exit point list will be used | ||
| 76 | for (Point e : _starts) { | ||
| 77 | _panel->SetGridSymbol(e.first, e.second, Decoration::Start, | ||
| 78 | Decoration::Color::None); | ||
| 79 | } | ||
| 80 | for (Point e : _exits) { | ||
| 81 | _panel->SetGridSymbol(e.first, e.second, Decoration::Exit, | ||
| 82 | Decoration::Color::None); | ||
| 83 | } | ||
| 84 | |||
| 58 | // Fill gridpos with every available grid block | 85 | // Fill gridpos with every available grid block |
| 59 | _gridpos.clear(); | 86 | _gridpos.clear(); |
| 60 | for (int x = 1; x < _panel->width(); x += 2) { | 87 | for (int x = 1; x < _panel->width(); x += 2) { |
| @@ -503,6 +530,9 @@ bool Generate::generateInternal(int width, int height, PuzzleSymbols symbols) { | |||
| 503 | std::cout << row << std::endl; | 530 | std::cout << row << std::endl; |
| 504 | } | 531 | } |
| 505 | 532 | ||
| 533 | erase_path(); | ||
| 534 | std::cout << _panel->Write() << std::endl; | ||
| 535 | |||
| 506 | return true; | 536 | return true; |
| 507 | } | 537 | } |
| 508 | 538 | ||
| @@ -944,12 +974,14 @@ bool Generate::place_start(int amount) { | |||
| 944 | } | 974 | } |
| 945 | if (adjacent && Random::rand() % 10 > 0) continue; | 975 | if (adjacent && Random::rand() % 10 > 0) continue; |
| 946 | _starts.insert(pos); | 976 | _starts.insert(pos); |
| 947 | set(pos.first, pos.second, Decoration::Start | Decoration::Color::None); | 977 | _panel->SetGridSymbol(pos.first, pos.second, Decoration::Start, |
| 978 | Decoration::Color::None); | ||
| 948 | amount--; | 979 | amount--; |
| 949 | if (_panel->symmetry) { | 980 | if (_panel->symmetry) { |
| 950 | Point sp = get_sym_point(pos); | 981 | Point sp = get_sym_point(pos); |
| 951 | _starts.insert(sp); | 982 | _starts.insert(sp); |
| 952 | set(sp.first, sp.second, Decoration::Start | Decoration::Color::None); | 983 | _panel->SetGridSymbol(sp.first, sp.second, Decoration::Start, |
| 984 | Decoration::Color::None); | ||
| 953 | } | 985 | } |
| 954 | } | 986 | } |
| 955 | return true; | 987 | return true; |
| @@ -994,12 +1026,14 @@ bool Generate::place_exit(int amount) { | |||
| 994 | } | 1026 | } |
| 995 | if (adjacent) continue; | 1027 | if (adjacent) continue; |
| 996 | _exits.insert(pos); | 1028 | _exits.insert(pos); |
| 997 | set(pos.first, pos.second, Decoration::Exit | Decoration::Color::None); | 1029 | _panel->SetGridSymbol(pos.first, pos.second, Decoration::Exit, |
| 1030 | Decoration::Color::None); | ||
| 998 | amount--; | 1031 | amount--; |
| 999 | if (_panel->symmetry) { | 1032 | if (_panel->symmetry) { |
| 1000 | Point sp = get_sym_point(pos); | 1033 | Point sp = get_sym_point(pos); |
| 1001 | _exits.insert(sp); | 1034 | _exits.insert(sp); |
| 1002 | set(sp.first, sp.second, Decoration::Exit | Decoration::Color::None); | 1035 | _panel->SetGridSymbol(sp.first, sp.second, Decoration::Exit, |
| 1036 | Decoration::Color::None); | ||
| 1003 | } | 1037 | } |
| 1004 | } | 1038 | } |
| 1005 | return true; | 1039 | return true; |
| @@ -1123,8 +1157,7 @@ bool Generate::can_place_dot(Point pos, bool intersectionOnly) { | |||
| 1123 | } | 1157 | } |
| 1124 | 1158 | ||
| 1125 | // Place the given amount of dots at random points on the path | 1159 | // Place the given amount of dots at random points on the path |
| 1126 | bool Generate::place_dots(int amount, Decoration::Color color, | 1160 | bool Generate::place_dots(int amount, int color, bool intersectionOnly) { |
| 1127 | bool intersectionOnly) { | ||
| 1128 | if (_parity != -1) { // For full dot puzzles, don't put dots on the starts | 1161 | if (_parity != -1) { // For full dot puzzles, don't put dots on the starts |
| 1129 | // and exits unless there are multiple | 1162 | // and exits unless there are multiple |
| 1130 | for (int x = 0; x < _panel->width(); x += 2) { | 1163 | for (int x = 0; x < _panel->width(); x += 2) { |
| @@ -1141,19 +1174,17 @@ bool Generate::place_dots(int amount, Decoration::Color color, | |||
| 1141 | setFlagOnce(Config::DisableDotIntersection); | 1174 | setFlagOnce(Config::DisableDotIntersection); |
| 1142 | } | 1175 | } |
| 1143 | 1176 | ||
| 1144 | /*if (color == Decoration::Color::Blue || color == Decoration::Color::Cyan) | 1177 | if (color == Decoration::Color::Blue || color == Decoration::Color::Cyan) |
| 1145 | color = IntersectionFlags::DOT_IS_BLUE; | 1178 | color = IntersectionFlags::DOT_IS_BLUE; |
| 1146 | else if (color == Decoration::Color::Yellow || | 1179 | else if (color == Decoration::Color::Yellow || |
| 1147 | color == Decoration::Color::Orange) | 1180 | color == Decoration::Color::Orange) |
| 1148 | color = IntersectionFlags::DOT_IS_ORANGE; | 1181 | color = IntersectionFlags::DOT_IS_ORANGE; |
| 1149 | else | 1182 | else |
| 1150 | color = 0;*/ | 1183 | color = 0; |
| 1151 | 1184 | ||
| 1152 | std::set<Point> open = | 1185 | std::set<Point> open = (color == 0 ? _path |
| 1153 | (color == 0 ? _path | 1186 | : (color == IntersectionFlags::DOT_IS_BLUE) ? _path1 |
| 1154 | : (color == Decoration::Color::Blue || color == Decoration::Color::Cyan) | 1187 | : _path2); |
| 1155 | ? _path1 | ||
| 1156 | : _path2); | ||
| 1157 | for (Point p : _starts) open.erase(p); | 1188 | for (Point p : _starts) open.erase(p); |
| 1158 | for (Point p : _exits) open.erase(p); | 1189 | for (Point p : _exits) open.erase(p); |
| 1159 | for (Point p : blockPos) open.erase(p); | 1190 | for (Point p : blockPos) open.erase(p); |
