structure of the core folder
This commit is contained in:
parent
3c5948f053
commit
edb429ce33
11 changed files with 289 additions and 0 deletions
74
.vscode/settings.json
vendored
Normal file
74
.vscode/settings.json
vendored
Normal file
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
24
engine/core/board.hpp
Normal file
24
engine/core/board.hpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef BOARD_HPP
|
||||
#define BOARD_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "cell.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
class Board {
|
||||
private:
|
||||
int width;
|
||||
int height;
|
||||
std::vector<std::vector<Cell>> grid;
|
||||
|
||||
public:
|
||||
Board(int w, int h) : width(w), height(h), grid(h, std::vector<Cell>(w)) {}
|
||||
int getWidth() const { return width; }
|
||||
int getHeight() const { return height; }
|
||||
Cell& getCell(int x, int y) { return grid[y][x]; }
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
16
engine/core/cell.hpp
Normal file
16
engine/core/cell.hpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef CELL_HPP
|
||||
#define CELL_HPP
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace engine {
|
||||
|
||||
struct PieceId;
|
||||
|
||||
struct Cell {
|
||||
std::optional<PieceId> pieceId;
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
15
engine/core/events.hpp
Normal file
15
engine/core/events.hpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
#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
|
||||
35
engine/core/game_state.hpp
Normal file
35
engine/core/game_state.hpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include "piece.hpp"
|
||||
#include "move.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
struct Cell {
|
||||
std::optional<PieceId> 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<Cell> cells_;
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
35
engine/core/move.hpp
Normal file
35
engine/core/move.hpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
#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<int> extra;
|
||||
};
|
||||
|
||||
enum class MoveType { Normal, Capture, Castling, Promotion, Multi, CardEffect };
|
||||
|
||||
struct Move {
|
||||
PieceId actor = 0;
|
||||
std::vector<MoveAction> actions;
|
||||
MoveType type = MoveType::Normal;
|
||||
int playerId = -1;
|
||||
std::string tag;
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
16
engine/core/move_applier.hpp
Normal file
16
engine/core/move_applier.hpp
Normal file
|
|
@ -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
|
||||
18
engine/core/move_generator.hpp
Normal file
18
engine/core/move_generator.hpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#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<Move> generateForPlayer(const GameState& state, int playerId) const;
|
||||
std::vector<Move> generateForPiece(const GameState& state, PieceId pieceId) const;
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
18
engine/core/move_result.hpp
Normal file
18
engine/core/move_result.hpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "move.hpp"
|
||||
#include "events.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
enum class MoveStatus { Ok, Illegal, BlockedByCard, OutOfBounds, RequiresConfirmation };
|
||||
|
||||
struct MoveResult {
|
||||
MoveStatus status = MoveStatus::Ok;
|
||||
std::vector<Event> events;
|
||||
std::string reason;
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
14
engine/core/piece.hpp
Normal file
14
engine/core/piece.hpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef PIECE_HPP
|
||||
#define PIECE_HPP
|
||||
|
||||
namespace engine {
|
||||
|
||||
class Piece {
|
||||
private:
|
||||
|
||||
public:
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
24
engine/plugins/effect_plugin.hpp
Normal file
24
engine/plugins/effect_plugin.hpp
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue