57 lines
1.6 KiB
C
Raw Normal View History

2023-11-25 10:16:48 +02:00
#pragma once
#include <string>
#include <array>
#include <vector>
class Chessboard {
public:
Chessboard();
2023-11-27 10:41:04 +02:00
std::string process(const std::string& t);
2023-11-25 10:16:48 +02:00
std::string stringifyBoard();
private:
using Move = std::pair<int, int>;
2023-11-27 10:41:04 +02:00
bool move(const Move& move);
2023-11-25 10:16:48 +02:00
struct Piece {
enum Types {
Pawn,
Knight,
Bishop,
Rook,
Queen,
King,
Taken,
};
enum Colors {
Black,
White
};
Types type;
Colors color;
int pos;
};
2023-11-27 10:41:04 +02:00
Piece::Types tokenToType(std::string_view token);
size_t tokenToPos(std::string_view token);
2023-11-25 10:16:48 +02:00
using PieceSet = std::array<Piece, 16>;
PieceSet blackPieces;
PieceSet whitePieces;
2023-11-27 10:41:04 +02:00
int m_moveCounter = 0;
2023-11-25 10:16:48 +02:00
using Board = std::array<Piece*, 64>;
Board board;
2023-11-27 10:41:04 +02: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 10:16:48 +02:00
};