diff --git a/Sources/Bitboard/src/bagaturchess/bitboard/impl1/internal/MoveGenerator.java b/Sources/Bitboard/src/bagaturchess/bitboard/impl1/internal/MoveGenerator.java index 6a9e4659..037f2d72 100644 --- a/Sources/Bitboard/src/bagaturchess/bitboard/impl1/internal/MoveGenerator.java +++ b/Sources/Bitboard/src/bagaturchess/bitboard/impl1/internal/MoveGenerator.java @@ -71,8 +71,8 @@ public void clearHistoryHeuristics() { Arrays.fill(HH_MOVES[BLACK], 0); Arrays.fill(BF_MOVES[WHITE], 1); Arrays.fill(BF_MOVES[BLACK], 1); - Arrays.fill(LMR_ALL[WHITE], 1); - Arrays.fill(LMR_ALL[BLACK], 1); + Arrays.fill(LMR_ALL[WHITE], 0); + Arrays.fill(LMR_ALL[BLACK], 0); Arrays.fill(LMR_ABOVE_ALPHA[WHITE], 0); Arrays.fill(LMR_ABOVE_ALPHA[BLACK], 0); @@ -158,29 +158,43 @@ public void addLMR_AboveAlpha(final int color, final int move, final int depth) } - public int getLMR_Rate(final int color, final int move) { - - int fromToIndex = MoveUtil.getFromToIndex(move); - - return LMR_STAT_MULTIPLIER * LMR_ABOVE_ALPHA[color][fromToIndex] / LMR_ALL[color][fromToIndex]; - } - - - public VarStatistic updateLMRAboveAlpha_Stats(final int color, VarStatistic stats) { + public VarStatistic updateLMRStats(final int color, VarStatistic stats) { stats.clear(); for (int fromToIndex = 0; fromToIndex < LMR_ALL[color].length; fromToIndex++) { - int rate = LMR_STAT_MULTIPLIER * LMR_ABOVE_ALPHA[color][fromToIndex] / LMR_ALL[color][fromToIndex]; + boolean has_stats = LMR_ALL[color][fromToIndex] != 0; - stats.addValue(rate); + if (has_stats) { //Prevent adding zeros for from_to squares without statistics yet + + stats.addValue(getLMR_Rate_internal(color, fromToIndex)); + } } return stats; } + public int getLMR_Rate(final int color, final int move) { + + int fromToIndex = MoveUtil.getFromToIndex(move); + + return getLMR_Rate_internal(color, fromToIndex); + } + + + private int getLMR_Rate_internal(final int color, final int fromToIndex) { + + if (LMR_ALL[color][fromToIndex] == 0) { + + return 0; + } + + return LMR_STAT_MULTIPLIER * LMR_ABOVE_ALPHA[color][fromToIndex] / LMR_ALL[color][fromToIndex]; + } + + public void addKillerMove(final int move, final int ply) { if (EngineConstants.ENABLE_KILLER_MOVES) { if (KILLER_MOVE_1[ply] != move) { diff --git a/Sources/Search/src/bagaturchess/search/impl/alg/SearchImpl.java b/Sources/Search/src/bagaturchess/search/impl/alg/SearchImpl.java index 12cca665..14d19ea4 100644 --- a/Sources/Search/src/bagaturchess/search/impl/alg/SearchImpl.java +++ b/Sources/Search/src/bagaturchess/search/impl/alg/SearchImpl.java @@ -171,10 +171,10 @@ protected boolean isDraw() { } - protected boolean isDrawPV(int depth) { + protected boolean isDrawPV(int ply) { //Skip the draw check for the root, we need at least one move in the pv - if (depth == 0) { + if (ply == 0) { return false; } diff --git a/Sources/Search/src/bagaturchess/search/impl/alg/impl1/Search_PVS_NWS.java b/Sources/Search/src/bagaturchess/search/impl/alg/impl1/Search_PVS_NWS.java index cf42fd28..46cdafae 100644 --- a/Sources/Search/src/bagaturchess/search/impl/alg/impl1/Search_PVS_NWS.java +++ b/Sources/Search/src/bagaturchess/search/impl/alg/impl1/Search_PVS_NWS.java @@ -91,12 +91,18 @@ public class Search_PVS_NWS extends SearchImpl { private long lastSentMinorInfo_timestamp; private long lastSentMinorInfo_nodesCount; + private VarStatistic historyAVGScores; + private VarStatistic lmrAboveAlphaAVGScores_white; private VarStatistic lmrAboveAlphaAVGScores_black; + private static final boolean USE_LMR_ABOVE_ALPHA = false; + + private boolean USE_DTZ_CACHE = false; + private IEvalEntry temp_cache_entry; @@ -777,17 +783,20 @@ If the engine needs to know the DTZ value (which is only necessary when a TB roo if (EngineConstants.ENABLE_LMR && reduction != 1) { - moveGen.addLMR_All(cb.colorToMoveInverse, move, depth); + if (USE_LMR_ABOVE_ALPHA) moveGen.addLMR_All(cb.colorToMoveInverse, move, depth); score = -search(mediator, info, pvman, evaluator, cb, moveGen, ply + 1, depth - reduction, -alpha - 1, -alpha, false, 0); - if (score > alpha) { - - moveGen.addLMR_AboveAlpha(cb.colorToMoveInverse, move, depth); + if (USE_LMR_ABOVE_ALPHA) { - moveGen.updateLMRAboveAlpha_Stats(cb.colorToMoveInverse, getLMRStats(cb.colorToMoveInverse)); - - //System.out.println(getLMRStats(cb.colorToMoveInverse).getEntropy()); + if (score > alpha) { + + moveGen.addLMR_AboveAlpha(cb.colorToMoveInverse, move, depth); + + moveGen.updateLMRStats(cb.colorToMoveInverse, getLMRStats(cb.colorToMoveInverse)); + + //System.out.println("COLOR " + cb.colorToMoveInverse + " ENTROPY=" + getLMRStats(cb.colorToMoveInverse).getEntropy() + " DISPERSE=" + getLMRStats(cb.colorToMoveInverse).getDisperse()); + } } } @@ -887,14 +896,11 @@ If the engine needs to know the DTZ value (which is only necessary when a TB roo } - if (!SearchUtils.isMateVal(bestScore)) { + if (env.getTPT() != null) { - if (env.getTPT() != null) { - - env.getTPT().put(hashkey, depth, bestScore, alphaOrig, beta, bestMove); - } + env.getTPT().put(hashkey, depth, bestScore, alphaOrig, beta, bestMove); } - + if (bestScore != node.eval) { @@ -938,7 +944,7 @@ public int qsearch(ISearchMediator mediator, PVManager pvman, IEvaluator evaluat if (isDraw()) { node.eval = getDrawScores(-1); - + return node.eval; } @@ -1141,12 +1147,9 @@ public int qsearch(ISearchMediator mediator, PVManager pvman, IEvaluator evaluat } //TODO: Maybe this puts are too often and SMP version could have [problems 10 times lower NPS - to check - if (!SearchUtils.isMateVal(alpha)) { - - if (env.getTPT() != null) { + if (env.getTPT() != null) { - env.getTPT().put(cb.zobristKey, 0, bestScore, alphaOrig, beta, bestMove); - } + env.getTPT().put(cb.zobristKey, 0, bestScore, alphaOrig, beta, bestMove); } } else { @@ -1209,15 +1212,15 @@ private boolean extractFromTT(int ply, PVNode result, ITTEntry entry, ISearchInf } result.leaf = true; - - if (ply > 0 && isDraw()) { - result.eval = getDrawScores(-1); //EvalConstants.SCORE_DRAW; + if ((isPv && isDrawPV(ply)) || (ply > 0 && !isPv && isDraw())) { + + result.eval = getDrawScores(-1); result.bestmove = 0; return true; - } + } if (info != null && info.getSelDepth() < ply) { @@ -1235,34 +1238,37 @@ private boolean extractFromTT(int ply, PVNode result, ITTEntry entry, ISearchInf if (isPv) { - if (!env.getBitboard().isPossible(result.bestmove)) { - - throw new IllegalStateException("!env.getBitboard().isPossible(result.bestmove)"); - } - - env.getBitboard().makeMoveForward(result.bestmove); - ply++; - env.getTPT().get(env.getBitboard().getHashKey(), tt_entries_per_ply[ply]); - - if (!tt_entries_per_ply[ply].isEmpty()) { + if (ply < ISearch.MAX_DEPTH) { + if (!env.getBitboard().isPossible(result.bestmove)) { + + throw new IllegalStateException("!env.getBitboard().isPossible(result.bestmove)"); + } - draw = extractFromTT(ply, result.child, tt_entries_per_ply[ply], info, isPv); + env.getBitboard().makeMoveForward(result.bestmove); + env.getTPT().get(env.getBitboard().getHashKey(), tt_entries_per_ply[ply]); - if (draw) { + if (!tt_entries_per_ply[ply].isEmpty()) { - result.eval = getDrawScores(-1); - } else { + draw = extractFromTT(ply, result.child, tt_entries_per_ply[ply], info, isPv); + - result.leaf = false; + if (draw) { + + result.eval = getDrawScores(-1); + + } else { + + result.leaf = false; + } } + + env.getBitboard().makeMoveBackward(result.bestmove); } - - env.getBitboard().makeMoveBackward(result.bestmove); } } @@ -1271,8 +1277,6 @@ private boolean extractFromTT(int ply, PVNode result, ITTEntry entry, ISearchInf } - - private Stack stack = new Stack(); diff --git a/Sources/Search/src/bagaturchess/search/impl/tpt/TTable_StaticArrays.java b/Sources/Search/src/bagaturchess/search/impl/tpt/TTable_StaticArrays.java index 91a63a76..09b8352f 100644 --- a/Sources/Search/src/bagaturchess/search/impl/tpt/TTable_StaticArrays.java +++ b/Sources/Search/src/bagaturchess/search/impl/tpt/TTable_StaticArrays.java @@ -26,6 +26,7 @@ import bagaturchess.bitboard.impl1.internal.Assert; import bagaturchess.bitboard.impl1.internal.EngineConstants; import bagaturchess.bitboard.impl1.internal.Util; +import bagaturchess.search.impl.alg.SearchUtils; import bagaturchess.uci.api.ChannelManager; @@ -135,6 +136,11 @@ public void get(long key, ITTEntry entry) { @Override public void put(long hashkey, int depth, int eval, int alpha, int beta, int bestmove) { + if (SearchUtils.isMateVal(eval)) { + + return; + } + int flag = ITTEntry.FLAG_EXACT; if (eval >= beta) {