Compare commits
2 Commits
f8ac60f6a6
...
d2b0b1f184
| Author | SHA1 | Date | |
|---|---|---|---|
|
d2b0b1f184
|
|||
|
11ae406073
|
@ -270,6 +270,8 @@ public:
|
||||
|
||||
auto RemoveBlock(int x, int y) -> bool;
|
||||
|
||||
auto ToggleTarget(int x, int y) -> bool;
|
||||
|
||||
auto MoveBlockAt(int x, int y, Direction dir) -> bool;
|
||||
|
||||
auto GetNextStates() const -> std::vector<State>;
|
||||
|
||||
@ -136,6 +136,16 @@ inline auto state_complex_4f() -> State {
|
||||
|
||||
inline auto state_complex_4f_wc(const State &state) -> bool { return false; }
|
||||
|
||||
inline auto state_complex_5r() -> State {
|
||||
return State("R6x6:31....12....1221......12..ba..1212..21..12....12......21.."
|
||||
"....21..21....");
|
||||
}
|
||||
|
||||
inline auto state_complex_5r_wc(const State &state) -> bool {
|
||||
// R6x6:................................ba......................................
|
||||
return state.GetBlockAt(4, 2) == "ba";
|
||||
}
|
||||
|
||||
inline auto state_klotski() -> State {
|
||||
State s = State(4, 5, false);
|
||||
s.AddBlock(Block(0, 0, 1, 2, false));
|
||||
@ -157,12 +167,13 @@ inline auto state_klotski_wc(const State &state) -> bool {
|
||||
}
|
||||
|
||||
std::vector<StateGenerator> generators{
|
||||
state_simple_1r, state_simple_2r, state_simple_3r, state_complex_1r,
|
||||
state_complex_2r, state_complex_3r, state_complex_4f, state_klotski};
|
||||
state_simple_1r, state_simple_2r, state_simple_3r,
|
||||
state_complex_1r, state_complex_2r, state_complex_3r,
|
||||
state_complex_4f, state_complex_5r, state_klotski};
|
||||
|
||||
std::vector<WinCondition> win_conditions{
|
||||
state_simple_1r_wc, state_simple_2r_wc, state_simple_3r_wc,
|
||||
state_complex_1r_wc, state_complex_2r_wc, state_complex_3r_wc,
|
||||
state_complex_4f_wc, state_klotski_wc};
|
||||
state_complex_4f_wc, state_complex_5r_wc, state_klotski_wc};
|
||||
|
||||
#endif
|
||||
|
||||
@ -136,6 +136,20 @@ auto State::RemoveBlock(int x, int y) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto State::ToggleTarget(int x, int y) -> bool {
|
||||
Block block = GetBlock(x, y);
|
||||
if (!block.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
block.target = !block.target;
|
||||
|
||||
int index = GetIndex(block.x, block.y);
|
||||
state.replace(index, 2, block.ToString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto State::MoveBlockAt(int x, int y, Direction dir) -> bool {
|
||||
Block block = GetBlock(x, y);
|
||||
if (!block.IsValid()) {
|
||||
|
||||
26
src/main.cpp
26
src/main.cpp
@ -14,6 +14,17 @@
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
// TODO: Klotski state file loading
|
||||
// - File should contain a single state per line, multiple lines possible
|
||||
// - If a file is loaded, the presets should be replaced with the states
|
||||
// from the file
|
||||
// - Automatically determine the winning condition based on a configured
|
||||
// board exit
|
||||
// TODO: Graph interaction
|
||||
// - Click states to display them in the board
|
||||
// - Find shortest path to any winning state and mark it in the graph
|
||||
// - Also mark the next move along the path on the board
|
||||
|
||||
auto apply_state(MassSpringSystem &mass_springs, StateGenerator generator)
|
||||
-> State {
|
||||
mass_springs.springs.clear();
|
||||
@ -203,7 +214,15 @@ auto main(int argc, char *argv[]) -> int {
|
||||
sel_x++;
|
||||
}
|
||||
} else if (IsKeyPressed(KEY_P)) {
|
||||
std::cout << current_state.state << std::endl;
|
||||
std::cout << "State: " << current_state.state << std::endl;
|
||||
Block sel = current_state.GetBlock(sel_x, sel_y);
|
||||
int idx = current_state.GetIndex(sel.x, sel.y) - 5;
|
||||
if (sel.IsValid()) {
|
||||
std::cout << "Sel: " << current_state.state.substr(0, 5)
|
||||
<< std::string(idx, '.') << sel.ToString()
|
||||
<< std::string(current_state.state.length() - idx - 7, '.')
|
||||
<< std::endl;
|
||||
}
|
||||
} else if (IsKeyPressed(KEY_N)) {
|
||||
current_preset =
|
||||
(generators.size() + current_preset - 1) % generators.size();
|
||||
@ -228,8 +247,11 @@ auto main(int argc, char *argv[]) -> int {
|
||||
renderer.mark_solutions = !renderer.mark_solutions;
|
||||
} else if (IsKeyPressed(KEY_O)) {
|
||||
renderer.connect_solutions = !renderer.connect_solutions;
|
||||
} else if (IsKeyPressed(KEY_T)) {
|
||||
} else if (IsKeyPressed(KEY_F)) {
|
||||
current_state.restricted = !current_state.restricted;
|
||||
} else if (IsKeyPressed(KEY_T)) {
|
||||
current_state.ToggleTarget(sel_x, sel_y);
|
||||
previous_state = clear_masssprings(masssprings, current_state);
|
||||
} else if (IsKeyPressed(KEY_LEFT) && current_state.width > 1) {
|
||||
current_state = current_state.RemoveColumn();
|
||||
previous_state = clear_masssprings(masssprings, current_state);
|
||||
|
||||
@ -299,7 +299,7 @@ auto Renderer::DrawMenu(const MassSpringSystem &masssprings, int current_preset,
|
||||
draw_btn(1, 2, std::format("Print Board State to Console (P)"), DARKBLUE);
|
||||
|
||||
draw_btn(2, 0,
|
||||
std::format("Preset (M/N): {}, {} (T)", current_preset,
|
||||
std::format("Preset (M/N): {}, {} (F)", current_preset,
|
||||
current_state.restricted ? "Restricted" : "Free"),
|
||||
DARKPURPLE);
|
||||
draw_btn(2, 1, std::format("Populate Graph (G), Clear Graph (C)"),
|
||||
|
||||
Reference in New Issue
Block a user