/// <summary> /// Returns a string that describes the given principal variation. /// </summary> /// <param name="position">The position the principal variation is to be played on.</param> /// <param name="depth">The depth of the search that yielded the principal variation.</param> /// <param name="value">The value of the search that yielded the principal variation.</param> /// <returns>A string that describes the given principal variation.</returns> private String CreatePVString(Position position, Int32 depth, Int32 value) { List <Int32> pv = GetCurrentPV(); Boolean isMate = Math.Abs(value) > NearCheckmateValue; Int32 movesToMate = (CheckmateValue - Math.Abs(value) + 1) / 2; switch (Restrictions.Output) { // Return standard output. case OutputType.GUI: String depthString = depth.ToString(); String valueString = isMate ? (value > 0 ? "+Mate " : "-Mate ") + movesToMate : (value / 100.0).ToString("+0.00;-0.00"); String movesString = Stringify.MovesAlgebraically(position, pv); return(String.Format(PVFormat, depthString, valueString, movesString)); // Return UCI output. case OutputType.UCI: String score = isMate ? "mate " + (value < 0 ? "-" : "") + movesToMate : "cp " + value; Double elapsed = _stopwatch.Elapsed.TotalMilliseconds; Int64 nps = (Int64)(1000 * _totalNodes / elapsed); return(String.Format("info depth {0} score {1} time {2} nodes {3} nps {4} pv {5}", depth, score, (Int32)elapsed, _totalNodes, nps, Stringify.Moves(pv))); } return(null); }
/// <summary> /// Returns the PGN string of the game. /// </summary> /// <returns>The PGN string of the game.</returns> public String GetPGN() { StringBuilder sb = new StringBuilder(); sb.Append("[Date \"" + _date + "\"]"); sb.Append(Environment.NewLine); sb.Append("[White \"" + White.Name + "\"]"); sb.Append(Environment.NewLine); sb.Append("[Black \"" + Black.Name + "\"]"); sb.Append(Environment.NewLine); String result = "*"; switch (_state) { case GameState.WhiteWon: result = "1-0"; break; case GameState.BlackWon: result = "0-1"; break; case GameState.Draw: result = "1/2-1/2"; break; } sb.Append("[Result \"" + result + "\"]"); sb.Append(Environment.NewLine); String initialFEN = _initialPosition.GetFEN(); if (initialFEN != Position.StartingFEN) { sb.Append("[SetUp \"1\"]"); sb.Append(Environment.NewLine); sb.Append("[FEN \"" + initialFEN + "\"]"); sb.Append(Environment.NewLine); } sb.Append(Environment.NewLine); sb.Append(Stringify.MovesAlgebraically(_initialPosition, _moves, StringifyOptions.Proper)); if (result != "*") { sb.Append(" " + result); } return(sb.ToString()); }