# How are chess engines able to rank a Mate in X above a Mate in X+Y?

According to an engine, a mate in X moves = +infinity, since it is a forced win for it.

Also according to an engine, a mate in X+Y moves = +infinity, since it's a forced win (just more moves, but an engine doesn't care about this).

Due to the pruning in the minimax algorithm, if the engine first examines the "mate in X+Y moves" branch, it will see it's a forced win and then prune all the other branches.

Due to this pruning, it wouldn't examine the mate in X moves branch.

However, engines like Stockfish always rank a mate in X moves above a mate in X+Y moves. I refuse to believe these engines always know intuitively which branch to look at first (if this was the case, then the engines would first look at the mate in X moves branch first, and then prune the rest, which would make sense).

Question: Given this, how do engines always rank a forced win/mate in X above a forced win/mate in X+Y, if they sometimes look at the latter first?

• Not an answer to your question, but I believe that engines don't evaluate a mate as +infinity but as some (large) finite number. Jun 21, 2018 at 21:30
• I think your premise is flawed. I sometimes see the engine declare a mate in 15, think for a few seconds, and then declare a mate in 12 instead. Obviously it didn't look at the best branch first, but considered it later.
– D M
Jun 21, 2018 at 21:32
• @user1583209 Agreed, I was just using "infinity" as a theoretical value. Jun 22, 2018 at 1:17
• @D M Okay, that makes sense. I just couldn't remember seeing that, so I thought it was odd. Jun 22, 2018 at 1:18
• When a computer finds a mate in X, it returns (INF - X). This allows it to keep track of of number of move til mate and to return a better value. If you use Iterative deepening, the first mate found is the shortest mate. Note: INF is a high number and may be negative for black mating, so the formula would change to -INF + X. Jun 22, 2018 at 2:35