Files
cpl_cpp-project/Piece.hpp
2022-12-23 23:57:29 +01:00

70 lines
1.6 KiB
C++

#ifndef CHESS_ENGINE_PIECE_HPP
#define CHESS_ENGINE_PIECE_HPP
#include <optional>
#include <iosfwd>
enum class PieceColor {
White = 0x0,
Black = 0x1,
};
enum class PieceType {
Pawn = 2,
Knight,
Bishop,
Rook,
Queen,
King
};
std::ostream &operator<<(std::ostream &os, const PieceType &pt);
class Piece {
public:
constexpr static const PieceType PromotionTypes[4] = {PieceType::Knight, PieceType::Bishop, PieceType::Rook,
PieceType::Queen};
constexpr static const unsigned PieceValue[6] = {100, 350, 350, 525, 1000, 10000};
constexpr static const unsigned PromotionScore[6] = {0, 26, 36, 46, 56, 0};
constexpr static const unsigned MVV_LVA[6][6] = {
{15, 14, 13, 12, 11, 10}, // Pawn
{25, 24, 23, 22, 21, 20}, // Knight
{35, 34, 33, 32, 31, 30}, // Bishop
{45, 44, 43, 42, 41, 40}, // Rook
{55, 54, 53, 52, 51, 50}, // Queen
{65, 64, 63, 62, 61, 60}, // King
};
using Optional = std::optional<Piece>;
Piece(PieceColor color, PieceType type);
static Optional fromSymbol(char symbol);
static char toSymbol(PieceType type);
static std::optional<PieceType> pieceTypeFromSymbol(char symbol);
PieceColor color() const;
PieceType type() const;
char toSymbol() const;
private:
const PieceColor mColor;
const PieceType mType;
};
bool operator==(const Piece &lhs, const Piece &rhs);
std::ostream &operator<<(std::ostream &os, const Piece &piece);
// Invert a color (White becomes Black and vice versa)
PieceColor operator!(PieceColor color);
#endif