I've just implemented tapered eval but I'm not sure if I'm actually done in it because it just ruins the move ordering.
I'm using this fen for test: r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1
So this are the info with tapered eval:
info depth 1 score cp 18.000000 nodes 65 time 116 pv e2a6
info depth 2 score cp 18.000000 nodes 165 time 402 pv e2a6 b4c3
info depth 3 score cp 18.000000 nodes 457 time 568 pv e2a6 b4c3 d2c3
info depth 4 score cp 18.000000 nodes 3833 time 1108 pv e2a6 b4c3 d2c3 h3g2
info depth 5 score cp 17.000000 nodes 12212 time 1875 pv e2a6 e6d5 c3d5
info depth 6 score cp 17.000000 nodes 77350 time 4348 pv e2a6 e6d5 c3d5
bestmove e2a6 ponder e6d5
And without tapered eval:
info depth 1 score cp 19.000000 nodes 75 time 66 pv e2a6
info depth 2 score cp 19.000000 nodes 175 time 182 pv e2a6 b4c3
info depth 3 score cp 19.000000 nodes 398 time 371 pv e2a6 b4c3 d2c3
info depth 4 score cp 19.000000 nodes 3650 time 947 pv e2a6 b4c3 d2c3 h3g2
info depth 5 score cp 18.000000 nodes 10995 time 1849 pv e2a6 e6d5 c3d5
info depth 6 score cp 18.000000 nodes 75881 time 4334 pv e2a6 e6d5 c3d5
bestmove e2a6 ponder e6d5
You can see that without tapered eval actualy has less nodes than the other, I'm just wondering if this is necessary or did I just implemented it wrong.
My phase function:
int totalPhase = pawnPhase * 16 + knightPhase * 4 + bishopPhase * 4 + rookPhase * 4 + queenPhase * 2;
int phase = totalPhase;
for each piece in node {
if piece is pawn, phase -= pawnPhase
else if piece is knight, phase -= knightPhase
...
}
return (phase * 256 + (totalPhase / 2)) / totalPhase;
And then I added the interpolation in the eval function:
for (each piece in node) {
...score material weights and positional scores, etc.
}
evaluation = ((mgEvaluation * (256 - phase)) + (egEvaluation * phase)) / 256;
I got the formula in this site: Tapered Eval
If this is actually necessary, can someone give me tips to optimize this?
Tapered eval is very useful and needs to be used since the tactic in early/mid game is way different than in the end game. You don't mention how you sort the moves, but since the tapered eval gives you different numbers in the piece square tables (PST) for a mid game position it is just natural that the move ordering will be slightly different than before. The results you are getting are pretty close to eachother and seems plausible.
Test the start position with tapered eval and see that it gives the same results as just normal eval with the PST for opening. Also do the same with an endgame position and just PST for endgame which should also give the same result.