aboutsummaryrefslogtreecommitdiff
path: root/src/game_tab/HalfMove.hpp
blob: 0666f387438582668a260c88628a01d8751dfe95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include "CGEditor.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 cgeditor::CGEHalfMove {
  HalfMove *parent = nullptr;
  HalfMove *mainline = nullptr;
  chessarbiter::ChessArbiter arbiter;
  std::vector<HalfMove *> variations;
  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;

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
  bool HasParent(HalfMove*m);
  bool HasChild(HalfMove*m);
  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();
  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);
};