Пример #1
0
 private void makeEatMove(CheckersPiece i_Piece)
 {
     m_IsPieceBecomeKing = isPieceGoingToBecomeKing(i_Piece);
     r_GameBoard.RemoveOpponentPiece(r_CurremtRow, r_CurrentColumn, r_TargetRow, r_TargetColumn, r_Opponent);
     r_GameBoard.UpdatePieceInBoard(r_Player, r_CurremtRow, r_CurrentColumn, r_TargetRow, r_TargetColumn);
     updatePossibleEatMoves(i_Piece);
 }
Пример #2
0
        internal bool IsPreformedMove()
        {
            CheckersPiece pieceToMove = r_GameBoard.GetCell(r_CurremtRow, r_CurrentColumn).Piece;
            bool          isLegalMove = false;

            m_IsNeedToEatAgain = false;

            UpdateAllPlayerPieces(r_Player);

            bool isValidPlayerPiece = isValidPiece(pieceToMove);

            if (isValidPlayerPiece && IsPlayerMustEat(r_Player))
            {
                if (isLegalMove = isMoveInList(pieceToMove.PossibleEatMoves))
                {
                    makeEatMove(pieceToMove);
                    m_IsNeedToEatAgain = pieceToMove.PossibleEatMoves.Any();
                }
            }
            else if (isValidPlayerPiece && isSimpleMoveLeft() && !m_IsNeedToEatAgain)
            {
                if (isLegalMove = isMoveInList(pieceToMove.PossibleSimpleMoves))
                {
                    makeSimpleMove(pieceToMove);
                }
            }

            updateEndOfMove();

            return(isLegalMove);
        }
Пример #3
0
        private bool isMoveInBounds(int i_MoveType, CheckersPiece i_Piece, int i_TargetRow, int i_TargetColumn)
        {
            int currentRow    = i_Piece.Location[0];
            int currentColumn = i_Piece.Location[1];

            return(isValidRowMove(i_MoveType, currentRow, i_TargetRow, i_Piece.PieceType) && isValidColumnMove(i_MoveType, currentColumn, i_TargetColumn));
        }
Пример #4
0
        private void updatePossibleEatMoves(CheckersPiece i_Piece)
        {
            i_Piece.PossibleEatMoves.Clear();
            int negativMove  = -1 * k_EatMove;
            int positiveMove = k_EatMove;

            if (isValidMove(i_Piece, positiveMove, positiveMove, k_EatMove) && isEatOverOpponent(i_Piece, positiveMove, positiveMove))
            {
                addMove(i_Piece, positiveMove, positiveMove, k_EatMove);
            }

            if (isValidMove(i_Piece, negativMove, negativMove, k_EatMove) && isEatOverOpponent(i_Piece, negativMove, negativMove))
            {
                addMove(i_Piece, negativMove, negativMove, k_EatMove);
            }

            if (isValidMove(i_Piece, positiveMove, negativMove, k_EatMove) && isEatOverOpponent(i_Piece, positiveMove, negativMove))
            {
                addMove(i_Piece, positiveMove, negativMove, k_EatMove);
            }

            if (isValidMove(i_Piece, negativMove, positiveMove, k_EatMove) && isEatOverOpponent(i_Piece, negativMove, positiveMove))
            {
                addMove(i_Piece, negativMove, positiveMove, k_EatMove);
            }
        }
Пример #5
0
        internal void UpdatePossibleSimpleMoves(CheckersPiece i_Piece)
        {
            i_Piece.PossibleSimpleMoves.Clear();
            int moveToNegativSide  = -1 * k_SimpleMove;
            int moveToPositiveSide = k_SimpleMove;

            if (isValidMove(i_Piece, moveToPositiveSide, moveToPositiveSide, k_SimpleMove))
            {
                addMove(i_Piece, moveToPositiveSide, moveToPositiveSide, k_SimpleMove);
            }

            if (isValidMove(i_Piece, moveToNegativSide, moveToNegativSide, k_SimpleMove))
            {
                addMove(i_Piece, moveToNegativSide, moveToNegativSide, k_SimpleMove);
            }

            if (isValidMove(i_Piece, moveToPositiveSide, moveToNegativSide, k_SimpleMove))
            {
                addMove(i_Piece, moveToPositiveSide, moveToNegativSide, k_SimpleMove);
            }

            if (isValidMove(i_Piece, moveToNegativSide, moveToPositiveSide, k_SimpleMove))
            {
                addMove(i_Piece, moveToNegativSide, moveToPositiveSide, k_SimpleMove);
            }
        }
Пример #6
0
        private bool isValidMove(CheckersPiece i_Piece, int i_RowTargetMove, int i_ColumnTargetMove, int i_MoveType)
        {
            int  targetRow    = i_Piece.Location[0] + i_RowTargetMove;
            int  targetColumn = i_Piece.Location[1] + i_ColumnTargetMove;
            bool isValidMove  = isMoveInBounderies(targetRow, targetColumn) && isMoveInBounds(i_MoveType, i_Piece, targetRow, targetColumn);

            return(isValidMove && isTargetEmpty(targetRow, targetColumn));
        }
Пример #7
0
        private bool isPieceGoingToBecomeKing(CheckersPiece i_Piece)
        {
            bool isBecomingKing;

            if (r_Player.PawnType.Equals(CheckersPiece.ePieceType.X))
            {
                isBecomingKing = i_Piece.PieceType.Equals(CheckersPiece.ePieceType.X) && (r_TargetRow == 0);
            }
            else
            {
                isBecomingKing = i_Piece.PieceType.Equals(CheckersPiece.ePieceType.O) && (r_TargetRow == r_GameBoard.BoardSize - 1);
            }

            return(isBecomingKing);
        }
Пример #8
0
        private bool isEatOverOpponent(CheckersPiece i_Piece, int i_RowMove, int i_ColumnMove)
        {
            int  rowToCheck        = i_Piece.Location[0] + (i_RowMove / 2);
            int  columnToCheck     = i_Piece.Location[1] + (i_ColumnMove / 2);
            bool isCellEmpty       = r_GameBoard.GetCell(rowToCheck, columnToCheck).Piece != null;
            bool isEatOverOpponent = false;

            if (isCellEmpty)
            {
                isEatOverOpponent = r_GameBoard.GetCell(rowToCheck, columnToCheck).Piece.PieceType == r_Opponent.PawnType;
                isEatOverOpponent = isEatOverOpponent || r_GameBoard.GetCell(rowToCheck, columnToCheck).Piece.PieceType == r_Opponent.KingType;
            }

            return(isEatOverOpponent);
        }
Пример #9
0
        private void addMove(CheckersPiece i_Piece, int i_RowMove, int i_ColumnMove, int i_MoveType)
        {
            int[] newMove = new int[2];
            newMove[0] = i_Piece.Location[0] + i_RowMove;
            newMove[1] = i_Piece.Location[1] + i_ColumnMove;

            if (i_MoveType == k_SimpleMove)
            {
                i_Piece.PossibleSimpleMoves.Add(newMove);
            }
            else
            {
                i_Piece.PossibleEatMoves.Add(newMove);
            }
        }
Пример #10
0
 private void makeSimpleMove(CheckersPiece i_Piece)
 {
     r_GameBoard.UpdatePieceInBoard(r_Player, r_CurremtRow, r_CurrentColumn, r_TargetRow, r_TargetColumn);
 }
Пример #11
0
        private bool isValidPiece(CheckersPiece i_Piece)
        {
            bool isValidPiece = (i_Piece != null) ? (i_Piece.PieceType.Equals(r_Player.PawnType) || i_Piece.PieceType.Equals(r_Player.KingType)) : false;

            return(isValidPiece);
        }