0

As I understand, when implementing iterative deepening the best move at one depth should be used for ordering moves at higher depths. I have one issue with this: say I got the move m as my best move at the depth n, then when searching at the depth n + 1 should the move orderer only prioritize m at the highest level of search or at every level where move m is legal?

My current implementation of iterative deepening:

Search:

pvLine = None
for depth in range(1, self.maxDepth):
    self.auxSearch(board, depth, initalHash)
    
    # find the principal variation from the TT
    pvLine = self.getPVLine(board, initalHash)

    bestMove = pvLine[0][0] 
    bestValue = pvLine[0][1]

    self.ordering.setBestMove(bestMove, depth + 1)
    print(f'{depth=} | {bestValue=} | {bestMove=} | {pvLine=}')

return pvLine 

Move ordering:

if((move, depth) == self.bestMove):
    priority += self.BESTMOVE_BONUS

setBestMove function:

def setBestMove(self, move: chess.Move, depth: int) -> None:
    self.bestMove = (move, depth)

self.BESTMOVE_BONUS is a very big number, so the move will have the highest priority.

Currently, I am making sure that the move orderer only prioritizes the best move from previous shallower search at the highest level of the current search. I am not sure if my approach is correct or not?

user8277998
  • 147
  • 6
  • You can use it everywhere. But test the engine's performance every time you apply it anywhere to make sure you are not overdoing it. – ferdy Apr 26 '22 at 05:23

1 Answers1

1

Move ordering will give you a much faster algorithm than without and is fairly easy to implement. You can read more about it here: https://www.chessprogramming.org/Move_Ordering.

I suggest you do as of now and put the best move from previous iteration first. The best move (or the best move sequence, "principal variation") is always the move from previous depths. So if you get a sequence of moves a1, b1, and c1 from depth 3, then at depth 4 you will try a1 at depth 1, b1 at depth 2, and c1 at depth 3 first.

Second you should try good capture moves, often found with MVV-LVA. Capturing a queen with a pawn is usually a good move, but the other way around could be bad if the pawn is protected.

Other easy to implement techniques are Killer moves and History moves, also found in the link above.

eligolf
  • 1,682
  • 1
  • 6
  • 22
  • Should also use best moves from depth 2 ? Like if the PV from depth two is e2, c2, should I prioritize e2 at depth 4 search? – user8277998 Apr 26 '22 at 18:40
  • That is not necessary, you could try and see if it gets you better results but I would assume that the time it takes to save all those into some sort of list would take more time than it gives benefit. – eligolf Apr 27 '22 at 04:29