|
@@ -70,10 +70,14 @@ std::pair<Move, MoveValue> chessy::miniMax(ChessGame& cg, int depth)
|
|
|
{
|
|
|
std::vector<Move> moves;
|
|
|
moves.reserve(200);
|
|
|
- if (cg.getTurn() == WHITE_SIDE)
|
|
|
+ if (cg.getTurn() == WHITE_SIDE) {
|
|
|
generateAllMoves<WHITE_SIDE>(cg, moves);
|
|
|
- else
|
|
|
+ orderMoves<WHITE_SIDE>(cg, moves);
|
|
|
+ }
|
|
|
+ else {
|
|
|
generateAllMoves<BLACK_SIDE>(cg, moves);
|
|
|
+ orderMoves<BLACK_SIDE>(cg, moves);
|
|
|
+ }
|
|
|
|
|
|
const Board& b = cg.getBoard();
|
|
|
auto isCheck = [&cg, &b] () {
|
|
@@ -118,23 +122,27 @@ MoveValue chessy::negamaxImplementation(ChessGame& cg, int depth,
|
|
|
}
|
|
|
|
|
|
const Board& b = cg.getBoard();
|
|
|
- auto isCheck = [&cg, &b] () {
|
|
|
- return cg.getTurn() == BLACK_SIDE ? b.isCheck<WHITE_SIDE>() :
|
|
|
+ auto isCheck = [&cg, &b] (Side turn) {
|
|
|
+ return turn == BLACK_SIDE ? b.isCheck<WHITE_SIDE>() :
|
|
|
b.isCheck<BLACK_SIDE>();
|
|
|
};
|
|
|
|
|
|
std::vector<Move> moves;
|
|
|
- if (cg.getTurn() == WHITE_SIDE)
|
|
|
+ if (cg.getTurn() == WHITE_SIDE) {
|
|
|
generateAllMoves<WHITE_SIDE>(cg, moves);
|
|
|
- else
|
|
|
+ orderMoves<WHITE_SIDE>(cg, moves);
|
|
|
+ }
|
|
|
+ else {
|
|
|
generateAllMoves<BLACK_SIDE>(cg, moves);
|
|
|
+ orderMoves<BLACK_SIDE>(cg, moves);
|
|
|
+ }
|
|
|
|
|
|
bool thereIsMove = false;
|
|
|
for (Move move : moves) {
|
|
|
MoveInfo mi{ move, cg };
|
|
|
UndoInfo ui = cg.doMove(mi);
|
|
|
MoveValue val;
|
|
|
- if (isCheck())
|
|
|
+ if (isCheck(cg.getTurn()))
|
|
|
val = -1e+30;
|
|
|
else {
|
|
|
val = -negamaxImplementation(cg, depth - 1, -beta, -alpha);
|
|
@@ -147,7 +155,7 @@ MoveValue chessy::negamaxImplementation(ChessGame& cg, int depth,
|
|
|
alpha = val;
|
|
|
}
|
|
|
if (!thereIsMove)
|
|
|
- return 0.0;
|
|
|
+ return isCheck(otherSide(cg.getTurn())) ? -1e+30 : 0.0;
|
|
|
return alpha;
|
|
|
}
|
|
|
|
|
@@ -168,10 +176,8 @@ MoveValue chessy::evaluate(const ChessGame& game)
|
|
|
piecePoints += 1 * p.popcount();
|
|
|
piecePoints += 3 * n.popcount();
|
|
|
piecePoints += 3 * b.popcount();
|
|
|
- piecePoints += 4 * r.popcount();
|
|
|
- piecePoints += 6 * q.popcount();
|
|
|
- if (k == Bitboard(0ULL))
|
|
|
- piecePoints -= 100000;
|
|
|
+ piecePoints += 5 * r.popcount();
|
|
|
+ piecePoints += 9 * q.popcount();
|
|
|
|
|
|
constexpr Side other = otherSide(side);
|
|
|
p = bd.getPawns<other>();
|
|
@@ -185,10 +191,8 @@ MoveValue chessy::evaluate(const ChessGame& game)
|
|
|
piecePoints -= 1 * p.popcount();
|
|
|
piecePoints -= 3 * n.popcount();
|
|
|
piecePoints -= 3 * b.popcount();
|
|
|
- piecePoints -= 4 * r.popcount();
|
|
|
- piecePoints -= 6 * q.popcount();
|
|
|
- if (k == Bitboard(0ULL))
|
|
|
- piecePoints += 100000;
|
|
|
+ piecePoints -= 5 * r.popcount();
|
|
|
+ piecePoints -= 9 * q.popcount();
|
|
|
|
|
|
return piecePoints;
|
|
|
}
|