コード例 #1
0
 public static void ShowFullInfoBoard(IMoveResult moveResult)
 {
     DisplaySmashed(moveResult.AllSmashedFigures(), TeamColor.White);
     Console.WriteLine();
     DisplaySmashed(moveResult.AllSmashedFigures(), TeamColor.Black);
     ShowBoard(moveResult.GetBoard());
 }
コード例 #2
0
        private IMoveResult PlayerMoveHelper()
        {
            Console.WriteLine($"\n ==================== {_player} ===================== ");
            Position from        = UserInteraction.GetPositionFromUser("Position of your figure: ");
            Position destination = UserInteraction.GetPositionFromUser("Destination position: ");

            IMoveResult moveResult = _gameConductor.DoMove(from, destination);
            var         isValid    = moveResult.IsValidMove();

            while (isValid.Status != MoveResultStatus.Valid)
            {
                Console.WriteLine($"Invalid move: {isValid.Cause}");
                PlayerMoveHelper();
            }
            BoardDisplay.ShowFullInfoBoard(moveResult);

            Console.WriteLine("Select action");
            Console.WriteLine("1. Submit");
            Console.WriteLine("2. Undo");
            Console.WriteLine("3. Save");

            int choice = UserInteraction.GetNumberFromUser("", "Option not found, please try again", 1, 3);

            if (choice == 2)
            {
                Console.WriteLine(_gameConductor.Undo() ? "The move has been reversed." : "Cannot reverse move.");
                BoardDisplay.ShowFullInfoBoard(moveResult);
                return(PlayerMoveHelper());
            }
            if (choice == 3)
            {
                return(SaveGame(moveResult));
            }
            return(moveResult);
        }
コード例 #3
0
 public GridScanner(string input)
 {
     _playerInput = input;
     _moveResult  = new MoveResult {
         Status = LastMoveStatus.NoPlay
     };
 }
コード例 #4
0
 public CordinatePositionValidator(string input)
 {
     _playerInput = input;
     _moveResult  = new MoveResult {
         Status = LastMoveStatus.NoPlay
     };
 }
コード例 #5
0
 public InputParser(string input)
 {
     _playerInput = input;
     _moveResult  = new MoveResult {
         Status = LastMoveStatus.NoPlay
     };
 }
コード例 #6
0
        public IMoveResult ProcessMove(IPlayer player, int column)
        {
            if (!isGameOver)
            {
                IMoveResult result = gameBoard.Put(player, column);

                if (result.MoveResultStatus == MoveResultStatus.Success)
                {
                    IMove move = result.Moves[0];
                    if (IsWinningMove(move))
                    {
                        result.MoveResultStatus = MoveResultStatus.GameOver;
                        winningResult           = result;
                        isGameOver = true;
                    }
                    else if (move.SequenceNumber >= gameBoard.BoardSize - 1)
                    {
                        result.MoveResultStatus = MoveResultStatus.GameTie;
                    }
                }
                return(result);
            }
            else
            {
                return(winningResult);
            }
        }
コード例 #7
0
 public SkippCodeChecker(string input)
 {
     _playerInput = input;
     _moveResult  = new MoveResult {
         Status = LastMoveStatus.NoPlay
     };
 }
コード例 #8
0
 public void UpdatePieces(IMoveResult moveResult)
 {
     foreach (var lostPiece in moveResult.GetLostPieces().Where(p => p.PlayerId == Id))
     {
         ActiveSquares.Remove(moveResult.UpdatedSquares.Single(s => s.ContainedPiece == lostPiece));
         LostPieces.Add(lostPiece);
     }
 }
コード例 #9
0
 private void VerifyCheckAndDisplayMessage(IMoveResult moveResult, int playerNumber)
 {
     if (moveResult.IsCheck(_players[playerNumber].TeamColor))
     {
         Console.WriteLine("!!!");
         Console.WriteLine("Beware, your king is in check!");
         Console.WriteLine("!!!");
     }
 }
コード例 #10
0
 public ValidCordinateUpdator(string input)
 {
     _playerInput = input;
     _moveResult  = new MoveResult {
         Status = LastMoveStatus.InvalidCordinates
     };
     _moveResult.Status  = LastMoveStatus.InvalidCordinates;
     _moveResult.Message = Constants.INVALIDCORDINATES;
 }
コード例 #11
0
        public SinglePlayerModeConsoleGame()
        {
            _player          = UserInteraction.GetPlayerFromUser();
            _difficulty      = (int)UserInteraction.GetDifficultyLevelFromUser();
            _gameConductor   = new GameConductor();
            _startMoveResult = _gameConductor.Start();
            TeamColor computerColor = _player.TeamColor == TeamColor.Black ? TeamColor.White : TeamColor.Black;

            _computer = new ComputerPlayer(computerColor, _difficulty + 1, _difficulty);
        }
コード例 #12
0
        public SinglePlayerModeConsoleGame(ChessGameState state)
        {
            _player          = state.Players[0];
            _difficulty      = state.DifficultyLevel;
            _gameConductor   = new GameConductor(state);
            _startMoveResult = state.LastGameMoveResult;
            TeamColor computerColor = _player.TeamColor == TeamColor.Black ? TeamColor.White : TeamColor.Black;

            _computer = new ComputerPlayer(computerColor, _difficulty + 1, _difficulty);
        }
コード例 #13
0
        private IMoveResult NextTurn(IMoveResult moveResult, int playerNumber)
        {
            BoardDisplay.ShowFullInfoBoard(moveResult);
            VerifyCheckAndDisplayMessage(moveResult, playerNumber);

            Console.WriteLine($"\n ==================== {_players[playerNumber]} ===================== ");
            var newMoveResult = MoveHelper();

            if (newMoveResult.IsLastMoveSmash())
            {
                var smashed = newMoveResult.SmashedFigure();
                Console.WriteLine($"Player {_players[playerNumber].Name} smashed " +
                                  $"{_players[playerNumber == 0 ? 1 : 0].Name}'s {smashed.FigureType}");
コード例 #14
0
        private IMoveResult SaveGame(IMoveResult moveResult, int currentPlayer)
        {
            Console.WriteLine("Under what name save the game?");
            string file           = UserInteraction.ReadNotEmptyStringFromUser();
            var    saveRepository = SaveRepository.GetDefaultRepository();

            bool isEnded = moveResult.IsCheckMate(TeamColor.Black) || moveResult.IsCheckMate(TeamColor.White);
            var  state   = new ChessGameState(moveResult, isEnded, _players,
                                              _players[currentPlayer].TeamColor, PlayerMode.TwoPlayers, 0);

            saveRepository.Save(file + ".bin", state);
            Console.WriteLine("Game saved.");
            return(new StoppedMoveResult());
        }
コード例 #15
0
        private IMoveResult MoveHelper()
        {
            var         movePositions = GetMovePositions();
            IMoveResult moveResult    = _gameConductor.DoMove(movePositions.From, movePositions.Destination);
            var         isValid       = moveResult.IsValidMove();

            while (isValid.Status != MoveResultStatus.Valid)
            {
                Console.WriteLine($"Invalid move: {isValid.Cause}");
                return(MoveHelper());
            }
            BoardDisplay.ShowFullInfoBoard(moveResult);
            return(moveResult);
        }
コード例 #16
0
        private IMoveResult SaveGame(IMoveResult moveResult)
        {
            Console.WriteLine("Under what name save the game?");
            string file           = UserInteraction.ReadNotEmptyStringFromUser();
            var    saveRepository = SaveRepository.GetDefaultRepository();

            bool isEnded = moveResult.IsCheckMate(TeamColor.Black) || moveResult.IsCheckMate(TeamColor.White);
            var  state   = new ChessGameState(moveResult, isEnded, new [] { _player },
                                              _computer.MyTeamColor, PlayerMode.SinglePlayer, _difficulty);

            saveRepository.Save(file + ".bin", state);
            Console.WriteLine("Game saved.");
            return(new StoppedMoveResult());
        }
コード例 #17
0
        private void UserMove(IMoveResult moveResult, int userIdx)
        {
            while (!moveResult.IsCheckMate(_players[userIdx].TeamColor))
            {
                moveResult = NextTurn(moveResult, userIdx);
                if (moveResult.IsValidMove().Status == MoveResultStatus.Stopped)
                {
                    return;
                }

                userIdx = userIdx == 1 ? 0 : 1;
            }
            EndGame(userIdx);
        }
コード例 #18
0
 public ChessGameState(
     IMoveResult lastGameMoveResult,
     bool isEnded,
     Player[] players,
     TeamColor currentMovingTeam,
     PlayerMode playerMode,
     int difficultyLevel)
 {
     LastGameMoveResult = lastGameMoveResult;
     IsEnded            = isEnded;
     Players            = players;
     CurrentMovingTeam  = currentMovingTeam;
     PlayerMode         = playerMode;
     DifficultyLevel    = difficultyLevel;
 }
コード例 #19
0
        public void Start()
        {
            display.ShowStartMessage();

            bool player1Turn = true;

            while (true)
            {
                display.ShowBoard(gameEngine.BoardData);

                display.AskForMove(player1Turn ? player1 : player2);


                HumanPlayer currentPlayer = player1Turn ? player1 : player2;

                //IMoveResult result = ExecutePlayerMove(input, player1Turn ? player1 : player2);
                string move = currentPlayer.MakeMove();

                IMoveResult result = ExecutePlayerMove(move, currentPlayer);
                if (result.MoveResultStatus == Enums.MoveResultStatus.GameOver)
                {
                    display.ClearScreen();
                    display.ShowBoard(gameEngine.BoardData);
                    display.DelcareWinner(result);
                    break;
                }
                else if (result.MoveResultStatus == Enums.MoveResultStatus.GameTie)
                {
                    display.ClearScreen();
                    display.ShowBoard(gameEngine.BoardData);
                    display.DelcareTie();
                    break;
                }
                else if (result.MoveResultStatus != Enums.MoveResultStatus.InValidMove)
                {
                    player1Turn = !player1Turn;
                }
                else if (result.MoveResultStatus == Enums.MoveResultStatus.UserQuit)
                {
                    break;
                }


                display.ClearScreen();
            }

            display.WaitToQuit();
        }
コード例 #20
0
        private void PlayerMove(IMoveResult moveResult)
        {
            BoardDisplay.ShowFullInfoBoard(moveResult);
            if (moveResult.IsCheckMate(_player.TeamColor))
            {
                Console.WriteLine("\n \n \n \n");
                Console.WriteLine($"Computer wins!");
                return;
            }

            moveResult = PlayerMoveHelper();
            if (moveResult.IsValidMove().Status != MoveResultStatus.Stopped)
            {
                ComputerMove(moveResult);
            }
        }
コード例 #21
0
        private void ComputerMove(IMoveResult moveResult)
        {
            if (moveResult.IsCheckMate(_computer.MyTeamColor))
            {
                Console.WriteLine("\n \n \n \n");
                Console.WriteLine($"Player {_player.Name} wins!");
                return;
            }

            Console.WriteLine($"==================== Computer - {_computer.MyTeamColor} =====================");
            var nextMove = _computer.NextMove(moveResult.GetBoard());

            moveResult = _gameConductor.DoMove(nextMove.From, nextMove.Destination);

            Console.WriteLine($"Computer has moved the figure from the {nextMove.From} position to the {nextMove.Destination} position");
            PlayerMove(moveResult);
        }
コード例 #22
0
        private PlayerAction PlayerActionApprove(ref IMoveResult moveResult, int currentPlayer)
        {
            int choice = UserInteraction.GetNumberFromUser(
                "1. Submit\n2. Undo\n3. Save", $"Option not found. Please try again.", 1, 3);

            if (choice == 1)
            {
                return(PlayerAction.Submit);
            }

            if (choice == 2)
            {
                Console.WriteLine(_gameConductor.Undo() ? "The move has been withdrawn" : "You cannot withdraw this move");
                return(PlayerAction.Undo);
            }
            moveResult = SaveGame(moveResult, currentPlayer == 0 ? 1 : 0);
            return(PlayerAction.Save);
        }
コード例 #23
0
        public IMoveResult ExecuteMove(int humanMove)
        {
            IMoveResult moveResult = GameEngine.ProcessMove(webPlayer, humanMove);

            if (moveResult.MoveResultStatus == Common.Data.Enums.MoveResultStatus.Success)
            {
                int aiMove = aiPlyaer.GenerateMove(GameEngine, webPlayer);

                if (aiMove != -1)
                {
                    IMoveResult aiMoveResult = GameEngine.ProcessMove(aiPlyaer, aiMove);

                    moveResult.MoveResultStatus = aiMoveResult.MoveResultStatus;
                    moveResult.Moves[1]         = aiMoveResult.Moves[0];
                    moveResult.Winner           = aiMoveResult.Winner;
                }
                else
                {
                    moveResult.Winner           = webPlayer;
                    moveResult.MoveResultStatus = Enums.MoveResultStatus.GameOver;
                }
            }
            return(moveResult);
        }
コード例 #24
0
        // PUT api/<controller>/5
        public IMoveResult Put(int id, [FromBody] string value)
        {
            IMoveResult result = ConnectGameController.ProcessMove(id);

            return(result);
        }
コード例 #25
0
 public TwoPlayersModeConsoleGame()
 {
     SetUsers();
     _gameConductor = new GameConductor();
     _moveResult    = _gameConductor.Start();
 }
コード例 #26
0
 public TwoPlayersModeConsoleGame(ChessGameState state)
 {
     _players       = state.Players;
     _gameConductor = new GameConductor(state);
     _moveResult    = state.LastGameMoveResult;
 }
コード例 #27
0
        public IMoveResult ProcessMove(int column)
        {
            IMoveResult result = playerMoveController.ExecuteMove(column);

            return(result);
        }
コード例 #28
0
 public void DelcareWinner(IMoveResult result)
 {
     Console.WriteLine(string.Format("Player {0} has won the game in {1} moves!", result.Moves[0].Player.PlayerID, result.Moves[0].SequenceNumber));
 }
コード例 #29
0
 public void SetProcessAIMove(IPlayer aiPlayer, int move, IMoveResult result)
 {
     gameEngineMoq.Setup(mk => mk.ProcessMove(aiPlayer, move)).Returns(result);
 }