Ejemplo n.º 1
0
        private void initializeBoard(CheckersGameBoard.eBoardSize i_BoardSize)
        {
            if (!CheckersGameBoard.IsBoardSizeValid((byte)i_BoardSize))
            {
                throw new ArgumentException();
            }

            m_CheckersBoard = new CheckersGameBoard(i_BoardSize);
        }
Ejemplo n.º 2
0
        private void initializeBoard(CheckersGameBoard.eBoardSize i_BoardSize)
        {
            if (!CheckersGameBoard.IsBoardSizeValid((byte)i_BoardSize))
            {
                throw new ArgumentException();
            }

            m_CheckersBoard = new CheckersGameBoard(i_BoardSize);
        }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
0
        // Initializes the game - players and board size
        public void InitializeGameLogic(
            CheckersGameBoard.eBoardSize i_BoardSize, 
            string i_Player1Name,
            string i_Player2Name,
            bool i_IsPlayer2Human)
        {
            const bool v_Human = true;

            initializeBoard(i_BoardSize);
            m_Player1 = new PlayerInfo(i_Player1Name, v_Human, ePlayerTag.First);
            m_Player2 = new PlayerInfo(i_Player2Name, i_IsPlayer2Human, ePlayerTag.Second);
            m_CurrPlayerTurn = m_Player1;
            buildPlayersPiecesList();
        }
Ejemplo n.º 6
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);
            }
Ejemplo n.º 7
0
            // Goes over possible moves of a piece and adds it into the list if it's a valid move for this part of the round
            public void AddLegalMovesToList(
                LinkedList <Move> i_LegalMovesList,
                CheckersGameBoard i_CheckersGameBoard,
                bool i_OnlyCaptureMoves)
            {
                int      maxIndexOfPossibleMove = m_King ? k_KingNumberOfPossibleMoves : k_ManNumberOfPossibleMoves;
                Position newPossiblePosition;
                bool     captureMove;

                for (int i = 0; i < maxIndexOfPossibleMove; ++i)
                {
                    newPossiblePosition = CurrPosition.AddPosition(r_PossibleMoves[i]);
                    if (isMoveValid(newPossiblePosition, i_CheckersGameBoard, out captureMove) &&
                        ((i_OnlyCaptureMoves && captureMove) || !i_OnlyCaptureMoves))
                    {
                        // Create a linkedList node and add it to the legal moves list - Source: currPosition, Dst: newLegalPosition
                        Move tempMove = new Move(m_CurrPosition, newPossiblePosition);
                        LinkedListNode <Move> tempNode = new LinkedListNode <Move>(tempMove);

                        // If we only need capture moves and it's a capture move; or if we don't nessecarily need a capture move - add to list:
                        i_LegalMovesList.AddLast(tempNode);
                    }
                }
            }
Ejemplo n.º 8
0
 public void RemovePiece(CheckersGameBoard i_CheckersBoard)
 {
     i_CheckersBoard.ErasePieceFromBoard(m_CurrPosition);
 }
Ejemplo n.º 9
0
 private void turnManToKing(CheckersGameBoard i_CheckersBoard)
 {
     m_King = true;
     i_CheckersBoard.TurnManToKingOnBoard(m_CurrPosition);
 }
Ejemplo n.º 10
0
 public void RemovePiece(CheckersGameBoard i_CheckersBoard)
 {
     i_CheckersBoard.ErasePieceFromBoard(m_CurrPosition);
 }
Ejemplo n.º 11
0
 private void turnManToKing(CheckersGameBoard i_CheckersBoard)
 {
     m_King = true;
     i_CheckersBoard.TurnManToKingOnBoard(m_CurrPosition);
 }
Ejemplo n.º 12
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);
     }
 }
Ejemplo n.º 13
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;
            }
Ejemplo n.º 14
0
 // Goes over possible moves of a piece and adds it into the list if it's a valid move for this part of the round
 public void AddLegalMovesToList(
     LinkedList<Move> i_LegalMovesList,
     CheckersGameBoard i_CheckersGameBoard,
     bool i_OnlyCaptureMoves)
 {
     int maxIndexOfPossibleMove = m_King ? k_KingNumberOfPossibleMoves : k_ManNumberOfPossibleMoves;
     Position newPossiblePosition;
     bool captureMove;
     for (int i = 0; i < maxIndexOfPossibleMove; ++i)
     {
         newPossiblePosition = CurrPosition.AddPosition(r_PossibleMoves[i]);
         if (isMoveValid(newPossiblePosition, i_CheckersGameBoard, out captureMove)
             && ((i_OnlyCaptureMoves && captureMove) || !i_OnlyCaptureMoves))                       
         {                      
                 // Create a linkedList node and add it to the legal moves list - Source: currPosition, Dst: newLegalPosition
                 Move tempMove = new Move(m_CurrPosition, newPossiblePosition);
                 LinkedListNode<Move> tempNode = new LinkedListNode<Move>(tempMove);
                
                 // If we only need capture moves and it's a capture move; or if we don't nessecarily need a capture move - add to list:
                 i_LegalMovesList.AddLast(tempNode);                         
         }
     }
 }