示例#1
0
 private void OnWinnerAvailable(Player player, WinningReason winningReason, Move invalidMove)
 {
     System.Windows.Application.Current.Dispatcher.Invoke(() =>
     {
         WinnerAvailable?.Invoke(player, winningReason, invalidMove);
     });
 }
示例#2
0
        private bool DoHumanMove()
        {
            var nextHumanMove = PickHumanMove();

            if (nextHumanMove == null)
            {
                return(false);
            }

            if (!GameAnalysis.IsMoveLegal(currentBoardState, nextHumanMove))
            {
                WinnerAvailable?.Invoke(computerPlayer, WinningReason.InvalidMove, nextHumanMove);
                return(false);
            }

            currentBoardState = currentBoardState.ApplyMove(nextHumanMove);
            NewBoardStateAvailable?.Invoke(currentBoardState);

            if (nextHumanMove is Capitulation)
            {
                WinnerAvailable?.Invoke(computerPlayer, WinningReason.Capitulation, null);
            }

            var winner = GameAnalysis.CheckWinningCondition(currentBoardState);

            if (winner != null)
            {
                WinnerAvailable?.Invoke(winner, WinningReason.RegularQuoridorWin, null);
                return(false);
            }

            return(true);
        }
示例#3
0
        private Move GetTopPlayerBotMove()
        {
            topPlayerBotMoves.Clear();
            topPlayerBotTimer.Change(gameConstraints.MaximalComputingTimePerMove, TimeSpan.Zero);
            topPlayerBot.DoMove(currentBoardState);

            Move nextMove;

            while ((nextMove = topPlayerBotMoves.TimeoutTake()) == null)
            {
                if (stopRunning)
                {
                    return(null);
                }
            }

            if (nextMove is BotsTimeOut)
            {
                WinnerAvailable?.Invoke(currentBoardState.BottomPlayer.Player, WinningReason.ExceedanceOfThoughtTime);
                return(null);
            }

            return(nextMove);
        }
示例#4
0
 private void OnWinnerAvailable(Player player, WinningReason winningReason, Move invalidMove)
 {
     StopGame();
     WinnerAvailable?.Invoke(player, winningReason, invalidMove);
 }
示例#5
0
 private void OnWinnerAvailable(Player player, WinningReason winningReason)
 {
     StopGame();
     WinnerAvailable?.Invoke(player, winningReason);
 }
示例#6
0
        public void Run()
        {
            IsRunning = true;

            NewBoardStateAvailable?.Invoke(currentBoardState);

            var moveCounter = 0;

            while (!stopRunning)
            {
                if (moveCounter >= gameConstraints.MaximalMovesPerPlayer)
                {
                    WinnerAvailable?.Invoke(currentBoardState.TopPlayer.Player, WinningReason.ExceedanceOfMaxMoves);
                }

                var nextBottomPlayerBotMove = GetBottomPlayerBotMove();

                if (nextBottomPlayerBotMove == null)
                {
                    break;
                }

                if (!GameAnalysis.IsMoveLegal(currentBoardState, nextBottomPlayerBotMove))
                {
                    WinnerAvailable?.Invoke(currentBoardState.TopPlayer.Player, WinningReason.InvalidMove);
                    break;
                }

                currentBoardState = currentBoardState.ApplyMove(nextBottomPlayerBotMove);
                NewBoardStateAvailable?.Invoke(currentBoardState);

                if (nextBottomPlayerBotMove is Capitulation)
                {
                    WinnerAvailable?.Invoke(currentBoardState.TopPlayer.Player, WinningReason.Capitulation);
                }

                var winner = GameAnalysis.CheckWinningCondition(currentBoardState);
                if (winner != null)
                {
                    WinnerAvailable?.Invoke(winner, WinningReason.RegularQuoridorWin);
                    break;
                }

                var nextTopPlayerBotMove = GetTopPlayerBotMove();

                if (nextTopPlayerBotMove == null)
                {
                    break;
                }

                if (!GameAnalysis.IsMoveLegal(currentBoardState, nextTopPlayerBotMove))
                {
                    WinnerAvailable?.Invoke(currentBoardState.BottomPlayer.Player, WinningReason.InvalidMove);
                    break;
                }

                currentBoardState = currentBoardState.ApplyMove(nextTopPlayerBotMove);
                NewBoardStateAvailable?.Invoke(currentBoardState);

                if (nextTopPlayerBotMove is Capitulation)
                {
                    WinnerAvailable?.Invoke(currentBoardState.BottomPlayer.Player, WinningReason.Capitulation);
                }

                var winner2 = GameAnalysis.CheckWinningCondition(currentBoardState);
                if (winner2 != null)
                {
                    WinnerAvailable?.Invoke(winner2, WinningReason.RegularQuoridorWin);
                    break;
                }

                moveCounter++;
            }

            IsRunning = false;

            bottomPlayerBot.NextMoveAvailable -= OnNextBottomPlayerBotMoveAvailable;
            topPlayerBot.NextMoveAvailable    -= OnNextTopPlayerBotMoveAvailable;
        }
示例#7
0
        public void Run()
        {
            IsRunning = true;

            computerPlayer = new Player(PlayerType.TopPlayer, botName);
            humanPlayer    = new Player(PlayerType.BottomPlayer);

            bot.Init(computerPlayer.PlayerType, gameConstraints);

            currentBoardState = BoardStateTransition.CreateInitialBoadState(computerPlayer, humanPlayer);
            NewBoardStateAvailable?.Invoke(currentBoardState);

            var moveCounter = 0;

            if (initialProgress != null)
            {
                var moves = ParseProgressText.FromFileText(initialProgress)
                            .Select(MoveParser.GetMove);

                foreach (var move in moves)
                {
                    currentBoardState = currentBoardState.ApplyMove(move);
                    NewBoardStateAvailable?.Invoke(currentBoardState);
                }

                if (moves.Count() % 2 == 1)
                {
                    var succeedGame = DoBotMove();

                    if (!succeedGame)
                    {
                        IsRunning              = false;
                        bot.NextMoveAvailable -= OnNextBotMoveAvailable;
                        return;
                    }
                }

                moveCounter = (int)Math.Ceiling(moves.Count() / 2.0);
            }

            while (!stopRunning)
            {
                if (moveCounter >= gameConstraints.MaximalMovesPerPlayer)
                {
                    WinnerAvailable?.Invoke(computerPlayer, WinningReason.ExceedanceOfMaxMoves, null);
                }

                bool succeedGame;

                succeedGame = DoHumanMove();
                if (!succeedGame)
                {
                    break;
                }


                succeedGame = DoBotMove();
                if (!succeedGame)
                {
                    break;
                }

                moveCounter++;
            }

            IsRunning              = false;
            bot.NextMoveAvailable -= OnNextBotMoveAvailable;
        }