/// <summary> /// Evaluates a position with stop parameters. /// </summary> /// <param name="evalReq">The eval request.</param> public void Evaluate(StartEvaluationRequest evalReq) { if (evalReq.EngineOptions != null) { foreach (var op in evalReq.EngineOptions) { this.SetOption(op.Key, op.Value.ToUciValueString()); } } var position = StartPositionExtrapolator.ExtrapolateStartingPosition(evalReq.Position); this.SetPosition(position.Fen); var goCmd = evalReq.ToGoString(); this.bridgeLogger.LogInformation($"Using gocmd: '{goCmd}'."); this.engineProcess.WriteCommand(goCmd); if (evalReq?.CompletionCriteria?.Infinite ?? false) { // infinite } else { this.engineProcess.WaitForText("bestmove", int.MaxValue); } this.engineProcess.PopOutputBuffer(); }
/// <summary> /// Gets the move filter string for "searchmoves". /// </summary> /// <param name="req">The evaluation request.</param> /// <returns>The "searchmoves" string.</returns> /// <exception cref="ArgumentException">If an invalid SAN move is given.</exception> internal static string GetMoveFilterString(this StartEvaluationRequest req) { var sb = new StringBuilder(); sb.Append("searchmoves "); var startFen = StartPositionExtrapolator.ExtrapolateStartingPosition(req.Position).Fen; var board = Board.NewFromFen(startFen); var moves = board.GetPossibleMoves(board.MoveHistory.Count % 2 == 0 ? PieceColor.White : PieceColor.Black); foreach (var m in req.SearchMoves) { if (!string.IsNullOrEmpty(m.UCI)) { sb.Append($"{m.UCI} "); } else if (!string.IsNullOrEmpty(m.SAN)) { var correspondingMove = moves.FirstOrDefault(mov => mov.ToContextualSANString(board) == m.SAN); if (correspondingMove == default(Move)) { throw new ArgumentException($"Cannot create go string with move filter with SAN '{m.SAN}' as no corresponding UCI move can be found."); } sb.Append($"{correspondingMove.ToUciString()} "); } } return(sb.ToString().TrimEnd()); }