public static void ShowFullInfoBoard(IMoveResult moveResult) { DisplaySmashed(moveResult.AllSmashedFigures(), TeamColor.White); Console.WriteLine(); DisplaySmashed(moveResult.AllSmashedFigures(), TeamColor.Black); ShowBoard(moveResult.GetBoard()); }
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); }
public GridScanner(string input) { _playerInput = input; _moveResult = new MoveResult { Status = LastMoveStatus.NoPlay }; }
public CordinatePositionValidator(string input) { _playerInput = input; _moveResult = new MoveResult { Status = LastMoveStatus.NoPlay }; }
public InputParser(string input) { _playerInput = input; _moveResult = new MoveResult { Status = LastMoveStatus.NoPlay }; }
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); } }
public SkippCodeChecker(string input) { _playerInput = input; _moveResult = new MoveResult { Status = LastMoveStatus.NoPlay }; }
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); } }
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("!!!"); } }
public ValidCordinateUpdator(string input) { _playerInput = input; _moveResult = new MoveResult { Status = LastMoveStatus.InvalidCordinates }; _moveResult.Status = LastMoveStatus.InvalidCordinates; _moveResult.Message = Constants.INVALIDCORDINATES; }
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); }
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); }
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}");
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()); }
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); }
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()); }
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); }
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; }
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(); }
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); } }
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); }
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); }
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); }
// PUT api/<controller>/5 public IMoveResult Put(int id, [FromBody] string value) { IMoveResult result = ConnectGameController.ProcessMove(id); return(result); }
public TwoPlayersModeConsoleGame() { SetUsers(); _gameConductor = new GameConductor(); _moveResult = _gameConductor.Start(); }
public TwoPlayersModeConsoleGame(ChessGameState state) { _players = state.Players; _gameConductor = new GameConductor(state); _moveResult = state.LastGameMoveResult; }
public IMoveResult ProcessMove(int column) { IMoveResult result = playerMoveController.ExecuteMove(column); return(result); }
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)); }
public void SetProcessAIMove(IPlayer aiPlayer, int move, IMoveResult result) { gameEngineMoq.Setup(mk => mk.ProcessMove(aiPlayer, move)).Returns(result); }