Exemplo n.º 1
0
        public static string IsLegalMovement(PlayerMove currentMove, Board i_Board)
        {
            bool   isValidMovement = true;
            Square sourceSquare;
            Square destinationSquare;
            char   currentUserCoinType;
            char   otherUserCoinType;
            bool   tryingToJump;

            Coin[,] boardArray = i_Board.BoardArray;
            sourceSquare       = currentMove.CurrentSquare;
            destinationSquare  = currentMove.NextSquare;
            string errorMessage = string.Empty;

            if (!movementIndexesInRange(currentMove, i_Board.BoardSize))
            {
                isValidMovement = false;
                errorMessage    = ErrorMessageGenerator.OutOfBoundMessage();
            }
            else
            {
                Coin currentCoin = boardArray[sourceSquare.RowIndex, sourceSquare.ColumnIndex];
                if (i_Board.IsEmptyAtSquare(sourceSquare))
                {
                    isValidMovement = false;
                    errorMessage    = ErrorMessageGenerator.NoCoinToMoveMessage();
                }

                if (isValidMovement)
                {
                    currentUserCoinType = currentCoin.Type;
                    otherUserCoinType   = currentUserCoinType == Constants.k_FirstCoinType ? Constants.k_SecondCoinType : Constants.k_FirstCoinType;

                    if (!currentCoin.Type.Equals(currentUserCoinType))
                    {
                        isValidMovement = false;
                        errorMessage    = ErrorMessageGenerator.NoCoinToMoveMessage();
                    }
                    else if (currentCoin.IsKing)
                    {
                        tryingToJump = KingValidation.isTryingToJump_King(currentMove);
                        if (tryingToJump)
                        {
                            isValidMovement = IsValidJump(currentMove, otherUserCoinType, i_Board);
                            if (!isValidMovement)
                            {
                                errorMessage = ErrorMessageGenerator.InvalidJumpMessage();
                            }
                        }
                        else
                        {
                            if (!i_Board.IsEmptyAtSquare(destinationSquare))
                            {
                                isValidMovement = false;
                                errorMessage    = ErrorMessageGenerator.SquareIsBlockedMessage();
                            }
                            else
                            {
                                isValidMovement = KingValidation.isDiagonal_King(currentMove);
                                if (!isValidMovement)
                                {
                                    errorMessage = ErrorMessageGenerator.NotDiagonalMessage();
                                }
                            }
                        }
                    }
                    else if (IsTryingToJump(currentMove, currentUserCoinType))
                    {
                        if (!IsValidJump(currentMove, otherUserCoinType, i_Board))
                        {
                            errorMessage = ErrorMessageGenerator.InvalidJumpMessage();
                        }
                    }
                    else if (!i_Board.IsEmptyAtSquare(destinationSquare))
                    {
                        isValidMovement = false;
                        errorMessage    = ErrorMessageGenerator.SquareIsBlockedMessage();
                    }
                    else if (!IsDiagonal(currentMove, currentUserCoinType))
                    {
                        isValidMovement = false;
                        errorMessage    = ErrorMessageGenerator.NotDiagonalMessage();
                    }
                }
            }

            return(errorMessage);
        }
Exemplo n.º 2
0
 public static bool IsCoinBelongToPlayer(Player i_Player, Coin i_Coin)
 {
     return(i_Player.CoinType.Equals(i_Coin.Type));
 }