Esempio n. 1
0
        public static byte OneRound(
            int blackTimeout         = 500,
            Algorithm blackAlgorithm = Algorithm.Mcts,
            int whiteTimeout         = 500,
            Algorithm whiteAlgorithm = Algorithm.Mcts,
            bool showLog             = true)
        {
            var state  = new State();
            var winner = Constant.Draw;

            while (!state.IsTerminal())
            {
                var isBlack   = state.Player == Constant.Black;
                var timeout   = isBlack ? blackTimeout : whiteTimeout;
                var algorithm = isBlack ? blackAlgorithm : whiteAlgorithm;
                var move      = Mcts.RunSearch(algorithm, state, timeout);

                state.NextState(move);
                winner = state.Winner();

                if (showLog)
                {
                    ShowLog(move, state);
                }
            }

            return(winner);
        }
Esempio n. 2
0
        private static ulong AiTurn(State state, int aiTimeout, Algorithm aiAlgorithm)
        {
            var move = Mcts.RunSearch(aiAlgorithm, state, aiTimeout);

            Console.Write("Ai move: " + move.ToNotation());
            Console.WriteLine(" - Runtime: {0}ms, Playout: {1}, wins: {2}%",
                              Mcts.LastRunTime,
                              Mcts.LastPlayout,
                              Mcts.LastWinPercentage);

            return(move);
        }
Esempio n. 3
0
        public (int row, int col) PerformAiMove(Algorithm algorithm)
        {
            var move = Mcts.RunSearch(algorithm, _state, _timeOut);

            _state.NextState(move); // TODO auto swapPlayer in state.NextState will effect this

            var notation = move.ToNotation();

            if (move != 0)
            {
                _recordText += notation;
            }
            Console.WriteLine("{0} - Me: {1} - Win {2}% - Playout {3}",
                              _recordText.Length / 2,
                              notation,
                              Mcts.LastWinPercentage,
                              Mcts.LastPlayout);

            return(move == 0 ? (-1, -1) : move.ToCoordinate());
        }