ochess/src/game_tab/HalfMove.hpp
2023-01-01 19:05:15 +01:00

71 lines
2 KiB
C++

#pragma once
#include "CGEditor.hpp"
#include "ChessArbiter.hpp"
#include "ochess.hpp"
#include "pgnp.hpp"
#include <map>
#include <vector>
/**
* @brief Create your custom half move class
*
* The implementation of the class should give you
* an overview of how to keep your move sync with the one of CGEditor
*
*/
class HalfMove : public cgeditor::CGEHalfMove {
HalfMove *parent = nullptr;
HalfMove *mainline = nullptr;
chessarbiter::ChessArbiter arbiter;
std::vector<HalfMove *> variations;
std::string fen;
char capture;
void BuildAndVerify(HalfMove *m, std::string fen);
std::string move_absolute;
public:
HalfMove(HalfMove *m);
HalfMove(std::string move_absolute,std::string move_san);
HalfMove(std::string move_absolute,std::string move_san, std::string fen);
HalfMove(pgnp::HalfMove *m);
~HalfMove();
/// @brief Add variation to current move
void AddVariation(HalfMove *m);
/// @brief Remove the specified child from mainline and/or variations
void RemoveChild(HalfMove *m);
void AddMove(HalfMove *m);
/// @brief Set value of the mailine
void SetMainline(HalfMove *m);
/// @brief Set this move as mainline
void SetAsMainline();
/// @brief Promote the current move and submove
void Promote();
/// @brief Check if current half move is within a variation
bool IsVariation();
/// @brief Get the root of a variation
HalfMove *GetRoot();
/// @brief Get parent of the current move
HalfMove *GetParent();
HalfMove *GetMainline();
std::vector<HalfMove *> GetVariations();
std::map<char, std::uint8_t> GetLineCaptures();
/// @brief Set parent of the current move
void SetParent(HalfMove *m);
std::string GetFen();
void SetFen(std::string fen);
void SetCapture(char c);
bool IsABlackMove();
std::string GetAbsoluteMove(){return move_absolute;};
/**
* @brief Build current move
* Verify and play all the moves in the game
* while building the fen for each move
*/
void BuildAndVerify(std::string initial_fen);
};