Portfish icon indicating copy to clipboard operation
Portfish copied to clipboard

Contempt factor

Open BillOatman opened this issue 12 years ago • 8 comments

Hello. I have added the most recent contempt factor code from Stockfish into my local Portfish as it seemed to be missing. Can I give that code to you to approve and check in?

BillOatman avatar Oct 16 '12 16:10 BillOatman

Thanks Bill, but I do not want to do it like this. I'm behind a lot of commits, I know. But I want to follow a clear order as I did so far. Also, I have no time currently at all. Hmm. But please share that code of course!

bpfliegel avatar Oct 16 '12 16:10 bpfliegel

Gladly, but share it how? It wasn't that much code, I could post it here?

BillOatman avatar Oct 16 '12 16:10 BillOatman

Sorry, I thought you have a forked repo. I suspect you could post it here.

bpfliegel avatar Oct 16 '12 16:10 bpfliegel

UciOptions.cs OptionMap() this.Add("Contempt Factor", new UCIOption(idx++, 0, -50, 50, null));

The rest in Search.cs internal static class Search { #region SignalsType

    /// The SignalsType struct stores volatile flags updated during the search
    /// typically in an async fashion, for instance to stop the search by the GUI.
    internal static volatile bool SignalsStopOnPonderhit = false, SignalsFirstRootMove = false, SignalsStop = false, SignalsFailedLowAtRoot = false;

    #endregion

    internal static LimitsType Limits = new LimitsType();
    internal static readonly List<RootMove> RootMoves = new List<RootMove>();
    internal static Stopwatch SearchTime = new Stopwatch();
    internal static Stopwatch lastInfoTime = new Stopwatch();
    internal static readonly Position RootPosition = new Position();
    internal static readonly RKISS rk = new RKISS();

** internal static Value [] DrawValue = new Value [2];


New routine ///

    /// Determine game phase.  Same logic that is in MaterialTable::probe().
    /// </summary>


    /// <returns>The current game phase.</returns>
    internal static Value gamePhase()
    {
        Value MidgameLimit = (15581);
        Value EndgameLimit = (3998);
        Position pos = RootPosition;
        Value npm = pos.non_pawn_material(ColorC.WHITE) + pos.non_pawn_material(ColorC.BLACK);
        Value gamePhase = npm >= MidgameLimit ? PhaseC.PHASE_MIDGAME
              : npm <= EndgameLimit ? PhaseC.PHASE_ENDGAME
              : (((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));

        return gamePhase;
    }

think() if (RootMoves.Count == 0) { Plug.Write("info depth 0 score "); Plug.Write(score_to_uci(pos.in_check() ? -ValueC.VALUE_MATE : ValueC.VALUE_DRAW)); Plug.Write(Constants.endl);

            RootMoves.Add(new RootMove(MoveC.MOVE_NONE));
            goto finalize;
        }

** if (int.Parse(OptionMap.Instance["Contempt Factor"].v) != 0 && !bool.Parse(OptionMap.Instance["UCI_AnalyseMode"].v)) ** { ** Value cf = int.Parse(OptionMap.Instance["Contempt Factor"].v) * Constants.PawnValueMidgame / 100; // In centipawns
** cf = cf * gamePhase() / PhaseC.PHASE_MIDGAME; // Scale down with phase ** DrawValue[pos.sideToMove] = ValueC.VALUE_DRAW - cf; ** DrawValue[pos.sideToMove ^ 1] = ValueC.VALUE_DRAW + cf; ** } ** else

** DrawValue[ColorC.WHITE] = DrawValue[ColorC.BLACK] = ValueC.VALUE_DRAW;

search() // Step 2. Check for aborted search and immediate draw // Enforce node limit here. FIXME: This only works with 1 search thread. if ((Limits.nodes != 0) && pos.nodes >= Limits.nodes) SignalsStop = true;

        if ((SignalsStop
             || pos.is_draw(false)
             || ss[ssPos].ply > Constants.MAX_PLY) && !RootNode)
        {
            MovesSearchedBroker.Free();

** return DrawValue[pos.sideToMove];

}

qsearch() // Check for an instant draw or maximum ply reached if (pos.is_draw(true) || ss[ssPos].ply > Constants.MAX_PLY) ** return DrawValue[pos.sideToMove];

BillOatman avatar Oct 16 '12 18:10 BillOatman

Formatting is a challenge. Hopefully you can make sense out of it :) The ** lines are new or changed.

BillOatman avatar Oct 16 '12 18:10 BillOatman

Oh man. Thanks.

bpfliegel avatar Oct 16 '12 18:10 bpfliegel

Bill, I won't merge it now, I'm very busy for the next month for certain...

bpfliegel avatar Oct 16 '12 19:10 bpfliegel

No worries.

BillOatman avatar Oct 16 '12 19:10 BillOatman