public static bool isDiagonal_King(PlayerMove currentMove) { bool moveIsValid = true; moveIsValid = MovementValidation.IsDiagonal(currentMove, Constants.k_FirstCoinType); if (!moveIsValid) { moveIsValid = MovementValidation.IsDiagonal(currentMove, Constants.k_SecondCoinType); } return(moveIsValid); }
public static bool isTryingToJump_King(PlayerMove i_CurrentMove) { bool isTryingToJump = true; isTryingToJump = MovementValidation.IsTryingToJump(i_CurrentMove, Convert.ToString(Constants.k_FirstCoinType)); if (!isTryingToJump) { isTryingToJump = MovementValidation.IsTryingToJump(i_CurrentMove, Convert.ToString(Constants.k_SecondCoinType)); } return(isTryingToJump); }
private void addValidMoveToArray(Square i_CurrentSquare, int i_RowToAdd, int i_ColumnToAdd, Board i_Board, ArrayList i_CurrentPlayerMoves) { PlayerMove currentMove; if (MovementValidation.movementIndexesInRange(i_CurrentSquare.ColumnIndex, i_CurrentSquare.RowIndex, i_CurrentSquare.ColumnIndex + i_ColumnToAdd, i_CurrentSquare.RowIndex + i_RowToAdd, i_Board.BoardSize)) { currentMove = new PlayerMove(i_CurrentSquare, new Square(i_CurrentSquare.ColumnIndex + i_ColumnToAdd, i_CurrentSquare.RowIndex + i_RowToAdd)); if (MovementValidation.IsLegalMovement(currentMove, i_Board).Equals(string.Empty)) { i_CurrentPlayerMoves.Add(currentMove); } } }
public PossibleMoves(Board i_Board) { m_MovementValidation = new MovementValidation(); this.m_Board = i_Board; Coin currentCoin; Coin[,] boardArray = m_Board.BoardArray; for (int i = 0; i < i_Board.BoardSize; i++) { for (int j = 0; j < i_Board.BoardSize; j++) { currentCoin = boardArray[i, j]; if (currentCoin != null) { addValidMovesToBothArrays(currentCoin, new Square(j, i)); } } } }
private bool parseUserInput(Player i_CurrentPlayer, Player i_OtherPlayer) { bool isValidMove = false; string inputMove; bool currentMoveIsJump = false; bool gameIsOver = false; bool tryingToQuit = false; bool allowedToQuit = false; bool newKingWasCreated = false; Coin currentCoin; ArrayList allPossibleJumps; m_PossibleMoves = new PossibleMoves(m_PlayingBoard); if (!this.m_CurrentPlayer.IsComputer) { inputMove = Console.ReadLine(); while (!gameIsOver && (!isValidMove || (isValidMove && tryingToQuit))) { tryingToQuit = m_InputValidation.IsTryingToQuit(inputMove); allowedToQuit = MovementValidation.IsAllowedToQuit(m_MatchInformation, i_CurrentPlayer, i_OtherPlayer); if (tryingToQuit && !allowedToQuit) { Console.WriteLine(ErrorMessageGenerator.InvalidQuitMessage()); } if (tryingToQuit && allowedToQuit) { if (quitHandler(this.m_CurrentPlayer.Name)) { gameIsOver = true; } else { tryingToQuit = false; inputMove = Console.ReadLine(); } } else { isValidMove = m_InputValidation.InputFormatIsValid(inputMove); if (isValidMove) { this.m_CurrentMove = new PlayerMove(inputMove); string errorMessage = MovementValidation.IsLegalMovement(this.m_CurrentMove, m_PlayingBoard); if (!errorMessage.Equals(string.Empty)) { isValidMove = false; Console.WriteLine(errorMessage); inputMove = Console.ReadLine(); } else { currentCoin = m_PlayingBoard.BoardArray[this.m_CurrentMove.CurrentRowIndex, this.m_CurrentMove.CurrentColIndex]; if (!MovementValidation.IsCoinBelongToPlayer(this.m_CurrentPlayer, currentCoin)) { Console.WriteLine(ErrorMessageGenerator.TryingToMoveOpponentsCoin()); inputMove = Console.ReadLine(); } } } else { Console.WriteLine(ErrorMessageGenerator.FormatErrorMessage()); inputMove = Console.ReadLine(); } } } this.m_CurrentMove = new PlayerMove(inputMove); } else { this.m_CurrentMove = RandomMovementGenerator.getRandomMove(m_PossibleMoves.SecondPlayerPossibleMoves); } Coin[,] boardArray = m_PlayingBoard.BoardArray; currentCoin = m_PlayingBoard.BoardArray[this.m_CurrentMove.CurrentRowIndex, this.m_CurrentMove.CurrentColIndex]; if (!gameIsOver) { char currentUserCoinType = currentCoin.Type; m_PlayingBoard.MoveCoinInBoard(this.m_CurrentMove); if (shouldBeKinged()) { currentCoin.IsKing = true; newKingWasCreated = true; } currentMoveIsJump = currentCoin.IsKing == false?MovementValidation.IsTryingToJump(this.m_CurrentMove, currentUserCoinType) : KingValidation.isTryingToJump_King(this.m_CurrentMove); if (currentMoveIsJump) { m_PlayingBoard.EatCoin(this.m_CurrentMove); m_PossibleMoves = new PossibleMoves(m_PlayingBoard); allPossibleJumps = m_PossibleMoves.getAllPossibleJumps(this.m_CurrentMove, currentUserCoinType); while (allPossibleJumps.Count != 0 && !newKingWasCreated) { Ex02.ConsoleUtils.Screen.Clear(); m_PlayingBoard.printBoard(); if (!this.m_CurrentPlayer.IsComputer) { Console.WriteLine(this.m_CurrentPlayer.Name + ", you can eat more. Please enter another move."); inputMove = Console.ReadLine(); isValidMove = m_InputValidation.InputFormatIsValid(inputMove); while (!isValidMove) { Console.WriteLine(this.m_CurrentPlayer.Name + ", the input is invalid. enter a good move please"); inputMove = Console.ReadLine(); isValidMove = m_InputValidation.InputFormatIsValid(inputMove); this.m_CurrentMove = new PlayerMove(inputMove); } this.m_CurrentMove = new PlayerMove(inputMove); if (!PossibleMoves.isJumpPossible(allPossibleJumps, this.m_CurrentMove)) { Console.WriteLine(this.m_CurrentPlayer.Name + ", the Move is not a valid jump. enter a good jump please"); isValidMove = false; } } else { this.m_CurrentMove = RandomMovementGenerator.getRandomMove(allPossibleJumps); } m_PlayingBoard.EatCoin(this.m_CurrentMove); m_PlayingBoard.MoveCoinInBoard(this.m_CurrentMove); m_PossibleMoves = new PossibleMoves(m_PlayingBoard); allPossibleJumps = m_PossibleMoves.getAllPossibleJumps(this.m_CurrentMove, currentUserCoinType); } } } if (shouldBeKinged()) { currentCoin.IsKing = true; newKingWasCreated = true; } Ex02.ConsoleUtils.Screen.Clear(); if (!gameIsOver) { this.m_MatchInformation = new MatchInformation(this.m_FirstPlayer, this.m_SecondPlayer, m_PlayingBoard); gameIsOver = this.m_MatchInformation.IsWinnerFound(); if (gameIsOver) { endMatch(); } else { m_PlayingBoard.printBoard(); Console.WriteLine(this.m_CurrentPlayer.Name + "'s move was: " + this.m_CurrentMove.GetFullMove()); Console.WriteLine(i_OtherPlayer.Name + "'s Turn (" + i_OtherPlayer.CoinType + ") :"); } } return(gameIsOver); }