104 lines
3.0 KiB
C++

#ifndef Chessboard_H
#define Chessboard_H
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <memory>
#include "../Player/Player.hpp"
#include "../ChessPieces/ChessPieceColor.hpp"
#include "../ChessPieces/ChessPiecePosition.hpp"
class ChessPiece;
class Chessboard {
private:
std::map<ChessPiecePosition, ChessPiece*> chessboard;
std::vector<std::pair<ChessPiecePosition, ChessPiecePosition>> history;
std::pair<Player*, Player*> players;
Player* currentPlayer;
public:
struct Board_ChessPiece {
int color;
char type;
std::pair<char, int> position;
Board_ChessPiece(const int& c, const char& t, std::pair<char,int> p) : color(c), type(t), position(p) {}
bool operator<(const Board_ChessPiece& other) const {
if (position != other.position) {
return position < other.position;
}
if (color != other.color) {
return color < other.color;
}
return type < other.type;
}
};
inline static const std::set<Board_ChessPiece> defaultBoard = {
{0, 'P', {'A', 7}},
{0, 'P', {'B', 7}},
{0, 'P', {'C', 7}},
{0, 'P', {'D', 7}},
{0, 'P', {'E', 7}},
{0, 'P', {'F', 7}},
{0, 'P', {'G', 7}},
{0, 'P', {'H', 7}},
{0, 'R', {'A', 8}},
{0, 'K', {'B', 8}},
{0, 'B', {'C', 8}},
{0, 'Q', {'D', 8}},
{0, 'K', {'E', 8}},
{0, 'B', {'F', 8}},
{0, 'K', {'G', 8}},
{0, 'R', {'H', 8}},
{1, 'P', {'A', 2}},
{1, 'P', {'B', 2}},
{1, 'P', {'C', 2}},
{1, 'P', {'D', 2}},
{1, 'P', {'E', 2}},
{1, 'P', {'F', 2}},
{1, 'P', {'G', 2}},
{1, 'P', {'H', 2}},
{1, 'R', {'A', 1}},
{1, 'N', {'B', 1}},
{1, 'B', {'C', 1}},
{1, 'Q', {'D', 1}},
{1, 'K', {'E', 1}},
{1, 'B', {'F', 1}},
{1, 'K', {'G', 1}},
{1, 'R', {'H', 1}}
};
~Chessboard();
void InitializeStartBoard();
void InitializeBoard(std::set<Board_ChessPiece> board);
//void SetChessPiece(std::unique_ptr<ChessPiece> piece);
void SetChessPiece(ChessPiece* chesspiece);
bool IsEmptyField(ChessPiecePosition* position);
ChessPiece* GetChessPiece(ChessPiecePosition* position);
std::vector<ChessPiece*> GetChessPieces();
void UpdateChessPieces();
void MoveChessPiece(std::string move);
void SetToHistory(ChessPiecePosition fromPosition, ChessPiecePosition toPosition);
int GetCountMoves();
std::pair<ChessPiecePosition, ChessPiecePosition> GetLastMove();
bool IsCheckmate();
bool IsCheck();
bool IsStalemate();
bool IsPositionUnderAttack(ChessPiecePosition position, ChessPieceColor color);
Player* GetCurrentPlayer();
Player* GetOpponentPlayer();
void SetPlayers(Player* playerA, Player* playerB);
void SwitchCurrentPlayer();
Player* GetPlayer(ChessPieceColor color);
ChessPiece* GetChessPieceKing(ChessPieceColor color);
};
#endif