2023-11-25 08:16:48 +00:00
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include <array>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class Chessboard {
|
|
|
|
public:
|
|
|
|
Chessboard();
|
2023-11-27 08:41:04 +00:00
|
|
|
std::string process(const std::string& t);
|
2023-11-25 08:16:48 +00:00
|
|
|
std::string stringifyBoard();
|
2023-11-29 13:29:16 +00:00
|
|
|
std::string getRules() const;
|
2023-11-25 08:16:48 +00:00
|
|
|
using Move = std::pair<int, int>;
|
2023-11-29 13:29:16 +00:00
|
|
|
private:
|
2023-11-27 08:41:04 +00:00
|
|
|
bool move(const Move& move);
|
2023-11-29 13:29:16 +00:00
|
|
|
void updateMoves(const Move& move);
|
2023-11-25 08:16:48 +00:00
|
|
|
|
|
|
|
struct Piece {
|
|
|
|
enum Types {
|
|
|
|
Pawn,
|
|
|
|
Knight,
|
|
|
|
Bishop,
|
|
|
|
Rook,
|
|
|
|
Queen,
|
|
|
|
King,
|
|
|
|
Taken,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Colors {
|
2023-11-29 13:29:16 +00:00
|
|
|
White,
|
2023-11-25 08:16:48 +00:00
|
|
|
Black,
|
|
|
|
};
|
|
|
|
|
|
|
|
Types type;
|
|
|
|
Colors color;
|
|
|
|
int pos;
|
|
|
|
};
|
|
|
|
|
2023-11-27 08:41:04 +00:00
|
|
|
Piece::Types tokenToType(std::string_view token);
|
|
|
|
size_t tokenToPos(std::string_view token);
|
2023-11-25 08:16:48 +00:00
|
|
|
using PieceSet = std::array<Piece, 16>;
|
|
|
|
|
|
|
|
PieceSet blackPieces;
|
|
|
|
PieceSet whitePieces;
|
2023-11-27 08:41:04 +00:00
|
|
|
int m_moveCounter = 0;
|
2023-11-25 08:16:48 +00:00
|
|
|
|
|
|
|
using Board = std::array<Piece*, 64>;
|
|
|
|
Board board;
|
|
|
|
|
2023-11-29 13:29:16 +00:00
|
|
|
std::vector<Move> whiteMoves;
|
|
|
|
std::vector<Move> blackMoves;
|
|
|
|
|
2023-11-27 08:41:04 +00:00
|
|
|
bool validateMove(const Piece& piece, int pos);
|
|
|
|
// just basic validation
|
|
|
|
// fixme: missing en passant, castling, promotion, etc.
|
|
|
|
bool validatePawnMove(Piece::Colors color, int from_rank, int from_file, int to_rank, int to_file);
|
|
|
|
bool validateKnightMove(Piece::Colors color, int from_rank, int from_file, int to_rank, int to_file);
|
|
|
|
bool validateBishopMove(Piece::Colors color, int from_rank, int from_file, int to_rank, int to_file);
|
|
|
|
bool validateRookMove(Piece::Colors color, int from_rank, int from_file, int to_rank, int to_file);
|
|
|
|
bool validateQueenMove(Piece::Colors color, int from_rank, int from_file, int to_rank, int to_file);
|
|
|
|
bool validateKingMove(Piece::Colors color, int from_rank, int from_file, int to_rank, int to_file);
|
2023-11-25 08:16:48 +00:00
|
|
|
};
|