public async Task <IEnumerable <Position> > GetIsolatedDeadPositions(Fuego fuego, GameController gameController) { var action = FuegoAction.ThatReturnsGtpResponse(() => { var information = new AiGameInformation(gameController.Info, StoneColor.Black, gameController.Players.Black, gameController.GameTree); TrueInitialize(information); FixHistory(information); // Set the player's strength if (_lastMaxGames != fuego.MaxGames) { SendCommand("uct_param_player max_games " + fuego.MaxGames); _lastMaxGames = fuego.MaxGames; } var result = SendCommand("final_status_list dead"); return(result); }); EnqueueAction(action); var response = await action.GetGtpResponseAsync(); var positions = response.Text.Split(new[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries); var mark = new List <Position>(); foreach (string position in positions) { mark.Add(Position.FromIgsCoordinates(position)); } return(mark); }
public async Task <IEnumerable <Position> > GetDeadPositions(Fuego fuego) { var action = FuegoAction.ThatReturnsGtpResponse(() => { // Set the player's strength if (_lastMaxGames != fuego.MaxGames) { SendCommand("uct_param_player max_games " + fuego.MaxGames); _lastMaxGames = fuego.MaxGames; } var result = SendCommand("final_status_list dead"); return(result); }); EnqueueAction(action); var response = await action.GetGtpResponseAsync(); var positions = response.Text.Split(new[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries); var mark = new List <Position>(); foreach (string position in positions) { mark.Add(Position.FromIgsCoordinates(position)); } return(mark); }
public AIDecision RequestMove(Fuego fuego, AiGameInformation gameInformation) { var action = FuegoAction.ThatReturnsAiDecision(() => TrueRequestMove(fuego, gameInformation)); EnqueueAction(action); return(action.GetAiDecisionResult()); }
public AIDecision GetIsolatedHint(Fuego fuego, AiGameInformation gameInformation) { var action = FuegoAction.ThatReturnsAiDecision(() => { TrueInitialize(gameInformation); return(TrueRequestMove(fuego, gameInformation)); }); EnqueueAction(action); return(action.GetAiDecisionResult()); }
public AIDecision GetHint(Fuego fuego, AiGameInformation gameInformation) { var action = FuegoAction.ThatReturnsAiDecision(() => { var result = TrueRequestMove(fuego, gameInformation); UndoOneMove(); return(result); }); EnqueueAction(action); return(action.GetAiDecisionResult()); }
private AIDecision TrueRequestMove(Fuego fuego, AiGameInformation gameInformation) { FixHistory(gameInformation); // Set whether a player can resign bool allowResign = fuego.AllowResign && gameInformation.GameInfo.NumberOfHandicapStones == 0; if (allowResign != this._lastAllowResign) { this._lastAllowResign = allowResign; if (!allowResign) { SendCommand("uct_param_player resign_threshold 0"); } } // Set whether a player can ponder if (!_ponderSet) { SendCommand("uct_param_player ponder " + (fuego.Ponder ? "1" : "0")); _ponderSet = true; } // Set the player's strength if (_lastMaxGames != fuego.MaxGames) { SendCommand("uct_param_player max_games " + fuego.MaxGames); _lastMaxGames = fuego.MaxGames; } // Move for what color? string movecolor = gameInformation.AIColor == StoneColor.Black ? "B" : "W"; // Update remaining time var timeLeftArguments = gameInformation.AiPlayer.Clock.GetGtpTimeLeftCommandArguments(); if (timeLeftArguments != null) { int secondsRemaining = timeLeftArguments.NumberOfSecondsRemaining; secondsRemaining = Math.Max(secondsRemaining - 2, 0); // let's give the AI less time to ensure it does its move on time SendCommand("time_left " + movecolor + " " + secondsRemaining + " " + timeLeftArguments.NumberOfStonesRemaining); } // Generate the next move string result = SendCommand("genmove " + movecolor).Text; if (result == "resign") { var resignDecision = AIDecision.Resign("Resigned because of low win chance."); resignDecision.AiNotes = this._storedNotes; this._storedNotes.Clear(); return(resignDecision); } var move = result == "PASS" ? Move.Pass(gameInformation.AIColor) : Move.PlaceStone(gameInformation.AIColor, Position.FromIgsCoordinates(result)); // Change history this._history.Add(move); // Get win percentage string commandResult = SendCommand("uct_value_black").Text; float value = float.Parse(commandResult, CultureInfo.InvariantCulture); if (gameInformation.AIColor == StoneColor.White) { value = 1 - value; } string winChanceNote = (Math.Abs(value) < ComparisonTolerance) || (Math.Abs(value - 1) < ComparisonTolerance) ? "Reading from opening book." : "Win chance (" + gameInformation.AIColor + "): " + 100 * value + "%"; Debug.WriteLine(winChanceNote); var moveDecision = AIDecision.MakeMove( move, winChanceNote); moveDecision.AiNotes = this._storedNotes.ToList(); // copy // Prepare the way this._storedNotes.Clear(); // Return result return(moveDecision); }