add winning conditions and ability to mark them in the graph
This commit is contained in:
@ -15,26 +15,30 @@ constexpr int MENU_COLS = 3;
|
||||
|
||||
// Camera Controls
|
||||
constexpr float SIM_SPEED = 4.0;
|
||||
constexpr float CAMERA_FOV = 120.0;
|
||||
constexpr float CAMERA_DISTANCE = 100.0;
|
||||
constexpr float MIN_CAMERA_DISTANCE = 2.0;
|
||||
constexpr float MAX_CAMERA_DISTANCE = 2000.0;
|
||||
constexpr float ZOOM_SPEED = 2.5;
|
||||
constexpr float ZOOM_MULTIPLIER = 4.0;
|
||||
constexpr float PAN_SPEED = 2.0;
|
||||
constexpr float PAN_MULTIPLIER = 10.0;
|
||||
constexpr float ROT_SPEED = 1.0;
|
||||
|
||||
// Physics Engine
|
||||
constexpr float MASS = 1.0;
|
||||
constexpr float SPRING_CONSTANT = 1.5;
|
||||
constexpr float DAMPENING_CONSTANT = 0.8;
|
||||
constexpr float REST_LENGTH = 1.0;
|
||||
constexpr float REPULSION_FORCE = 0.1;
|
||||
constexpr float REPULSION_RANGE = 5.0 * REST_LENGTH;
|
||||
constexpr float VERLET_DAMPENING = 0.01; // [0, 1]
|
||||
constexpr float REST_LENGTH = 1.1;
|
||||
constexpr float REPULSION_FORCE = 0.5;
|
||||
constexpr float REPULSION_RANGE = 3.0 * REST_LENGTH;
|
||||
constexpr float VERLET_DAMPENING = 0.02; // [0, 1]
|
||||
|
||||
// Graph Drawing
|
||||
constexpr float VERTEX_SIZE = 0.1;
|
||||
constexpr Color VERTEX_COLOR = GREEN;
|
||||
constexpr Color EDGE_COLOR = DARKGREEN;
|
||||
constexpr int DRAW_VERTICES_LIMIT = 10000;
|
||||
|
||||
// Klotski Drawing
|
||||
constexpr int BOARD_PADDING = 5;
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <format>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
@ -197,9 +198,9 @@ public:
|
||||
std::cerr << "State width/height must be in [1, 9]!" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
if (state.length() != width * height * 2 + 4) {
|
||||
if (state.length() != width * height * 2 + 5) {
|
||||
std::cerr
|
||||
<< "State representation must have length [width * height * 2 + 4]!"
|
||||
<< "State representation must have length [width * height * 2 + 5]!"
|
||||
<< std::endl;
|
||||
exit(1);
|
||||
}
|
||||
@ -249,6 +250,10 @@ public:
|
||||
|
||||
auto GetBlock(int x, int y) const -> Block;
|
||||
|
||||
auto GetBlockAt(int x, int y) const -> std::string;
|
||||
|
||||
auto GetIndex(int x, int y) const -> int;
|
||||
|
||||
auto RemoveBlock(int x, int y) -> bool;
|
||||
|
||||
auto MoveBlockAt(int x, int y, Direction dir) -> bool;
|
||||
@ -264,4 +269,6 @@ template <> struct std::hash<State> {
|
||||
std::size_t operator()(const State &s) const noexcept { return s.Hash(); }
|
||||
};
|
||||
|
||||
using WinCondition = std::function<bool(const State &)>;
|
||||
|
||||
#endif
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <immintrin.h>
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "klotski.hpp"
|
||||
@ -26,12 +27,12 @@ private:
|
||||
public:
|
||||
OrbitCamera3D(Vector3 target, float distance)
|
||||
: camera({0}), target(target), distance(distance), angle_x(0.0),
|
||||
angle_y(0.3), last_mouse(Vector2Zero()), dragging(false),
|
||||
angle_y(0.0), last_mouse(Vector2Zero()), dragging(false),
|
||||
panning(false), target_lock(true) {
|
||||
camera.position = Vector3(0, 0, -1.0 * distance);
|
||||
camera.target = target;
|
||||
camera.up = Vector3(0, 1.0, 0);
|
||||
camera.fovy = 90.0;
|
||||
camera.fovy = CAMERA_FOV;
|
||||
camera.projection = CAMERA_PERSPECTIVE;
|
||||
}
|
||||
|
||||
@ -47,9 +48,16 @@ private:
|
||||
RenderTexture render_target;
|
||||
RenderTexture klotski_target;
|
||||
RenderTexture menu_target;
|
||||
std::unordered_set<State> winning_states;
|
||||
|
||||
public:
|
||||
Renderer() : camera(OrbitCamera3D(Vector3(0, 0, 0), CAMERA_DISTANCE)) {
|
||||
bool mark_solutions;
|
||||
bool connect_solutions;
|
||||
|
||||
public:
|
||||
Renderer()
|
||||
: camera(OrbitCamera3D(Vector3(0, 0, 0), CAMERA_DISTANCE)),
|
||||
mark_solutions(false), connect_solutions(false) {
|
||||
render_target = LoadRenderTexture(WIDTH, HEIGHT);
|
||||
klotski_target = LoadRenderTexture(WIDTH, HEIGHT);
|
||||
menu_target = LoadRenderTexture(WIDTH * 2, MENU_HEIGHT);
|
||||
@ -67,6 +75,12 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
auto UpdateWinningStates(const MassSpringSystem &masssprings,
|
||||
const WinCondition win_condition) -> void;
|
||||
|
||||
auto AddWinningState(const State &state, const WinCondition win_condition)
|
||||
-> void;
|
||||
|
||||
auto UpdateCamera(const MassSpringSystem &masssprings, const State ¤t)
|
||||
-> void;
|
||||
|
||||
@ -76,7 +90,8 @@ public:
|
||||
auto DrawKlotski(const State &state, int hov_x, int hov_y, int sel_x,
|
||||
int sel_y) -> void;
|
||||
|
||||
auto DrawMenu(const MassSpringSystem &masssprings) -> void;
|
||||
auto DrawMenu(const MassSpringSystem &masssprings, int current_preset)
|
||||
-> void;
|
||||
|
||||
auto DrawTextures() -> void;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user