Skip to content

Commit c4511c7

Browse files
committed
two very minor move ordering improvement
- hardcode for only two killer slots per depth - prioritize killer move slot - generate promotions in order: queen, knight, root, bishop
1 parent 5988f58 commit c4511c7

File tree

4 files changed

+19
-31
lines changed

4 files changed

+19
-31
lines changed

chess.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ class Game
461461
// killer moves
462462
static CMove killers[MAX_GAME_LENGTH][MAX_KILLERS];
463463

464+
// the code assumes that there are only two killer moves
465+
CT_ASSERT(MAX_KILLERS == 2);
464466

465467
// perform alpha-beta search on the given position
466468
template<uint8 chance>

chess_cpu.exe

1 KB
Binary file not shown.

move_gen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ void BitBoardUtils::addCompactPawnMoves(int *nMoves, CMove **genMoves, uint8 fro
314314
// promotion
315315
if (dst & (RANK1 | RANK8))
316316
{
317-
addCompactMove(nMoves, genMoves, from, to, flags | CM_FLAG_KNIGHT_PROMOTION);
318-
addCompactMove(nMoves, genMoves, from, to, flags | CM_FLAG_BISHOP_PROMOTION);
319317
addCompactMove(nMoves, genMoves, from, to, flags | CM_FLAG_QUEEN_PROMOTION);
318+
addCompactMove(nMoves, genMoves, from, to, flags | CM_FLAG_KNIGHT_PROMOTION);
320319
addCompactMove(nMoves, genMoves, from, to, flags | CM_FLAG_ROOK_PROMOTION);
320+
addCompactMove(nMoves, genMoves, from, to, flags | CM_FLAG_BISHOP_PROMOTION);
321321
}
322322
else
323323
{

search.cpp

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -290,24 +290,10 @@ int16 Game::alphabeta(HexaBitBoardPosition *pos, uint64 hash, int depth, int cur
290290
// update killer move table if this was a non-capture move
291291
if (!(ttMove.getFlags() & CM_FLAG_CAPTURE))
292292
{
293-
// TODO: add to the first slot
294-
295-
bool foundKiller = false;
296-
for (int j = 0; j < MAX_KILLERS; j++)
293+
if (killers[depth][0] != ttMove)
297294
{
298-
if (killers[depth][j] == ttMove)
299-
{
300-
foundKiller = true;
301-
break;
302-
}
303-
}
304-
305-
if (!foundKiller)
306-
{
307-
for (int j = 1; j < MAX_KILLERS; j++)
308-
killers[depth][j] = killers[depth][j - 1];
295+
killers[depth][1] = killers[depth][0];
309296
killers[depth][0] = ttMove;
310-
311297
}
312298
}
313299

@@ -390,7 +376,9 @@ int16 Game::alphabeta(HexaBitBoardPosition *pos, uint64 hash, int depth, int cur
390376
}
391377

392378
// try killers first
393-
// also filter out killers and TT move from the list
379+
// also filter out killers and TT move from the list
380+
// TODO: no need to generate non captures if we get a cutoff on trying killer moves
381+
// need a move validity checker routine
394382
for (int i = searched; i < nMoves; i++)
395383
{
396384
// filter TT moves
@@ -399,16 +387,9 @@ int16 Game::alphabeta(HexaBitBoardPosition *pos, uint64 hash, int depth, int cur
399387
newMoves[i] = CMove();
400388
continue;
401389
}
402-
bool isKiller = false;
403390

404-
for (int j = 0; j < MAX_KILLERS; j++)
405-
{
406-
if (killers[depth][j] == newMoves[i])
407-
{
408-
isKiller = true;
409-
break;
410-
}
411-
}
391+
bool isKiller = (killers[depth][0] == newMoves[i]) ||
392+
(killers[depth][1] == newMoves[i]);
412393

413394
if (isKiller)
414395
{
@@ -419,7 +400,13 @@ int16 Game::alphabeta(HexaBitBoardPosition *pos, uint64 hash, int depth, int cur
419400
int16 curScore = -alphabeta<!chance>(&newPos, newHash, depth - 1, curPly + 1, -beta, -alpha, true);
420401
if (curScore >= beta)
421402
{
422-
// TODO: increase priority of this killer
403+
// increase priority of this killer
404+
if (killers[depth][0] != newMoves[i])
405+
{
406+
killers[depth][1] = killers[depth][0];
407+
killers[depth][0] = newMoves[i];
408+
}
409+
423410
TranspositionTable::update(hash, curScore, SCORE_GE, newMoves[i], depth, curPly);
424411
return curScore;
425412
}
@@ -454,8 +441,7 @@ int16 Game::alphabeta(HexaBitBoardPosition *pos, uint64 hash, int depth, int cur
454441
if (curScore >= beta)
455442
{
456443
// update killer table
457-
for (int j = 1; j < MAX_KILLERS; j++)
458-
killers[depth][j] = killers[depth][j - 1];
444+
killers[depth][1] = killers[depth][0];
459445
killers[depth][0] = newMoves[i];
460446

461447
TranspositionTable::update(hash, curScore, SCORE_GE, newMoves[i], depth, curPly);

0 commit comments

Comments
 (0)