void Book_MoveReceived(object sender, UCIMoveEventArgs e) { OnClearAnalysis(); UCIInfoEventArgs args = new UCIInfoEventArgs("", -1, 0, 0, 0, 0, 0, e.MoveFrom + e.MoveTo, 0, 0, 0, 0, false, false, -1); SetPoints("0.00", "0"); ProcessEvaluations(args); }
private string GetScore(UCIInfoEventArgs e) { string eval = ""; if (e.Mate > 0) { eval = "#" + e.Mate; } else { eval = GetPointsDisplayValue(e.ScoreCP); } return(GetPositionEvaluationSymbol(e) + " (" + eval + ")"); }
void UciEngine_InfoReceived(object sender, UCIInfoEventArgs e) { ProcessEvaluations(e); }
/*------------------------------------------ * = The position is about equal * +/= White is slightly better * +/- White is clearly better * +- White is winning * * -+ Black is winning * * -/+ Black is clearly better * * =/+ Black is slightly better * * ------------------------------------------*/ private string GetPositionEvaluationSymbol(UCIInfoEventArgs e) { int cp = Math.Abs(e.ScoreCP); bool isWhiteWinning = false; if (cp <= 25) { return("="); } if (this.Game.GameMode == GameMode.EngineVsEngine || this.Game.GameMode == GameMode.OnlineEngineVsEngine) { if (((e.ScoreCP) < 0 && this.Game.Flags.AmIWhite) || ((e.ScoreCP) > 0 && this.Game.Flags.AmIBlack)) { isWhiteWinning = false; } else if (((e.ScoreCP) > 0 && this.Game.Flags.AmIWhite) || ((e.ScoreCP) < 0 && this.Game.Flags.AmIBlack)) { isWhiteWinning = true; } } else if (this.Game.GameMode == GameMode.HumanVsEngine || this.Game.GameMode == GameMode.OnlineHumanVsEngine) { if ((e.ScoreCP * defaultAdvantageValue) > 0) { isWhiteWinning = true; } else { isWhiteWinning = false; } } if (isWhiteWinning) { if (cp > 25 && cp <= 100) { return("+/="); } else if (cp > 100 && cp <= 200) { return("+/-"); } else if (cp > 200) { return("+-"); } } else { if (cp > 25 && cp <= 100) { return("=/+"); } else if (cp > 100 && cp <= 200) { return("-/+"); } else if (cp > 200) { return("-+"); } } return("="); }
private void ProcessEvaluations(UCIInfoEventArgs e) { if (!IsEvaluationsAllowed) { return; } AnalysisEventArgs args = new AnalysisEventArgs(); #region Set Depth,Nps etc. if (e.Depth > 0) { eDepth = e.Depth.ToString(); args.Depth = eDepth; } if (e.NPS > 0) { args.Rate = (e.NPS / 1000) + " kN/s"; } #endregion #region Evaluation Item if (!string.IsNullOrEmpty(e.PV)) { args.Points = GetScore(e); args.IsLowerBound = e.IsLowerBound; args.IsUpperBound = e.IsUpperBound; Moves eMoves; eMoves = LoadMoves(e.PV); args.Pv = e.PV; expectedMove = this.Game.PonderMove; args.Move_Time = expectedMove; string stats = string.Empty; string points = GetScore(e); stats += points + " Depth: " + e.Depth + " "; stats += Clock.GetTimeString(e.Time / 1000) + " "; if (e.NPS > 0) { stats += (e.NPS / 1000) + " kN/s"; } args.EMoves = GetMovesString(eMoves); if (this.UciEngine.IsKibitzer) { TestDebugger.Instance.Write("Analysis........:" + args.EMoves); } args.EStatistics = stats; } #endregion #region ExpectedMove if (e.CurrentMoveNumber > 0) { if (e.CurrentMoveNumber > maxCurrentMoveNumber) { maxCurrentMoveNumber = e.CurrentMoveNumber; } Move m = Move.NewMove(); m.Game = this.Game; if (!this.UciEngine.IsKibitzer) { m.MoveNo = currentMoveNumber; } else { if (this.Game.CurrentMove != null) { m.MoveNo = this.Game.CurrentMove.MoveNo; } else { m.MoveNo = 1; } } if (this.Game.CurrentMove != null) { m.IsWhite = this.Game.CurrentMove.IsWhite; } m.From = e.CurrentMove.Substring(0, 2); m.To = e.CurrentMove.Substring(2, 2); //GameWrapper = new GameW(CurrentFen); GameWrapper.SetFen(CurrentFen); if (!string.IsNullOrEmpty(this.Game.PonderMove) && GameWrapper.IsLegalMove(this.Game.PonderMove) && !this.UciEngine.IsKibitzer) { GameWrapper.AppendMove(this.Game.PonderMove); } m.Piece = Board.PieceFromString(GameWrapper.GetMovingPiece(e.CurrentMove)); string dot = "."; int correctNextMoveNo = this.Game.NextMoveNo; #region Move Formatting if (this.Game.CurrentMove != null) { if (!this.UciEngine.IsKibitzer) { if (this.Game.Flags.IsInfiniteAnalysisOff) { if (!this.Game.CurrentMove.IsWhite) { dot = "..."; } else { correctNextMoveNo++; } } else { if (!this.Game.CurrentMove.IsWhite) { dot = "."; } else { dot = "..."; } } } else { if (!this.Game.NextMoveIsWhite) { dot = "..."; } } } #endregion string moveDisplay = m.Notation.Substring(m.Notation.IndexOf(".") + 1); moveDisplay = correctNextMoveNo + dot + moveDisplay + "(" + e.CurrentMoveNumber + "/" + maxCurrentMoveNumber + ")"; args.MoveDepth = moveDisplay; } #endregion #region Set Player's(Engine's) Eval SetEvaluation(args); #endregion #region Fire Event if (EvaluationsReceived != null) { EvaluationsReceived(this, args); } #endregion }