|
@@ -10,6 +10,8 @@
|
|
|
|
|
|
namespace chessy
|
|
namespace chessy
|
|
{
|
|
{
|
|
|
|
+ enum PieceType : char;
|
|
|
|
+
|
|
struct Index;
|
|
struct Index;
|
|
|
|
|
|
struct Move;
|
|
struct Move;
|
|
@@ -21,11 +23,25 @@ namespace chessy
|
|
const Side WHITE_SIDE = 0;
|
|
const Side WHITE_SIDE = 0;
|
|
const Side BLACK_SIDE = 1;
|
|
const Side BLACK_SIDE = 1;
|
|
|
|
|
|
- inline constexpr Side otherSide(Side side) {
|
|
|
|
|
|
+ inline constexpr Side otherSide(Side side)
|
|
|
|
+ {
|
|
return !side;
|
|
return !side;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+enum chessy::PieceType : char
|
|
|
|
+{
|
|
|
|
+ EMPTY = -1,
|
|
|
|
+ PAWN = 0,
|
|
|
|
+ KNIGHT = 1,
|
|
|
|
+ BISHOP = 2,
|
|
|
|
+ ROOK = 3,
|
|
|
|
+ QUEEN = 4,
|
|
|
|
+ KING = 5,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+
|
|
/*!
|
|
/*!
|
|
* data structure to index one field on a chess board
|
|
* data structure to index one field on a chess board
|
|
*/
|
|
*/
|
|
@@ -53,11 +69,21 @@ struct chessy::Index
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
+/*!
|
|
|
|
+ * data structure that holds a simple move
|
|
|
|
+ */
|
|
struct chessy::Move
|
|
struct chessy::Move
|
|
{
|
|
{
|
|
Index origin;
|
|
Index origin;
|
|
Index destination;
|
|
Index destination;
|
|
|
|
|
|
|
|
+ //! If the move is a promotion move, this field stores
|
|
|
|
+ //! the type of the resulting piece.
|
|
|
|
+ //! If this field is equal to <code>PieceType::PAWN</code>,
|
|
|
|
+ //! it is indicated, that no promotion happened.
|
|
|
|
+ PieceType promotion;
|
|
|
|
+
|
|
|
|
+
|
|
Move (void) = default;
|
|
Move (void) = default;
|
|
Move (const Move&) = default;
|
|
Move (const Move&) = default;
|
|
Move (Move&&) = default;
|
|
Move (Move&&) = default;
|
|
@@ -65,20 +91,37 @@ struct chessy::Move
|
|
Move& operator= (const Move&) = default;
|
|
Move& operator= (const Move&) = default;
|
|
Move& operator= (Move&&) = default;
|
|
Move& operator= (Move&&) = default;
|
|
|
|
|
|
- inline Move(const std::string& move)
|
|
|
|
|
|
+ inline Move(const std::string& move) :
|
|
|
|
+ promotion{ PieceType::PAWN }
|
|
{
|
|
{
|
|
if (move.length() < 4)
|
|
if (move.length() < 4)
|
|
return;
|
|
return;
|
|
origin = Index { move.substr(0, 2) };
|
|
origin = Index { move.substr(0, 2) };
|
|
destination = Index { move.substr(2, 2) };
|
|
destination = Index { move.substr(2, 2) };
|
|
|
|
+ if (move.length() > 4) {
|
|
|
|
+ switch (move[4]) {
|
|
|
|
+ case 'n': promotion = PieceType::KNIGHT; break;
|
|
|
|
+ case 'b': promotion = PieceType::BISHOP; break;
|
|
|
|
+ case 'r': promotion = PieceType::ROOK; break;
|
|
|
|
+ case 'q': promotion = PieceType::QUEEN; break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
inline Move(Index origin, Index destination) :
|
|
inline Move(Index origin, Index destination) :
|
|
- origin{ origin }, destination{ destination } {}
|
|
|
|
|
|
+ origin{ origin }, destination{ destination },
|
|
|
|
+ promotion{ PieceType::PAWN } {}
|
|
|
|
+
|
|
|
|
+ inline Move(Index origin, Index destination, PieceType promotion) :
|
|
|
|
+ origin{ origin }, destination{ destination }, promotion{ promotion } {}
|
|
|
|
|
|
inline std::string asString(void) const
|
|
inline std::string asString(void) const
|
|
{
|
|
{
|
|
- return origin.getName() + destination.getName();
|
|
|
|
|
|
+ return origin.getName() + destination.getName() +
|
|
|
|
+ (promotion == PieceType::KNIGHT ? "n" : "") +
|
|
|
|
+ (promotion == PieceType::BISHOP ? "b" : "") +
|
|
|
|
+ (promotion == PieceType::ROOK ? "r" : "") +
|
|
|
|
+ (promotion == PieceType::QUEEN ? "q" : "");
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -129,6 +172,13 @@ struct chessy::Bitboard
|
|
inline void moveSEOne (void) { bits = (bits >> 7) & ~aColumn; }
|
|
inline void moveSEOne (void) { bits = (bits >> 7) & ~aColumn; }
|
|
inline Bitboard seOne (void) { return (bits >> 7) & ~aColumn; }
|
|
inline Bitboard seOne (void) { return (bits >> 7) & ~aColumn; }
|
|
|
|
|
|
|
|
+ template<Side side>
|
|
|
|
+ inline void pushOne (void);
|
|
|
|
+ template<>
|
|
|
|
+ inline void pushOne<WHITE_SIDE>(void) { moveNorthOne(); }
|
|
|
|
+ template<>
|
|
|
|
+ inline void pushOne<BLACK_SIDE>(void) { moveSouthOne(); }
|
|
|
|
+
|
|
inline void operator &= (const Bitboard& b) { bits &= b.bits; }
|
|
inline void operator &= (const Bitboard& b) { bits &= b.bits; }
|
|
inline void operator |= (const Bitboard& b) { bits |= b.bits; }
|
|
inline void operator |= (const Bitboard& b) { bits |= b.bits; }
|
|
inline void operator ^= (const Bitboard& b) { bits ^= b.bits; }
|
|
inline void operator ^= (const Bitboard& b) { bits ^= b.bits; }
|