public override AIDecision RequestMove(AiGameInformation gameInformation) { if (_brokenDueToInvalidLaunch) { return(AIDecision.Resign( "Fuego already plays in another game. Fuego may only play in one game at a time.")); } RequireInitialization(gameInformation); return(FuegoSingleton.Instance.RequestMove(this, gameInformation)); }
public override AIDecision RequestMove(AiGameInformation preMoveInformation) { var moves = preMoveInformation.GameTree.PrimaryMoveTimeline.ToList(); if (moves.Any() && moves.Last().Kind == MoveKind.Pass) { return(AIDecision.MakeMove(Move.Pass(preMoveInformation.AIColor), "You passed, too!")); } GameBoard createdBoard = GameBoard.CreateBoardFromGameTree(preMoveInformation.GameInfo, preMoveInformation.GameTree); MoveResult[,] moveResults = Ruleset.Create( preMoveInformation.GameInfo.RulesetType, preMoveInformation.GameInfo.BoardSize, CountingType.Area).GetMoveResult(GetLastNodeOrEmptyBoard(preMoveInformation.GameTree)); List <Position> possibleIntersections = new List <Position>(); for (int x = 0; x < preMoveInformation.GameInfo.BoardSize.Width; x++) { for (int y = 0; y < preMoveInformation.GameInfo.BoardSize.Height; y++) { if (moveResults[x, y] == MoveResult.Legal) { possibleIntersections.Add(new Position(x, y)); } } } if (possibleIntersections.Count == 0) { // TODO (future): The AI should probably pass, not resign. return(AIDecision.Resign("There are no more moves left to do.")); } Position chosen = possibleIntersections[Randomizer.Next(possibleIntersections.Count)]; return(AIDecision.MakeMove(Move.PlaceStone(preMoveInformation.AIColor, chosen), "I chose at random.")); }
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); }
/// <summary> /// Requests a move from the AI /// </summary> /// <param name="gameInformation">Move request info</param> /// <returns>AI decision</returns> public override AIDecision RequestMove(AiGameInformation gameInformation) { return(AIDecision.Resign("I could have won but I decided to let you win.")); }
private AIDecision TrueRequestMove(AiGameInformation gameInformation) { FixHistory(gameInformation); // 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) < OldFuego.ComparisonTolerance) || (Math.Abs(value - 1) < OldFuego.ComparisonTolerance) ? "Reading from opening book." : "Win chance (" + gameInformation.AIColor + "): " + 100 * value + "%"; Note(winChanceNote); var moveDecision = AIDecision.MakeMove( move, winChanceNote); moveDecision.AiNotes = this._storedNotes.ToList(); // copy // Prepare the way this._storedNotes.Clear(); // Return result return(moveDecision); }