|
@@ -0,0 +1,81 @@
|
|
|
|
+#include "Evaluate.h"
|
|
|
|
+
|
|
|
|
+using namespace chessy;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+namespace chessy
|
|
|
|
+{
|
|
|
|
+ namespace values
|
|
|
|
+ {
|
|
|
|
+ const MoveValue PAWN = 1.0f;
|
|
|
|
+ const MoveValue KNIGHT = 3.0f;
|
|
|
|
+ const MoveValue BISHOP = 3.0f;
|
|
|
|
+ const MoveValue ROOK = 5.0f;
|
|
|
|
+ const MoveValue QUEEN = 9.0f;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#include <random>
|
|
|
|
+static typename std::mt19937 e(1034345);
|
|
|
|
+static std::uniform_real_distribution<MoveValue> ee(0, 0.001);
|
|
|
|
+
|
|
|
|
+template<Side side>
|
|
|
|
+MoveValue chessy::evaluatePositives(const ChessGame& game)
|
|
|
|
+{
|
|
|
|
+ MoveValue piecePoints = 0;
|
|
|
|
+ const Board& bd = game.getBoard();
|
|
|
|
+ Bitboard p = bd.getPawns<side>();
|
|
|
|
+ Bitboard n = bd.getKnights<side>();
|
|
|
|
+ Bitboard b = bd.getBishops<side>();
|
|
|
|
+ Bitboard r = bd.getRooks<side>();
|
|
|
|
+ Bitboard q = bd.getQueens<side>();
|
|
|
|
+ Bitboard k = bd.getKing<side>();
|
|
|
|
+ piecePoints += values::PAWN * p.popcount();
|
|
|
|
+ piecePoints += values::KNIGHT * n.popcount();
|
|
|
|
+ piecePoints += values::BISHOP * b.popcount();
|
|
|
|
+ piecePoints += values::ROOK * r.popcount();
|
|
|
|
+ piecePoints += values::QUEEN * q.popcount();
|
|
|
|
+
|
|
|
|
+ for (auto knight : PositionSet{ n })
|
|
|
|
+ piecePoints += KnightMoveGenerator{ knight, bd.get<side>() }.getBitboard().popcount() * 0.05;
|
|
|
|
+ for (auto bishop : PositionSet{ b })
|
|
|
|
+ piecePoints += PrimitiveBishopMoveGenerator{ bishop, bd.get<otherSide(side)>(), bd.get<side>() }.getBitboard().popcount() * 0.03;
|
|
|
|
+ for (auto rook : PositionSet{ r })
|
|
|
|
+ piecePoints += PrimitiveRookMoveGenerator{ rook, bd.get<otherSide(side)>(), bd.get<side>() }.getBitboard().popcount() * 0.03;
|
|
|
|
+ for (auto queen : PositionSet{ q })
|
|
|
|
+ piecePoints += PrimitiveQueenMoveGenerator{ queen, bd.get<otherSide(side)>(), bd.get<side>() }.getBitboard().popcount() * 0.012;
|
|
|
|
+
|
|
|
|
+ return piecePoints;// +ee(e);
|
|
|
|
+ /*
|
|
|
|
+ constexpr Side other = otherSide(side);
|
|
|
|
+ p = bd.getPawns<other>();
|
|
|
|
+ n = bd.getKnights<other>();
|
|
|
|
+ b = bd.getBishops<other>();
|
|
|
|
+ r = bd.getRooks<other>();
|
|
|
|
+ q = bd.getQueens<other>();
|
|
|
|
+ k = bd.getKing<other>();
|
|
|
|
+ piecePoints -= 1 * p.popcount();
|
|
|
|
+ piecePoints -= 3 * n.popcount();
|
|
|
|
+ piecePoints -= 3 * b.popcount();
|
|
|
|
+ piecePoints -= 5 * r.popcount();
|
|
|
|
+ piecePoints -= 9 * q.popcount();
|
|
|
|
+
|
|
|
|
+ //for (auto knight : PositionSet{ n })
|
|
|
|
+ // piecePoints -= KnightMoveGenerator{ knight, bd.get<otherSide(side)>() }.getBitboard().popcount() * 0.2;
|
|
|
|
+ for (auto bishop : PositionSet{ b })
|
|
|
|
+ piecePoints -= PrimitiveBishopMoveGenerator{ bishop, bd.get<side>(), bd.get<otherSide(side)>() }.getBitboard().popcount() * 0.2;
|
|
|
|
+ */
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+MoveValue chessy::evaluate(const ChessGame& game)
|
|
|
|
+{
|
|
|
|
+ if (game.getTurn() == WHITE_SIDE)
|
|
|
|
+ return evaluatePositives<WHITE_SIDE>(game) -
|
|
|
|
+ evaluatePositives<BLACK_SIDE>(game);
|
|
|
|
+ else
|
|
|
|
+ return evaluatePositives<BLACK_SIDE>(game) -
|
|
|
|
+ evaluatePositives<WHITE_SIDE>(game);
|
|
|
|
+}
|