Пример #1
0
        public CellChangedEventArgs(Position i_CellPosition, CheckersGameBoard.eCellMode i_CellMode)
        {
            if (!Enum.IsDefined(typeof(CheckersGameBoard.eCellMode), i_CellMode))
            {
                throw new ArgumentOutOfRangeException("i_CellMode");
            }

            CellPosition = i_CellPosition;
            NewCellMode = i_CellMode;
        }
Пример #2
0
 public bool IsPositionOutOfBounds(Position i_PositionToExamine )
 {
     return i_PositionToExamine.Row >= (int)r_BoardSize || i_PositionToExamine.Row < 0
            || i_PositionToExamine.Col >= (int)r_BoardSize || i_PositionToExamine.Col < 0;
 }
Пример #3
0
 public void TurnManToKingOnBoard(Position i_CurrPiecePosition)
 {
     eCellMode currentMode = r_BoardMatrix[i_CurrPiecePosition.Row, i_CurrPiecePosition.Col];
     if (currentMode == eCellMode.Player1Piece)
     {
         r_BoardMatrix[i_CurrPiecePosition.Row, i_CurrPiecePosition.Col] = eCellMode.Player1King;
     }
     else
     { // currentMode == eCellMode.Player2Piece                
         r_BoardMatrix[i_CurrPiecePosition.Row, i_CurrPiecePosition.Col] = eCellMode.Player2King;
     }
 }
Пример #4
0
 // Used to check if the player should become a king
 public bool IsPieceOnEdgeOfBoard(Position i_CurrPiecePosition)
 {
     return i_CurrPiecePosition.Row == (int)r_BoardSize - 1 || i_CurrPiecePosition.Row == 0;
 }
Пример #5
0
 public void ErasePieceFromBoard(Position i_CellToErasePosition)
 {
     r_BoardMatrix[i_CellToErasePosition.Row, i_CellToErasePosition.Col] = eCellMode.Empty;
 }
Пример #6
0
 public void MovePieceOnBoard(Position i_Source, Position i_Destination)
 {
     r_BoardMatrix[i_Destination.Row, i_Destination.Col] = r_BoardMatrix[i_Source.Row, i_Source.Col];
     r_BoardMatrix[i_Source.Row, i_Source.Col] = eCellMode.Empty;
 }
Пример #7
0
 // Finds the piece in the list using given position coordinates
 private Piece getPieceByPosition(PlayerInfo i_Player, Position i_Position)
 {
     List<Piece> playerPieceList = getPlayerPiecesList(i_Player);
     Piece wantedPiece = null;
     foreach (Piece currentPiece in playerPieceList)
     {
         if (currentPiece.CurrPosition.Equals(i_Position))
         {
             wantedPiece = currentPiece;
             break;
         }
     }
     
     return wantedPiece;
 }
Пример #8
0
 // Removes the piece from the current game
 private void removePieceFromPosition(PlayerInfo i_CurrPlayerTurn, Position i_PiecePosition)
 {
     List<Piece> playerPieceList = getPlayerPiecesList(i_CurrPlayerTurn);
     Piece pieceToRemove = getPieceByPosition(i_CurrPlayerTurn, i_PiecePosition);
     pieceToRemove.RemovePiece(m_CheckersBoard);
     playerPieceList.Remove(pieceToRemove);
 }
Пример #9
0
        // check if for detenation position represent a capture move, if so- the output parameter update the captured piece Position
        private bool captureMove(Piece i_SrcPiece, Position i_LegalDstPosition, out Position i_CapturePosition)
        {
            i_CapturePosition = new Position(                           // Position will be relevant only if i_Capture_Position is true
            (i_SrcPiece.CurrPosition.Row + i_LegalDstPosition.Row) / 2,
            (i_SrcPiece.CurrPosition.Col + i_LegalDstPosition.Col) / 2);

            return Math.Abs(i_SrcPiece.CurrPosition.Row - i_LegalDstPosition.Row) == 2;
        }
Пример #10
0
 public void MovePiece(Position i_DstPosition, CheckersGameBoard i_CheckersBoard)
 {
     i_CheckersBoard.MovePieceOnBoard(m_CurrPosition, i_DstPosition);
     CurrPosition = i_DstPosition;
     if (i_CheckersBoard.IsPieceOnEdgeOfBoard(m_CurrPosition) && !m_King)
     {
         turnManToKing(i_CheckersBoard);
     }
 }
Пример #11
0
            public Position? GetPossibleCapturePositionIfExists(Position i_NextPosition)
            {
                Position? returnedValue = null;
                if (Math.Abs(m_CurrPosition.Row - i_NextPosition.Row) == 2)
                {
                    returnedValue = new Position(
                        (m_CurrPosition.Row + i_NextPosition.Row) / 2,
                        (m_CurrPosition.Col + i_NextPosition.Col) / 2);
                }

                return returnedValue;
            }
Пример #12
0
            // Piece checks if a suggested move is valid
            private bool isMoveValid(Position i_PositionToExamine, CheckersGameBoard i_CheckersGameBoard, out bool o_IsMoveCapture)
            {
                o_IsMoveCapture = false;
                bool moveValid = !i_CheckersGameBoard.IsPositionOutOfBounds(i_PositionToExamine);
                if (moveValid)
                {
                    moveValid &= i_CheckersGameBoard[i_PositionToExamine.Row, i_PositionToExamine.Col] == CheckersGameBoard.eCellMode.Empty;
                    Position? possibleCapturePosition = GetPossibleCapturePositionIfExists(i_PositionToExamine);

                    // If the new position is 2 cells far from the current one
                    if(possibleCapturePosition != null)
                    {
                        int middleRow = possibleCapturePosition.Value.Row;
                        int middleCol = possibleCapturePosition.Value.Col;

                        if (r_Owner == ePlayerTag.First)
                        {
                            moveValid &= i_CheckersGameBoard[middleRow, middleCol]
                                         == CheckersGameBoard.eCellMode.Player2Piece
                                         || i_CheckersGameBoard[middleRow, middleCol]
                                         == CheckersGameBoard.eCellMode.Player2King;
                        }
                        else
                        {
                            // if(r_Owner == ePlayerTag.Second)
                            moveValid &= i_CheckersGameBoard[middleRow, middleCol]
                                         == CheckersGameBoard.eCellMode.Player1Piece
                                         || i_CheckersGameBoard[middleRow, middleCol]
                                         == CheckersGameBoard.eCellMode.Player1King;
                        }

                        // If the move is valid and distance is 2 cells - it's a capture move
                        o_IsMoveCapture = moveValid;
                    }
                }

                return moveValid;
            }