ochess/src/game_tab/HalfMove.hpp
2023-01-19 16:33:44 +01:00

55 lines
1.9 KiB
C++

#pragma once
#include "CMI.hpp"
#include "ChessArbiter.hpp"
#include "ochess.hpp"
#include "pgnp.hpp"
#include <map>
#include <vector>
/**
* @brief This class extends CGEHalfMove (to be displayed in the game editor)
*/
class HalfMove : public CMI::HalfMove {
std::string fen;
/// @brief Used in to retrieve captured pieces (see GetLineCaptures())
char capture;
void BuildAndVerify(HalfMove *m, std::string fen);
/// @brief Store the source and destination square of the current move (mainly used for pieces animation)
std::string src,dst;
/// @brief Opening reach by that move while taking into account all the parents
std::string opening, eco;
chessarbiter::ChessArbiter arbiter;
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(CMI::HalfMove *m);
void AddMove(HalfMove *m);
/// @brief Check if current half move is within a variation
bool IsVariation();
/// @brief Get the root of a variation
bool HasParent(HalfMove*m);
bool HasChild(HalfMove*m);
/// @brief Retrieve the list of moves from the current one to the first one
std::vector<HalfMove *> GetLine();
std::string GetLineAsSAN();
std::map<char, std::uint8_t> GetLineCaptures();
/// @brief The opening name of current line
void SetOpening(const std::string &name, const std::string &eco);
/// @brief Getters for name and eco
void GetOpening(std::string &name, std::string &eco);
std::string GetFen();
void SetFen(std::string fen);
void SetCapture(char c);
void GetAbsoluteMove(std::string &src,std::string &dst);
void SetAbsoluteMove(const std::string &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);
};