added killer moves to move ordering
This commit is contained in:
1 parent
cb403943cb
commit
8c4a157797
5 files changed
+37
-8
No files matched your search
@@ -49,8 +49,7 @@ int Bitboard::getLS1BIndex() const {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitboard Bitboard::getOccupancy(int index, Bitboard attackMask) {
|
Bitboard Bitboard::getOccupancy(int index, Bitboard attackMask) { Bitboard occupancy;
|
||||||
Bitboard occupancy;
|
|
||||||
int squareCount = attackMask.PopCount();
|
int squareCount = attackMask.PopCount();
|
||||||
|
|
||||||
for (int count = 0; count < squareCount; count++) {
|
for (int count = 0; count < squareCount; count++) {
|
||||||
|
|||||||
@@ -58,4 +58,8 @@ public:
|
|||||||
std::cout << squareCoords[MoveFrom()] << squareCoords[MoveTo()];
|
std::cout << squareCoords[MoveFrom()] << squareCoords[MoveTo()];
|
||||||
std::cout << " (" << moveTypes[GetFlags()] << ")\n";
|
std::cout << " (" << moveTypes[GetFlags()] << ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator uint16_t() {
|
||||||
|
return m_move;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
+30
-5
@@ -3,22 +3,35 @@
|
|||||||
#include "evaluate.h"
|
#include "evaluate.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
static inline int nodes = 0;
|
||||||
static inline int ply = 0;
|
static inline int ply = 0;
|
||||||
static inline Move bestMove = Move();
|
static inline Move bestMove = Move();
|
||||||
static inline int bestScore = -50000;
|
static inline int bestScore = -50000;
|
||||||
|
|
||||||
|
// killer moves [id][ply]
|
||||||
|
static inline Move killerMoves[2][64];
|
||||||
|
|
||||||
static int ScoreMove(Board &board, Move &move) {
|
static int ScoreMove(Board &board, Move &move) {
|
||||||
const int attackerType = board.GetPieceType(move.MoveFrom());
|
const int attackerType = board.GetPieceType(move.MoveFrom());
|
||||||
const int targetType = board.GetPieceType(move.MoveTo());
|
const int targetType = board.GetPieceType(move.MoveTo());
|
||||||
|
|
||||||
if (move.IsCapture()) {
|
if (move.IsCapture()) {
|
||||||
return moveScoreTable[attackerType][targetType];
|
return moveScoreTable[attackerType][targetType] + 10000;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
// 1st killer move
|
||||||
|
if (killerMoves[0][ply] == move) {
|
||||||
|
return 9000;
|
||||||
|
}
|
||||||
|
// 2nd killer move
|
||||||
|
else if (killerMoves[1][ply] == move) {
|
||||||
|
return 8000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SortMoves(Board &board) {
|
static void SortMoves(Board &board) {
|
||||||
std::array<int, 218> scores;
|
std::array<int, 218> scores;
|
||||||
std::array<int, 218> indices;
|
std::array<int, 218> indices;
|
||||||
|
|
||||||
@@ -47,15 +60,18 @@ void SortMoves(Board &board) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ListScores(Board &board) {
|
void ListScores(Board &board) {
|
||||||
|
SortMoves(board);
|
||||||
|
|
||||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||||
Move currentMove = board.moveList[i];
|
Move currentMove = board.moveList[i];
|
||||||
|
|
||||||
std::cout << squareCoords[currentMove.MoveFrom()] << squareCoords[currentMove.MoveTo()];
|
std::cout << squareCoords[currentMove.MoveFrom()] << squareCoords[currentMove.MoveTo()]; std::cout << ": " << ScoreMove(board, currentMove) << '\n';
|
||||||
std::cout << ": " << ScoreMove(board, currentMove) << '\n';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Quiescence(Board board, int alpha, int beta) {
|
static int Quiescence(Board board, int alpha, int beta) {
|
||||||
|
nodes++;
|
||||||
|
|
||||||
int staticScore = Evaluate(board);
|
int staticScore = Evaluate(board);
|
||||||
|
|
||||||
if (staticScore >= beta) {
|
if (staticScore >= beta) {
|
||||||
@@ -95,6 +111,8 @@ static int NegaMax(Board board, int depth, int alpha, int beta, bool isRoot) {
|
|||||||
return Quiescence(board, alpha, beta);
|
return Quiescence(board, alpha, beta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodes++;
|
||||||
|
|
||||||
GenerateMoves(board, board.sideToMove);
|
GenerateMoves(board, board.sideToMove);
|
||||||
|
|
||||||
SortMoves(board);
|
SortMoves(board);
|
||||||
@@ -121,6 +139,10 @@ static int NegaMax(Board board, int depth, int alpha, int beta, bool isRoot) {
|
|||||||
ply--;
|
ply--;
|
||||||
|
|
||||||
if (score >= beta) {
|
if (score >= beta) {
|
||||||
|
// store killer moves
|
||||||
|
killerMoves[1][ply] = killerMoves[0][ply];
|
||||||
|
killerMoves[0][ply] = board.moveList[i];
|
||||||
|
|
||||||
return beta;
|
return beta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,10 +164,13 @@ static int NegaMax(Board board, int depth, int alpha, int beta, bool isRoot) {
|
|||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SearchPosition(Board &board, int depth) {
|
void SearchPosition(Board &board, int depth) {
|
||||||
bestScore = -50000;
|
bestScore = -50000;
|
||||||
bestMove = Move();
|
bestMove = Move();
|
||||||
NegaMax(board, depth, -50000, 50000, true);
|
NegaMax(board, depth, -50000, 50000, true);
|
||||||
|
std::cout << "info depth " << depth << " nodes " << nodes << '\n';
|
||||||
std::cout << "bestmove " << squareCoords[bestMove.MoveFrom()]
|
std::cout << "bestmove " << squareCoords[bestMove.MoveFrom()]
|
||||||
<< squareCoords[bestMove.MoveTo()] << '\n';
|
<< squareCoords[bestMove.MoveTo()] << '\n';
|
||||||
}
|
}
|
||||||
@@ -12,5 +12,4 @@ constexpr int moveScoreTable[6][6] = {
|
|||||||
100, 200, 300, 400, 500, 600
|
100, 200, 300, 400, 500, 600
|
||||||
};
|
};
|
||||||
|
|
||||||
void SortMoves(Board &board);
|
|
||||||
void ListScores(Board &board);
|
void ListScores(Board &board);
|
||||||
@@ -5,6 +5,8 @@
|
|||||||
using U64 = uint64_t;
|
using U64 = uint64_t;
|
||||||
|
|
||||||
constexpr char StartingFen[] = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
constexpr char StartingFen[] = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||||
|
constexpr char KiwiPeteFen[] = "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -";
|
||||||
|
constexpr char KillerFen[] = "rnbqkb1r/pp1p1pPp/8/2p1pP2/1P1P4/3P3P/P1P1P3/RNBQKBNR w KQkq e6 0 1";
|
||||||
|
|
||||||
enum COLOR {
|
enum COLOR {
|
||||||
White,
|
White,
|
||||||
|
|||||||
Reference in new issue
Block a user