chessarbiter/src/ChessArbiter.hpp

76 lines
3 KiB
C++
Raw Normal View History

2022-02-16 11:18:22 +01:00
#pragma once
2022-01-29 11:52:47 +01:00
#include "Board.hpp"
#include "Fen.hpp"
#include <iostream>
#include <unordered_map>
2022-01-29 11:52:47 +01:00
#define INIT_BACKUP() \
FEN fen_backup = fen; \
char positions_backup = 0; \
if (positions.find(fen.board) != positions.end()) \
positions_backup = positions[fen.board]; \
std::string SAN_backup = SAN; \
char capture_backup = capture; \
bool was_enpassant_backup = was_enpassant;
#define RESTORE_BACKUP() \
SetFEN(fen_backup); \
if (positions_backup != 0) \
positions[fen.board] = positions_backup; \
SAN = SAN_backup; \
capture = capture_backup; \
was_enpassant = was_enpassant_backup;
2022-01-29 11:52:47 +01:00
namespace chessarbiter {
class ChessArbiter {
Board board;
FEN fen;
int wPawn, wRook, wKnight, wBishop, wQueen, wKing;
/// @brief Use to compute occurences of positions
std::unordered_map<std::string, char> positions;
/// @brief FEN methods used internally
2022-12-27 11:28:13 +01:00
void SetFEN(const std::string &newfen);
void SetFEN(const FEN &fen);
std::string SAN, SAN_last;
2022-02-16 22:24:35 +01:00
char capture;
bool was_enpassant;
2022-01-29 11:52:47 +01:00
public:
ChessArbiter();
2022-12-27 09:42:26 +01:00
void Setup(const std::string &fen);
2022-01-29 11:52:47 +01:00
std::string GetFEN();
/// @brief Check which player is going to play
bool IsBlackTurn();
/// @brief Check if a side is in check
bool IsCheck(bool);
/// @brief Play a move (return false if it's illegal)
2022-12-27 09:42:26 +01:00
bool Play(const std::string &move, char promote='Q');
2022-01-29 11:52:47 +01:00
/// @brief Check if a square is attacked by a particular player
2022-12-27 09:42:26 +01:00
bool IsAttacked(const std::string &square, bool);
2022-01-29 11:52:47 +01:00
/// @brief Get the serialized board
std::string GetBoard();
/// @brief Get current position evaluation according to player's material
int GetMaterialScore();
/// @brief Check if position is legal to be played
2022-01-29 11:52:47 +01:00
bool IsPlayable();
/// @brief Get pieces captures by a player
2022-12-27 09:42:26 +01:00
std::string GetCaptures(bool);
char GetCapture();
2022-02-16 15:18:26 +01:00
/// @brief Get the english SAN format of the last move
std::string GetSAN();
2022-01-29 11:52:47 +01:00
/// @brief List all the legal moves of a player
2022-12-27 09:42:26 +01:00
std::vector<std::string> ListLegalMoves(bool);
2022-01-29 11:52:47 +01:00
/// @brief Check if a specific castle is possible by a player
2022-12-27 09:42:26 +01:00
bool IsCastlePossible(bool, bool);
2022-01-29 11:52:47 +01:00
bool IsCheckMate();
/// @brief Draws check
bool IsDrawByFiftyMoveRule();
bool IsDrawByNoMoves();
bool IsDrawByRepetitions();
bool IsDraw();
bool WasEnPassant();
2022-12-27 09:42:26 +01:00
std::string ParseSAN(const std::string &SANMove);
char ParseSANPromotion(const std::string &SANMove);
2022-01-29 11:52:47 +01:00
};
2022-02-16 11:18:22 +01:00
} // namespace chessarbiter