#include "Evaluate.h" #include "ChessGame.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 static typename std::mt19937 e(1034345); static std::uniform_real_distribution ee(0, 0.001); template MoveValue chessy::evaluatePositives(const ChessGame& game) { MoveValue piecePoints = 0; const Board& bd = game.getBoard(); Bitboard p = bd.getPawns(); Bitboard n = bd.getKnights(); Bitboard b = bd.getBishops(); Bitboard r = bd.getRooks(); Bitboard q = bd.getQueens(); Bitboard k = bd.getKing(); 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() }.getBitboard().popcount() * 0.05; for (auto bishop : PositionSet{ b }) piecePoints += PrimitiveBishopMoveGenerator{ bishop, bd.get(), bd.get() }.getBitboard().popcount() * 0.03; for (auto rook : PositionSet{ r }) piecePoints += PrimitiveRookMoveGenerator{ rook, bd.get(), bd.get() }.getBitboard().popcount() * 0.03; for (auto queen : PositionSet{ q }) piecePoints += PrimitiveQueenMoveGenerator{ queen, bd.get(), bd.get() }.getBitboard().popcount() * 0.012; return piecePoints;// +ee(e); /* constexpr Side other = otherSide(side); p = bd.getPawns(); n = bd.getKnights(); b = bd.getBishops(); r = bd.getRooks(); q = bd.getQueens(); k = bd.getKing(); 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() }.getBitboard().popcount() * 0.2; for (auto bishop : PositionSet{ b }) piecePoints -= PrimitiveBishopMoveGenerator{ bishop, bd.get(), bd.get() }.getBitboard().popcount() * 0.2; */ } MoveValue chessy::evaluate(const ChessGame& game) { if (game.getTurn() == WHITE_SIDE) return evaluatePositives(game) - evaluatePositives(game); else return evaluatePositives(game) - evaluatePositives(game); }