示例#1
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);
        }
示例#2
0
 private void OnNextBoardstateAvailable(BoardState boardState)
 {
     System.Windows.Application.Current.Dispatcher.Invoke(() =>
     {
         CurrentBoardState = boardState;
         NewBoardStateAvailable?.Invoke(boardState);
     });
 }
示例#3
0
        private void ShowReplayState(int index)
        {
            currentReplayIndex = index;

            var nextState = allReplayStates[currentReplayIndex];

            currentBoardState = nextState;
            NewBoardStateAvailable?.Invoke(nextState);
        }
示例#4
0
        public void StopGame()
        {
            if (currentIpvBGame != null)
            {
                NewBoardStateAvailable?.Invoke(null);

                currentIpvBGame.StopGame();

                currentIpvBGame.DebugMessageAvailable   -= OnDebugMessageAvailable;
                currentIpvBGame.NextBoardstateAvailable -= OnNextBoardstateAvailable;
                currentIpvBGame.WinnerAvailable         -= OnWinnerAvailable;

                currentIpvBGame = null;
            }
        }
示例#5
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;
        }
示例#6
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;
        }