Ejemplo n.º 1
0
        private eMoveList tryDownValidMove(char[,] i_CheckersBoard, int i_CurrRow, int i_CurrCol, int i_NextRow, int i_NextCol)
        {
            eMoveList moveType = eMoveList.InvalidMove;

            if (i_NextRow - i_CurrRow <= 2 && i_CurrRow < i_NextRow && Math.Abs(i_CurrCol - i_NextCol) <= 2 &&
                Math.Abs(i_CurrCol - i_NextCol) > 0 && i_CheckersBoard[i_NextRow, i_NextCol] == ' ')
            {
                //// 1 skip for regular movement
                if (i_NextRow - i_CurrRow == 1 && Math.Abs(i_CurrCol - i_NextCol) == 1)
                {
                    moveType = eMoveList.Move;
                }
                else
                {
                    //// 2 skips for a "jump" move
                    if (i_CheckersBoard[i_CurrRow, i_CurrCol] == 'U' || i_CheckersBoard[i_CurrRow, i_CurrCol] == 'O')
                    {
                        //// right jump
                        if (i_CurrRow + 2 == i_NextRow && i_CurrCol + 2 == i_NextCol &&
                            (i_CheckersBoard[i_CurrRow + 1, i_CurrCol + 1] == 'X' || i_CheckersBoard[i_CurrRow + 1, i_CurrCol + 1] == 'K'))
                        {
                            moveType = eMoveList.JumpDownRight;
                        }
                        else if (i_CurrRow + 2 == i_NextRow && i_CurrCol - 2 == i_NextCol &&
                                 (i_CheckersBoard[i_CurrRow + 1, i_CurrCol - 1] == 'X' || i_CheckersBoard[i_CurrRow + 1, i_CurrCol - 1] == 'K'))
                        {
                            //// left jump
                            moveType = eMoveList.JumpDownLeft;
                        }
                    }
                    else if (i_CheckersBoard[i_CurrRow, i_CurrCol] == 'K')
                    {
                        //// right jump
                        if (i_CurrRow + 2 == i_NextRow && i_CurrCol + 2 == i_NextCol &&
                            (i_CheckersBoard[i_CurrRow + 1, i_CurrCol + 1] == 'O' || i_CheckersBoard[i_CurrRow + 1, i_CurrCol + 1] == 'U'))
                        {
                            moveType = eMoveList.JumpDownRight;
                        }
                        else if (i_CurrRow + 2 == i_NextRow && i_CurrCol - 2 == i_NextCol &&
                                 (i_CheckersBoard[i_CurrRow + 1, i_CurrCol - 1] == 'O' || i_CheckersBoard[i_CurrRow + 1, i_CurrCol - 1] == 'U'))
                        {
                            //// left jump
                            moveType = eMoveList.JumpDownLeft;
                        }
                    }
                }
            }

            return(moveType);
        }
Ejemplo n.º 2
0
        //// check and return valid move according to current player's checker piece
        public eMoveList ReturnMoveType(char i_PlayerPiece, char[,] i_CheckersBoard, int i_CurrRow, int i_CurrCol, int i_nextRow, int i_NextCol)
        {
            eMoveList moveType = eMoveList.InvalidMove;

            if (i_CheckersBoard[i_CurrRow, i_CurrCol] == 'X' && i_PlayerPiece == 'X')
            {
                moveType = tryUpValidMove(i_CheckersBoard, i_CurrRow, i_CurrCol, i_nextRow, i_NextCol);
            }
            else if (i_CheckersBoard[i_CurrRow, i_CurrCol] == 'O' && i_PlayerPiece == 'O')
            {
                moveType = tryDownValidMove(i_CheckersBoard, i_CurrRow, i_CurrCol, i_nextRow, i_NextCol);
            }
            else if ((i_CheckersBoard[i_CurrRow, i_CurrCol] == 'K' && i_PlayerPiece == 'X') ||
                     (i_CheckersBoard[i_CurrRow, i_CurrCol] == 'U' && i_PlayerPiece == 'O'))
            {
                eMoveList moveUp, moveDown;
                moveUp   = tryUpValidMove(i_CheckersBoard, i_CurrRow, i_CurrCol, i_nextRow, i_NextCol);
                moveDown = tryDownValidMove(i_CheckersBoard, i_CurrRow, i_CurrCol, i_nextRow, i_NextCol);

                if (moveUp == eMoveList.InvalidMove && moveDown == eMoveList.InvalidMove)
                {
                    moveType = eMoveList.InvalidMove;
                }
                else if (moveUp == eMoveList.InvalidMove)
                {
                    moveType = moveDown;
                }
                else
                {
                    moveType = moveUp;
                }
            }
            else
            {
                //// i_CheckersBoard[i_CurrRow, i_CurrCol] == ' ' (no available piece)
                moveType = eMoveList.InvalidMove;
            }

            return(moveType);
        }
Ejemplo n.º 3
0
        //// move type tells us in which direction the piece moves and current location specifies where the piece was before the move
        //// erase previous location of piece and update to new location
        public void checkersPieceMovement(char[,] i_CheckersBoard, int i_CurrRow, int i_CurrCol, int i_NextRow, int i_NextCol, char i_PlayerPiece, eMoveList i_MoveType)
        {
            i_CheckersBoard[i_NextRow, i_NextCol] = i_PlayerPiece; // player piece is the checkers piece that the user moves
            i_CheckersBoard[i_CurrRow, i_CurrCol] = ' ';

            if (i_MoveType.ToString().Contains("Jump"))
            {
                chessPieceConquer(i_CheckersBoard, i_CurrRow, i_CurrCol, i_MoveType);
            }

            //// if checkers piece reaches opponent's front line then change it to king accordingly
            changeSoldierToKing(i_CheckersBoard, i_NextRow, i_NextCol);
        }
Ejemplo n.º 4
0
 //// if jump happened then erase "conquer" opponent's checkers piece
 //// move type tells us in which direction the jump occurred and current row/col specifies were we were before the jump
 //// we then know the location of the checkers piece to erase
 private void chessPieceConquer(char[,] i_CheckersBoard, int i_CurrRow, int i_CurrCol, eMoveList i_MoveType)
 {
     if (i_MoveType == eMoveList.JumpDownLeft)
     {
         i_CheckersBoard[i_CurrRow + 1, i_CurrCol - 1] = ' ';
     }
     else if (i_MoveType == eMoveList.JumpDownRight)
     {
         i_CheckersBoard[i_CurrRow + 1, i_CurrCol + 1] = ' ';
     }
     else if (i_MoveType == eMoveList.JumpUpLeft)
     {
         i_CheckersBoard[i_CurrRow - 1, i_CurrCol - 1] = ' ';
     }
     else if (i_MoveType == eMoveList.JumpUpRight)
     {
         i_CheckersBoard[i_CurrRow - 1, i_CurrCol + 1] = ' ';
     }
 }