Example #1
0
        public override AIDecision RequestMove(AiGameInformation gameInformation)
        {
            var moves = gameInformation.GameTree.PrimaryMoveTimeline.ToList();

            if (moves.Any() &&
                moves.Last().Kind == MoveKind.Pass)
            {
                return(AIDecision.MakeMove(Move.Pass(gameInformation.AIColor), "You passed, too!"));
            }

            JokerGame currentGame = new JokerGame(gameInformation.GameInfo.BoardSize.Height,
                                                  gameInformation.GameInfo.BoardSize.Width,
                                                  null,
                                                  null);

            foreach (Move move in gameInformation.GameTree.PrimaryMoveTimeline)
            {
                currentGame.moves.AddLast(new JokerMove(move.WhoMoves == StoneColor.Black ? 'B' : 'W',
                                                        new JokerPoint(move.Coordinates.X, move.Coordinates.Y)));
            }

            currentGame.board = JokerExtensionMethods.OurBoardToJokerBoard(GetLastNodeOrEmptyBoard(gameInformation.GameTree).BoardState, gameInformation.GameInfo.BoardSize);

            JokerPoint point = new AlphaBetaPlayer(gameInformation.AIColor == StoneColor.Black ? 'B' : 'W').betterPlanMove(currentGame, this.TreeDepth);


            return(AIDecision.MakeMove(Move.PlaceStone(gameInformation.AIColor, new Position(point.x, point.y)),
                                       "I chose using the minimax algorithm and heuristics."));
        }
        public override AIDecision RequestMove(AiGameInformation gameInformation)
        {
            RandomPlayer internalPlayer = new RandomPlayer(gameInformation.AIColor == StoneColor.Black ? 'B' : 'W');

            char[,] board = JokerExtensionMethods.OurBoardToJokerBoard(GetLastNodeOrEmptyBoard(gameInformation.GameTree).BoardState, gameInformation.GameInfo.BoardSize);
            JokerPoint point = internalPlayer.makeMove(board, gameInformation.GameInfo.BoardSize.Width, gameInformation.GameInfo.BoardSize.Height);

            return(AIDecision.MakeMove(Move.PlaceStone(gameInformation.AIColor, new Position(point.x, point.y)),
                                       "I chose at random."));
        }
Example #3
0
        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."));
        }
Example #4
0
        public override AIDecision RequestMove(AiGameInformation gameInformation)
        {
            DateTime whenEndWaiting = DateTime.Now.AddSeconds(2);

            while (DateTime.Now < whenEndWaiting)
            {
                // Active waiting.
            }
            if (gameInformation.Node == null)
            {
                return(AIDecision.MakeMove(Move.PlaceStone(gameInformation.AIColor, new Position(0, 0)), "The board is empty so I'll just play at A1."));
            }
            for (int y = 0; y < gameInformation.GameInfo.BoardSize.Height; y++)
            {
                for (int x = 0; x < gameInformation.GameInfo.BoardSize.Width; x++)
                {
                    if (gameInformation.Node.BoardState[x, y] == StoneColor.None)
                    {
                        return(AIDecision.MakeMove(Move.PlaceStone(gameInformation.AIColor, new Position(x, y)), "I always place stones in the first point that's unoccupied."));
                    }
                }
            }
            return(AIDecision.MakeMove(Move.Pass(gameInformation.AIColor), "Board is full. This should never happen."));
        }
        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);
        }
Example #6
0
        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);
        }