From edb429ce33baa11bdd39403aa2ece3e3daadaef7 Mon Sep 17 00:00:00 2001 From: Didictateur Date: Mon, 13 Oct 2025 12:59:35 +0200 Subject: [PATCH] structure of the core folder --- .vscode/settings.json | 74 ++++++++++++++++++++++++++++++++ engine/core/board.hpp | 24 +++++++++++ engine/core/cell.hpp | 16 +++++++ engine/core/events.hpp | 15 +++++++ engine/core/game_state.hpp | 35 +++++++++++++++ engine/core/move.hpp | 35 +++++++++++++++ engine/core/move_applier.hpp | 16 +++++++ engine/core/move_generator.hpp | 18 ++++++++ engine/core/move_result.hpp | 18 ++++++++ engine/core/piece.hpp | 14 ++++++ engine/plugins/effect_plugin.hpp | 24 +++++++++++ 11 files changed, 289 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 engine/core/board.hpp create mode 100644 engine/core/cell.hpp create mode 100644 engine/core/events.hpp create mode 100644 engine/core/game_state.hpp create mode 100644 engine/core/move.hpp create mode 100644 engine/core/move_applier.hpp create mode 100644 engine/core/move_generator.hpp create mode 100644 engine/core/move_result.hpp create mode 100644 engine/core/piece.hpp create mode 100644 engine/plugins/effect_plugin.hpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a85d9aa --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,74 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "format": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "queue": "cpp", + "ranges": "cpp", + "semaphore": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stdfloat": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "text_encoding": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/engine/core/board.hpp b/engine/core/board.hpp new file mode 100644 index 0000000..41caedb --- /dev/null +++ b/engine/core/board.hpp @@ -0,0 +1,24 @@ +#ifndef BOARD_HPP +#define BOARD_HPP + +#include +#include "cell.hpp" + +namespace engine { + +class Board { +private: + int width; + int height; + std::vector> grid; + +public: + Board(int w, int h) : width(w), height(h), grid(h, std::vector(w)) {} + int getWidth() const { return width; } + int getHeight() const { return height; } + Cell& getCell(int x, int y) { return grid[y][x]; } +}; + +} // namespace engine + +#endif \ No newline at end of file diff --git a/engine/core/cell.hpp b/engine/core/cell.hpp new file mode 100644 index 0000000..23b8d1b --- /dev/null +++ b/engine/core/cell.hpp @@ -0,0 +1,16 @@ +#ifndef CELL_HPP +#define CELL_HPP + +#include + +namespace engine { + +struct PieceId; + +struct Cell { + std::optional pieceId; +}; + +} // namespace engine + +#endif \ No newline at end of file diff --git a/engine/core/events.hpp b/engine/core/events.hpp new file mode 100644 index 0000000..f3782f6 --- /dev/null +++ b/engine/core/events.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include +#include +#include +#include "move.hpp" + +namespace engine { + +struct Event { + std::string type; // e.g., "capture", "move", "promotion", "mine_triggered" + std::string detail; // JSON or human-readable details +}; + +} // namespace engine diff --git a/engine/core/game_state.hpp b/engine/core/game_state.hpp new file mode 100644 index 0000000..12922ea --- /dev/null +++ b/engine/core/game_state.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include +#include +#include "piece.hpp" +#include "move.hpp" + +namespace engine { + +struct Cell { + std::optional pieceId; + // additional flags: trap, fog, etc. +}; + +class GameState { +public: + GameState(); + + int width() const; + int height() const; + bool isValid(const Coord& c) const; + + const Cell& cellAt(const Coord& c) const; + Cell& cellAt(const Coord& c); + + // snapshot / clone + GameState clone() const; + +private: + int w_ = 8; + int h_ = 8; + std::vector cells_; +}; + +} // namespace engine diff --git a/engine/core/move.hpp b/engine/core/move.hpp new file mode 100644 index 0000000..191c0c9 --- /dev/null +++ b/engine/core/move.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include +#include +#include + +#include "piece.hpp" + +namespace engine { + +struct Coord { int x; int y; }; + +using PieceId = int; + +enum class MoveActionKind { Move, Capture, Create, Remove, SetFlag }; + +struct MoveAction { + MoveActionKind kind; + PieceId piece; // 0 for create + Coord from; + Coord to; + std::optional extra; +}; + +enum class MoveType { Normal, Capture, Castling, Promotion, Multi, CardEffect }; + +struct Move { + PieceId actor = 0; + std::vector actions; + MoveType type = MoveType::Normal; + int playerId = -1; + std::string tag; +}; + +} // namespace engine diff --git a/engine/core/move_applier.hpp b/engine/core/move_applier.hpp new file mode 100644 index 0000000..740dd9d --- /dev/null +++ b/engine/core/move_applier.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "game_state.hpp" +#include "move_result.hpp" + +namespace engine { + +class MoveApplier { +public: + MoveApplier(); + + MoveResult applyMove(GameState& state, const Move& move); + MoveResult simulateApply(const GameState& state, const Move& move, GameState& outState) const; +}; + +} // namespace engine diff --git a/engine/core/move_generator.hpp b/engine/core/move_generator.hpp new file mode 100644 index 0000000..7806062 --- /dev/null +++ b/engine/core/move_generator.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include "move.hpp" +#include "game_state.hpp" + +namespace engine { + +class MoveGenerator { +public: + MoveGenerator(); + + // generate moves for a specific piece; pieceId == 0 -> all pieces for player + std::vector generateForPlayer(const GameState& state, int playerId) const; + std::vector generateForPiece(const GameState& state, PieceId pieceId) const; +}; + +} // namespace engine diff --git a/engine/core/move_result.hpp b/engine/core/move_result.hpp new file mode 100644 index 0000000..e2959c7 --- /dev/null +++ b/engine/core/move_result.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include "move.hpp" +#include "events.hpp" + +namespace engine { + +enum class MoveStatus { Ok, Illegal, BlockedByCard, OutOfBounds, RequiresConfirmation }; + +struct MoveResult { + MoveStatus status = MoveStatus::Ok; + std::vector events; + std::string reason; +}; + +} // namespace engine diff --git a/engine/core/piece.hpp b/engine/core/piece.hpp new file mode 100644 index 0000000..b2cf9e4 --- /dev/null +++ b/engine/core/piece.hpp @@ -0,0 +1,14 @@ +#ifndef PIECE_HPP +#define PIECE_HPP + +namespace engine { + +class Piece { +private: + +public: +}; + +} // namespace engine + +#endif \ No newline at end of file diff --git a/engine/plugins/effect_plugin.hpp b/engine/plugins/effect_plugin.hpp new file mode 100644 index 0000000..df4d7b1 --- /dev/null +++ b/engine/plugins/effect_plugin.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "../core/game_state.hpp" +#include "../core/move.hpp" +#include "../core/move_result.hpp" +#include "../core/move_generator.hpp" + +namespace engine::plugins { + +class EffectPlugin { +public: + virtual ~EffectPlugin() = default; + + // modify the move generation step (can register extra moves) + virtual void modifyMoveGeneration(const engine::GameState& state, engine::MoveGenerator& generator) {} + + // hook before applying a move (can mutate the move or block it) + virtual void onBeforeApply(engine::GameState& state, engine::Move& move, engine::MoveResult& out) {} + + // hook after move applied + virtual void onAfterApply(engine::GameState& state, const engine::Move& move, engine::MoveResult& out) {} +}; + +} // namespace engine::plugins