ochess/src/game_tab/Game.hpp

60 lines
1.7 KiB
C++
Raw Normal View History

2022-02-23 18:11:55 +01:00
#pragma once
#include "ChessArbiter.hpp"
#include "HalfMove.hpp"
#include "ochess.hpp"
#include <unordered_map>
2023-01-13 10:42:57 +01:00
/**
* @brief Hold an entire chess game
* Used in many places in the projects.
*/
2022-02-23 18:11:55 +01:00
class Game {
2023-01-13 10:42:57 +01:00
/// @brief 64 char string that contains all the pieces on the board (used in BoardCanvas)
2022-02-23 18:11:55 +01:00
std::string board;
std::string initial_fen;
std::string result;
2022-02-23 18:11:55 +01:00
std::unordered_map<std::string, std::string> tags;
HalfMove *moves;
HalfMove *current;
2023-01-13 10:42:57 +01:00
/// @brief Used by various methods of the class
2022-02-23 18:11:55 +01:00
chessarbiter::ChessArbiter arbiter;
public:
2022-12-30 18:43:21 +01:00
Game(const Game* g);
2022-02-23 18:11:55 +01:00
Game();
Game(std::string fen);
2022-02-23 18:47:18 +01:00
Game(HalfMove *m, std::string initial_fen);
~Game();
2022-02-23 18:11:55 +01:00
std::string GetBoard();
std::string GetTag(std::string tagname);
void SetTag(std::string tagname, std::string value);
void DeleteTag(std::string tagname);
HalfMove *GetCurrentMove();
2023-01-01 20:21:23 +01:00
HalfMove *GetNextMove();
2022-02-23 18:11:55 +01:00
HalfMove *GetMoves();
std::string GetFen();
2022-03-01 15:58:02 +01:00
std::string GetResult();
2023-01-16 14:55:48 +01:00
void GetOpening(std::string &name,std::string &eco);
2023-01-13 10:42:57 +01:00
/// @brief Play the given absolute move
2023-01-10 16:01:26 +01:00
bool Play(std::string move,char promotion='q');
2022-02-23 18:11:55 +01:00
bool IsBlackToPlay();
2023-01-02 11:36:13 +01:00
bool IsCheckmate(bool forBlack);
2023-01-13 10:42:57 +01:00
/// @brief Check if a given absolute move consists in a pawn promotion
bool IsPromotionMove(std::string absolute_move);
2022-02-23 18:11:55 +01:00
void Previous();
void Next();
2023-01-13 10:42:57 +01:00
/// @brief Delete a move (its mainline and variations recursively)
2022-02-23 18:11:55 +01:00
void DeleteMove(HalfMove *m);
void PromoteMove(HalfMove *m);
void SetMoveAsMainline(HalfMove *m);
void SetCurrent(HalfMove *m);
std::vector<std::string> ListTags();
void SetResult(std::string result);
2022-02-25 13:38:49 +01:00
/**
* @brief Build current game
* Verify and play all the moves in the game
* while building the fen for each move
*/
2022-02-25 11:42:46 +01:00
void BuildAndVerify();
2022-02-23 18:11:55 +01:00
};