Beispiel #1
0
 private void printMassageInCaseTwoPlayersCanNotMoveInTheGame(OtheloGameBoard i_OtheloGameBoard)
 {
     i_OtheloGameBoard.PrintOtheloGameBoard();
     Console.WriteLine();
     Console.WriteLine("**********No one from the players can continue to play!**********");
     Console.WriteLine();
 }
Beispiel #2
0
        private bool checkEightPossibleSidesAroundCellOnBoard(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, int i_RowIndex, int i_ColumnIndex)
        {
            const bool v_GoodSideToBlockTheOpponent          = true;
            bool       atLeastOneOfTheSidesIsPossibleToBlock = true;
            int        atLeastOneOfTheSidesIsOk = 0;

            // By 'rowIndexToMoveAround' and 'columnIndexToMoveAround' indexes you can check all the eight sides around you
            for (int rowIndexToMoveAround = -1; rowIndexToMoveAround <= 1; rowIndexToMoveAround++)
            {
                for (int columnIndexToMoveAround = -1; columnIndexToMoveAround <= 1; columnIndexToMoveAround++)
                {
                    // Irellevent to check my position - only check the cells around me
                    if (rowIndexToMoveAround == 0 && columnIndexToMoveAround == 0)
                    {
                        continue;
                    }

                    if (checkNextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType(i_OtheloGameBoard, i_CurrentSignalTurn, i_RowIndex, i_ColumnIndex, rowIndexToMoveAround, columnIndexToMoveAround) == v_GoodSideToBlockTheOpponent)
                    {
                        atLeastOneOfTheSidesIsOk = 1;
                        rowIndexToMoveAround     = 2;
                        break;
                    }
                }
            }

            // No one of the eight sides is possible
            if (atLeastOneOfTheSidesIsOk == 0)
            {
                atLeastOneOfTheSidesIsPossibleToBlock = !atLeastOneOfTheSidesIsPossibleToBlock;
            }

            return(atLeastOneOfTheSidesIsPossibleToBlock);
        }
Beispiel #3
0
        private bool recursiveMethodToFlipOpponentSignalsYouBlockInSpecificRow(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, int i_RowIndex, int i_ColumnIndex, int i_RowIndexToMoveAround, int i_ColumnIndexToMoveAround)
        {
            const bool v_StayInBoardBordersIfYouMoveOneSide       = true;
            const bool v_FlipOpponentSignalsYouBlockInSpecificRow = true;
            const char k_EmptyCellInGameBoard = '\0';

            if (checkYouStayInBoardBordersIfYouMoveOneSideNextToPosition(i_OtheloGameBoard, i_CurrentSignalTurn, i_RowIndex, i_ColumnIndex, i_RowIndexToMoveAround, i_ColumnIndexToMoveAround) == !v_StayInBoardBordersIfYouMoveOneSide)
            {
                return(!v_FlipOpponentSignalsYouBlockInSpecificRow);
            }

            // If we arrive to empty cell before we have a signal type like me on board - so we can't block this row
            if (i_OtheloGameBoard.OtheloGameBoardMatrix[i_RowIndex + i_RowIndexToMoveAround, i_ColumnIndex + i_ColumnIndexToMoveAround] == k_EmptyCellInGameBoard)
            {
                return(!v_FlipOpponentSignalsYouBlockInSpecificRow);
            }

            // If we arrive to cell with same signal type - so it is the end cell of blocking this row
            if (i_OtheloGameBoard.OtheloGameBoardMatrix[i_RowIndex + i_RowIndexToMoveAround, i_ColumnIndex + i_ColumnIndexToMoveAround] == i_CurrentSignalTurn)
            {
                return(v_FlipOpponentSignalsYouBlockInSpecificRow);
            }

            // Recursive calling
            if (recursiveMethodToFlipOpponentSignalsYouBlockInSpecificRow(i_OtheloGameBoard, i_CurrentSignalTurn, i_RowIndex + i_RowIndexToMoveAround, i_ColumnIndex + i_ColumnIndexToMoveAround, i_RowIndexToMoveAround, i_ColumnIndexToMoveAround) == v_FlipOpponentSignalsYouBlockInSpecificRow)
            {
                // Flip the signal cell on board
                i_OtheloGameBoard.OtheloGameBoardMatrix[i_RowIndex + i_RowIndexToMoveAround, i_ColumnIndex + i_ColumnIndexToMoveAround] = i_CurrentSignalTurn;
                return(v_FlipOpponentSignalsYouBlockInSpecificRow);
            }
            else
            {
                return(!v_FlipOpponentSignalsYouBlockInSpecificRow);
            }
        }
Beispiel #4
0
        private void chooseTheSizeOfTheOtheloBoardGame(out OtheloGameBoard o_OtheloGameBoard)
        {
            string     strOtheloBoardDimension;
            int        intOtheloBoardDimension;
            const int  k_FirstCorrectBoardDimensionValue  = 6;
            const int  k_SecondCorrectBoardDimensionValue = 8;
            const bool v_SuccessParseStringToInt          = true;
            const bool v_UserInsertCorrectValue           = true;

            Console.WriteLine(@"
                                please choose the board dimension - you can choose 6x6 or 8x8 dimensions :
                                To 6x6 dimension insert '6'
                                To 8x8 dimension insert '8'");
            strOtheloBoardDimension = Console.ReadLine();

            checkIfUserInputWantToExitFromGame(strOtheloBoardDimension);

            while (int.TryParse(strOtheloBoardDimension, out intOtheloBoardDimension) != v_SuccessParseStringToInt ||
                   checkUserInsertCorrectValue(intOtheloBoardDimension, k_FirstCorrectBoardDimensionValue, k_SecondCorrectBoardDimensionValue) != v_UserInsertCorrectValue)
            {
                Console.WriteLine(@"
                                   Illegal bord dimension! Only 6x6 or 8x8 is possible !!! 
                                   To 6x6 dimension insert '6'
                                   To 8x8 dimension insert '8'
                                   Please enter your choise again :");

                strOtheloBoardDimension = Console.ReadLine();

                checkIfUserInputWantToExitFromGame(strOtheloBoardDimension);
            }

            o_OtheloGameBoard = new OtheloGameBoard(intOtheloBoardDimension);
        }
Beispiel #5
0
        public void PutSignalInTheRequiredUserPositionOnBoard(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, int[] io_PositionFromUserInTheBoard)
        {
            int rowInputIndex = io_PositionFromUserInTheBoard[0], columnInputIndex = io_PositionFromUserInTheBoard[1];

            // Put the signal in the game board
            i_OtheloGameBoard.OtheloGameBoardMatrix[rowInputIndex, columnInputIndex] = i_CurrentSignalTurn;

            changeAllTheOpponentSignalsYouBlockOnBoard(i_OtheloGameBoard, i_CurrentSignalTurn, rowInputIndex, columnInputIndex);
        }
Beispiel #6
0
 private void zeroTheLegalMovesMatrix(OtheloGameBoard i_OtheloGameBoard)
 {
     for (int i = 0; i < i_OtheloGameBoard.OtheloGameBoardMatrixDimension; i++)
     {
         for (int j = 0; j < i_OtheloGameBoard.OtheloGameBoardMatrixDimension; j++)
         {
             this.m_AllCurrentLegalMovesMatrix[i, j] = '\0';
         }
     }
 }
Beispiel #7
0
 private void fillCurrentLegalMovesMatrix(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, OtheloGamePlayer i_SecondPlayer)
 {
     for (int i = 0; i < i_OtheloGameBoard.OtheloGameBoardMatrixDimension; i++)
     {
         for (int j = 0; j < i_OtheloGameBoard.OtheloGameBoardMatrixDimension; j++)
         {
             fillSpecificCellInLegalMovesMatrix(i_OtheloGameBoard, i_CurrentSignalTurn, i, j, i_SecondPlayer);
         }
     }
 }
Beispiel #8
0
        public bool CheckTheUserChoiseIsLegal(char i_CurrentSignalTurn, OtheloGameBoard i_OtheloGameBoard, int[] io_PositionFromUserInTheBoard)
        {
            int  rowInputIndex = io_PositionFromUserInTheBoard[0], columnInputIndex = io_PositionFromUserInTheBoard[1];
            bool userPositinChoiseIsLegal = true;

            if (m_AllCurrentLegalMovesMatrix[rowInputIndex, columnInputIndex] != i_CurrentSignalTurn)
            {
                userPositinChoiseIsLegal = !userPositinChoiseIsLegal;
            }

            return(userPositinChoiseIsLegal);
        }
Beispiel #9
0
        private bool checkTheTwoPlayersCanNotMoveInTheGame(OtheloGameBoard i_OtheloGameBoard, OtheloGamePlayer i_SecondPlayer)
        {
            bool       twoPlayersCanNotMoveInTheGame    = true;
            const bool v_FirstPlayerCanContinueTheGame  = true;
            const bool v_SecondPlayerCanContinueTheGame = true;

            if (s_OtheloGamePolicy.CheckIfCurrentPlayerHasOptionToContinueThisTurn(k_SecondPlayerSignal, i_OtheloGameBoard, i_SecondPlayer) == v_FirstPlayerCanContinueTheGame ||
                s_OtheloGamePolicy.CheckIfCurrentPlayerHasOptionToContinueThisTurn(k_FirstPlayerSignal, i_OtheloGameBoard, i_SecondPlayer) == v_SecondPlayerCanContinueTheGame)
            {
                twoPlayersCanNotMoveInTheGame = !twoPlayersCanNotMoveInTheGame;
            }

            return(twoPlayersCanNotMoveInTheGame);
        }
Beispiel #10
0
        private bool checkYouStayInBoardBordersIfYouMoveOneSideNextToPosition(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, int i_RowIndex, int i_ColumnIndex, int i_RowIndexToMoveAround, int i_ColumnIndexToMoveAround)
        {
            bool stayInBoardBordersIfYouMoveOneSide = true;

            if (i_RowIndex + i_RowIndexToMoveAround < 0 || i_RowIndex + i_RowIndexToMoveAround > i_OtheloGameBoard.OtheloGameBoardMatrixDimension - 1)
            { // Out of rows bounds
                stayInBoardBordersIfYouMoveOneSide = !stayInBoardBordersIfYouMoveOneSide;
            }
            else if (i_ColumnIndex + i_ColumnIndexToMoveAround < 0 || i_ColumnIndex + i_ColumnIndexToMoveAround > i_OtheloGameBoard.OtheloGameBoardMatrixDimension - 1)
            { // Out of columns bounds
                stayInBoardBordersIfYouMoveOneSide = !stayInBoardBordersIfYouMoveOneSide;
            }

            return(stayInBoardBordersIfYouMoveOneSide);
        }
Beispiel #11
0
        private void currentPlayerCanContinueToPlayThisTurn(OtheloGameBoard i_OtheloGameBoard, out int[] o_PositionFromUserInTheBoard)
        {
            bool requiredCellIsEmpty = true;

            askFromCurrentPlayerToInsertThePositionToHisNextStep(out o_PositionFromUserInTheBoard, i_OtheloGameBoard);

            while (i_OtheloGameBoard.CheckTheRequiredPositionOnBoardIsEmpty(o_PositionFromUserInTheBoard[0], o_PositionFromUserInTheBoard[1]) != requiredCellIsEmpty)
            {
                // In case it's possible the current player to continue but he want to put his signal in not empty position
                Console.WriteLine(@"
                            This position isn't empty !!! try again -");

                askFromCurrentPlayerToInsertThePositionToHisNextStep(out o_PositionFromUserInTheBoard, i_OtheloGameBoard);
            }
        }
Beispiel #12
0
        private bool checkIfLegalMoveAndUpdateLegalMovesMatrix(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, int i_RowIndex, int i_ColumnIndex)
        {
            const char v_EmptyCellInGameBoard = '\0';
            bool       itIsLegalMove          = true;

            if (i_OtheloGameBoard.OtheloGameBoardMatrix[i_RowIndex, i_ColumnIndex] != v_EmptyCellInGameBoard)
            {
                itIsLegalMove = !itIsLegalMove;
            }
            else
            {
                itIsLegalMove = checkEightPossibleSidesAroundCellOnBoard(i_OtheloGameBoard, i_CurrentSignalTurn, i_RowIndex, i_ColumnIndex);
            }

            return(itIsLegalMove);
        }
Beispiel #13
0
        public void PutAutomaticSignalOfCompuerOnBoard(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn)
        {
            const int k_NumOfIdxesInArray = 2;

            // Ref to Random object of the System class
            Random chooseRandomPossibleCellInTheBoard = new Random();

            int randomListIndex = chooseRandomPossibleCellInTheBoard.Next(m_ListWithTheCurrentPositinsOptionsOnBoardForRandom.Count);

            int[] positionInTheBoard = new int[k_NumOfIdxesInArray];     // Array to place the 2 indexes for the current turn of the computer

            checkIfTheRandomValueFromListIsRowOrColumnIndexInTheMatrix(positionInTheBoard, randomListIndex);

            // Put the computer signal on board according the random possible cell you have
            PutSignalInTheRequiredUserPositionOnBoard(i_OtheloGameBoard, i_CurrentSignalTurn, positionInTheBoard);
        }
Beispiel #14
0
        private void fillSpecificCellInLegalMovesMatrix(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, int i_RowIndex, int i_ColumnIndex, OtheloGamePlayer i_SecondPlayer)
        {
            const bool v_LegalMove = true;

            if (checkIfLegalMoveAndUpdateLegalMovesMatrix(i_OtheloGameBoard, i_CurrentSignalTurn, i_RowIndex, i_ColumnIndex) == v_LegalMove)
            {
                // Fill the specific cell in the legal moves matrix with the current signal turn
                this.m_AllCurrentLegalMovesMatrix[i_RowIndex, i_ColumnIndex] = i_CurrentSignalTurn;

                // Fill the List with the relevent matrix indexes cell - For the random action later
                if (i_SecondPlayer.StateGame == OtheloGameBoard.eGameTypes.Computer)
                {
                    m_ListWithTheCurrentPositinsOptionsOnBoardForRandom.Add(i_RowIndex);    // Put the row index of cell in the even place of the list
                    m_ListWithTheCurrentPositinsOptionsOnBoardForRandom.Add(i_ColumnIndex); // Put the column index of cell in the odd place of the list
                }
            }
        }
Beispiel #15
0
        private bool checkThereIsAtLeastOneMoreSignalOnBoardTwoSidesFromMYPosition(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, int i_RowIndex, int i_ColumnIndex, int i_RowIndexToMoveAround, int i_ColumnIndexToMoveAround)
        {
            bool stayInBoardBordersIfYouMoveOneSide = true;
            int  doubleRowIndex    = i_RowIndexToMoveAround * 2;
            int  doubleColumnIndex = i_ColumnIndexToMoveAround * 2;

            if ((i_RowIndex + doubleRowIndex < 0) || (i_RowIndex + doubleRowIndex) > i_OtheloGameBoard.OtheloGameBoardMatrixDimension - 1)
            {    // Out of rows bounds
                stayInBoardBordersIfYouMoveOneSide = !stayInBoardBordersIfYouMoveOneSide;
            }
            else if ((i_ColumnIndex + doubleColumnIndex) < 0 || (i_ColumnIndex + doubleColumnIndex) > i_OtheloGameBoard.OtheloGameBoardMatrixDimension - 1)
            {  // Out of columns bounds
                stayInBoardBordersIfYouMoveOneSide = !stayInBoardBordersIfYouMoveOneSide;
            }

            return(stayInBoardBordersIfYouMoveOneSide);
        }
Beispiel #16
0
        private void changeAllTheOpponentSignalsYouBlockOnBoard(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, int i_RowInputIndex, int i_ColumnInputIndex)
        {
            const int k_MaxLowValueToAddColumnsAndRows  = -1;
            const int k_MaxHighValueToAddColumnsAndRows = 1;

            // By 'rowIndexToMoveAround' and 'columnIndexToMoveAround' indexes you can scan all the eight sides around you
            for (int rowIndexToMoveAround = k_MaxLowValueToAddColumnsAndRows; rowIndexToMoveAround <= k_MaxHighValueToAddColumnsAndRows; rowIndexToMoveAround++)
            {
                for (int columnIndexToMoveAround = k_MaxLowValueToAddColumnsAndRows; columnIndexToMoveAround <= k_MaxHighValueToAddColumnsAndRows; columnIndexToMoveAround++)
                {
                    // Irellevent to my position - only the cells around me
                    if (rowIndexToMoveAround == 0 && columnIndexToMoveAround == 0)
                    {
                        continue;
                    }

                    recursiveMethodToFlipOpponentSignalsYouBlockInSpecificRow(i_OtheloGameBoard, i_CurrentSignalTurn, i_RowInputIndex, i_ColumnInputIndex, rowIndexToMoveAround, columnIndexToMoveAround);
                }
            }
        }
Beispiel #17
0
        public char CheckWhoIsTheWinnerOfTheCurrentGame(OtheloGameBoard i_OtheloGameBoard, OtheloGamePlayer i_FirstPlayer, OtheloGamePlayer i_SecondPlayer)
        {
            char theWinnerOfTheCurrentGame;

            if (i_OtheloGameBoard.NumOfFirstPlayerSignalsOnBoard > i_OtheloGameBoard.NumOfSecondPlayerSignalsOnBoard)
            {
                theWinnerOfTheCurrentGame = k_PlayerSignalKind1;
            }
            else if (i_OtheloGameBoard.NumOfFirstPlayerSignalsOnBoard < i_OtheloGameBoard.NumOfSecondPlayerSignalsOnBoard)
            {
                theWinnerOfTheCurrentGame = k_PlayerSignalKind2;
            }
            else
            {  // FirstPlayer signals == SecondPlayer signals on board
                theWinnerOfTheCurrentGame = k_NoWinnerInTheGame;
            }

            i_FirstPlayer.PlayerPoints  = i_OtheloGameBoard.NumOfFirstPlayerSignalsOnBoard;
            i_SecondPlayer.PlayerPoints = i_OtheloGameBoard.NumOfSecondPlayerSignalsOnBoard;

            return(theWinnerOfTheCurrentGame);
        }
Beispiel #18
0
        public bool CheckIfCurrentPlayerHasOptionToContinueThisTurn(char i_CurrentSignalTurn, OtheloGameBoard i_OtheloGameBoard, OtheloGamePlayer i_SecondPlayer)
        {
            const bool v_LegalMovesMatrixEmptyFromCurrentSignalTurn = true;
            bool       currentPlayerHasOptionToContinueThisTurn     = true;

            zeroTheLegalMovesMatrix(i_OtheloGameBoard);

            if (i_SecondPlayer.StateGame == OtheloGameBoard.eGameTypes.Computer && m_ListWithTheCurrentPositinsOptionsOnBoardForRandom.Count != 0)
            {
                m_ListWithTheCurrentPositinsOptionsOnBoardForRandom.Clear();
            }

            createCurrentLegalMovesMatrix(i_OtheloGameBoard, i_CurrentSignalTurn, i_SecondPlayer);

            if (checkIfLegalMovesMatrixEmptyFromCurrentSignalTurn(i_CurrentSignalTurn, i_OtheloGameBoard) == v_LegalMovesMatrixEmptyFromCurrentSignalTurn)
            {
                currentPlayerHasOptionToContinueThisTurn = !currentPlayerHasOptionToContinueThisTurn;
            }

            return(currentPlayerHasOptionToContinueThisTurn);
        }
Beispiel #19
0
        private void startNewGame(OtheloGameBoard i_OtheloGameBoard)
        {
            i_OtheloGameBoard.InitializeOtheloGameBoard();

            s_CurrentSignalTurn = k_FirstPlayerSignal; // Always the 'X' player starts first
        }
Beispiel #20
0
        private void askFromCurrentPlayerToInsertThePositionToHisNextStep(out int[] o_PositionFromUserInTheBoard, OtheloGameBoard i_OtheloGameBoard)
        {
            string strUserRowNumberPosition;
            string strUserColumnLetterPosition;
            int    intUserRowNumberPosition;
            int    convertedIntUserRowNumberPosition;
            int    convertedIntUserColumnLetterPosition;

            Console.WriteLine(@"Please choose cell in the board you want to put {0}. First enter the row number and press enter :", s_CurrentSignalTurn);

            strUserRowNumberPosition = Console.ReadLine();
            intUserRowNumberPosition = checkTheInputRowNumberPosition(strUserRowNumberPosition, i_OtheloGameBoard);

            Console.WriteLine("Now enter column letter position you want :");

            strUserColumnLetterPosition = Console.ReadLine();
            checkTheInputColumnLetterPosition(ref strUserColumnLetterPosition, i_OtheloGameBoard);

            convertedIntUserRowNumberPosition = intUserRowNumberPosition - 1; // Match between input number row index and matrix row index

            convertedIntUserColumnLetterPosition = convertTheInputLetterToActualIndexesInTheBoard(strUserColumnLetterPosition);

            // Insert the position from user to the array
            o_PositionFromUserInTheBoard    = new int[2];
            o_PositionFromUserInTheBoard[0] = convertedIntUserRowNumberPosition;
            o_PositionFromUserInTheBoard[1] = convertedIntUserColumnLetterPosition;
        }
Beispiel #21
0
        private int checkTheInputRowNumberPosition(string i_StrUserRowNumberPosition, OtheloGameBoard i_OtheloGameBoard)
        {
            int        intUserRowNumberPosition;
            const bool v_UserInsertLegalRowNumber = true;
            const bool v_SuccessParseStringToInt  = true;

            checkIfUserInputWantToExitFromGame(i_StrUserRowNumberPosition);

            while (int.TryParse(i_StrUserRowNumberPosition, out intUserRowNumberPosition) != v_SuccessParseStringToInt ||
                   i_OtheloGameBoard.CheckTheInputRowNumberIsNotOutOfBoundsOfTheGameBoard(intUserRowNumberPosition) != v_UserInsertLegalRowNumber)
            {
                Console.WriteLine(@"

                Wrong input row number!!! Out of game board bounds
                Enter again row number value");

                i_StrUserRowNumberPosition = Console.ReadLine();

                checkIfUserInputWantToExitFromGame(i_StrUserRowNumberPosition);
            }

            return(intUserRowNumberPosition);
        }
Beispiel #22
0
        private void printMsgAboutTheWinner(OtheloGamePlayer i_FirstPlayer, OtheloGamePlayer i_SecondPlayer, OtheloGameBoard i_OtheloGameBoard, string i_MsgAboutTheWinner)
        {
            string msgAboutCurrentTurn = string.Format(@" GAME OVER ! ! ! {0}  Your points in this game are : {1} : {3} points, {2} : {4} points", i_MsgAboutTheWinner, i_FirstPlayer.PlayerName, i_SecondPlayer.PlayerName, i_FirstPlayer.PlayerPoints, i_SecondPlayer.PlayerPoints);

            Console.WriteLine(msgAboutCurrentTurn);
        }
Beispiel #23
0
        // $G$ CSS-028 (-3) method shouldn't include more then one return command.
        private bool recursiveMethodToCheckThereIsMyTypeBlockSignalInTheEndOfThisSideRow(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, int i_RowIndex, int i_ColumnIndex, int i_RowIndexToMoveAround, int i_ColumnIndexToMoveAround)
        {
            const bool v_ThereIsMyTypeBlockSignalInTheEndOfThisSideRow = true;
            const char k_EmptyCellInGameBoard = '\0';

            /* Stop conditions of the recursion :
             * If we out of the board bourders */
            if (i_RowIndex == i_OtheloGameBoard.OtheloGameBoardMatrixDimension || i_ColumnIndex == i_OtheloGameBoard.OtheloGameBoardMatrixDimension)
            {
                return(!v_ThereIsMyTypeBlockSignalInTheEndOfThisSideRow);
            }
            else if (i_OtheloGameBoard.OtheloGameBoardMatrix[i_RowIndex, i_ColumnIndex] == i_CurrentSignalTurn)
            {  // If we arrive to signal like my type - so stop and return true , cause bloking can be
                return(v_ThereIsMyTypeBlockSignalInTheEndOfThisSideRow);
            }
            else if (i_OtheloGameBoard.OtheloGameBoardMatrix[i_RowIndex, i_ColumnIndex] == k_EmptyCellInGameBoard)
            { // If we arrive to empty place in board - so stop and return false , cause bloking can't be
                return(!v_ThereIsMyTypeBlockSignalInTheEndOfThisSideRow);
            }
            else if (i_RowIndex + i_RowIndexToMoveAround < 0 || i_RowIndex + i_RowIndexToMoveAround > i_OtheloGameBoard.OtheloGameBoardMatrixDimension)
            {  // In case the next step is out of rows bounds
                return(!v_ThereIsMyTypeBlockSignalInTheEndOfThisSideRow);
            }
            else if (i_ColumnIndex + i_ColumnIndexToMoveAround < 0 || i_ColumnIndex + i_ColumnIndexToMoveAround > i_OtheloGameBoard.OtheloGameBoardMatrixDimension)
            { // In case the next step is out of columns bounds
                return(!v_ThereIsMyTypeBlockSignalInTheEndOfThisSideRow);
            }

            // Recursive calling
            return(recursiveMethodToCheckThereIsMyTypeBlockSignalInTheEndOfThisSideRow(i_OtheloGameBoard, i_CurrentSignalTurn, i_RowIndex + i_RowIndexToMoveAround, i_ColumnIndex + i_ColumnIndexToMoveAround, i_RowIndexToMoveAround, i_ColumnIndexToMoveAround));
        }
Beispiel #24
0
        private bool checkNextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, int i_RowIndex, int i_ColumnIndex, int i_RowIndexToMoveAround, int i_ColumnIndexToMoveAround)
        {
            const bool v_StayInBoardBordersIfYouMoveOneSide            = true;
            const bool v_StayInBoardBordersIfYouMoveTwoSide            = true;
            const bool v_ThereIsMyTypeBlockSignalInTheEndOfThisSideRow = true;
            bool       nextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType = true;
            int        doubleRowIndex    = i_RowIndexToMoveAround * 2;
            int        doubleColumnIndex = i_ColumnIndexToMoveAround * 2;

            if (checkYouStayInBoardBordersIfYouMoveOneSideNextToPosition(i_OtheloGameBoard, i_CurrentSignalTurn, i_RowIndex, i_ColumnIndex, i_RowIndexToMoveAround, i_ColumnIndexToMoveAround) == v_StayInBoardBordersIfYouMoveOneSide)
            {
                // If the close signal is the opposite of my type - so it is a possible side
                if (i_OtheloGameBoard.OtheloGameBoardMatrix[i_RowIndex + i_RowIndexToMoveAround, i_ColumnIndex + i_ColumnIndexToMoveAround] == i_OtheloGameBoard.GetTheOppositeSignal(i_CurrentSignalTurn))
                {
                    // If there is more than one signal after my signal in this side
                    if (checkThereIsAtLeastOneMoreSignalOnBoardTwoSidesFromMYPosition(i_OtheloGameBoard, i_CurrentSignalTurn, i_RowIndex, i_ColumnIndex, i_RowIndexToMoveAround, i_ColumnIndexToMoveAround) == v_StayInBoardBordersIfYouMoveTwoSide)
                    {
                        if (recursiveMethodToCheckThereIsMyTypeBlockSignalInTheEndOfThisSideRow(i_OtheloGameBoard, i_CurrentSignalTurn, i_RowIndex + doubleRowIndex, i_ColumnIndex + doubleColumnIndex, i_RowIndexToMoveAround, i_ColumnIndexToMoveAround) != v_ThereIsMyTypeBlockSignalInTheEndOfThisSideRow)
                        {
                            nextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType = !nextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType;
                        }
                    }
                    else
                    {
                        nextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType = !nextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType;
                    }
                }
                else
                {
                    nextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType = !nextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType;
                }
            }
            else
            {
                nextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType = !nextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType;
            }

            return(nextSignalInSpecificSideOppositeAndTheRowEndWithMySignalType);
        }
Beispiel #25
0
        private void printWhoIsTheWinnerOfTheCurrentGame(OtheloGamePlayer i_FirstPlayer, OtheloGamePlayer i_SecondPlayer, OtheloGameBoard i_OtheloGameBoard)
        {
            char   theWinnerOfTheCurrentGame;
            string msgAboutTheWinner;

            theWinnerOfTheCurrentGame = s_OtheloGamePolicy.CheckWhoIsTheWinnerOfTheCurrentGame(i_OtheloGameBoard, i_FirstPlayer, i_SecondPlayer);

            if (theWinnerOfTheCurrentGame == 'X')
            {
                msgAboutTheWinner = string.Format("{0} is the winner  :))))))", i_FirstPlayer.PlayerName);

                printMsgAboutTheWinner(i_FirstPlayer, i_SecondPlayer, i_OtheloGameBoard, msgAboutTheWinner);
            }
            else if (theWinnerOfTheCurrentGame == 'O')
            {
                msgAboutTheWinner = string.Format("{0} is the winner :))))))", i_SecondPlayer.PlayerName);

                printMsgAboutTheWinner(i_SecondPlayer, i_FirstPlayer, i_OtheloGameBoard, msgAboutTheWinner);
            }
            else
            {
                // FirstPlayer signals == SecondPlayer signals on board
                msgAboutTheWinner = string.Format("There is no winner this game", i_FirstPlayer.PlayerName);

                printMsgAboutTheWinner(i_FirstPlayer, i_SecondPlayer, i_OtheloGameBoard, msgAboutTheWinner);
            }
        }
Beispiel #26
0
        // $G$ DSN-999 (-5) this method is to long - should be divided to several methods
        private void startPlayOtheloGame(OtheloGamePlayer i_FirstPlayer, OtheloGamePlayer i_SecondPlayer, OtheloGameBoard i_OtheloGameBoard)
        {
            const bool v_HasFreePlaceOnBoardGame = true;
            const bool v_WantToPlayAnotherGameWithTheSamePlayer = true;
            const bool v_CurrentPlayerCanContinueThisTurn       = true;
            const bool v_UserChoiseIsLegal             = true;
            const bool v_TwoPlayersCanNotMoveInTheGame = true;
            const bool v_UserWantToStartNewGame        = true;
            const int  k_TimeToDelay                = 3000;
            bool       wantStartNewGame             = true;
            bool       currentPlayerCanPlayThisTurn = true;

            int[] positionFromUserInTheBoard;

            while (wantStartNewGame == v_UserWantToStartNewGame)
            {
                while (i_OtheloGameBoard.CheckTheOtheloBoardGameHasFreePlace() == v_HasFreePlaceOnBoardGame)
                {
                    // There are still empty cells on board - continue the game
                    i_OtheloGameBoard.PrintOtheloGameBoard();

                    i_OtheloGameBoard.CountAndUpdateHowManySignalsOnBoardFromAnyKind();

                    checkIfPrintMsgAboutTheCurrentPlayerHasNothingToDoThisTurn(ref currentPlayerCanPlayThisTurn);

                    printTheCurrentUserTurn(i_FirstPlayer.PlayerName, i_SecondPlayer.PlayerName);

                    if (s_OtheloGamePolicy.CheckIfCurrentPlayerHasOptionToContinueThisTurn(s_CurrentSignalTurn, i_OtheloGameBoard, i_SecondPlayer) == v_CurrentPlayerCanContinueThisTurn)
                    {
                        // If it's regular player turn ( not the computer )
                        if ((s_CurrentSignalTurn == k_FirstPlayerSignal) || (s_CurrentSignalTurn == k_SecondPlayerSignal && i_SecondPlayer.StateGame != OtheloGameBoard.eGameTypes.Computer))
                        {
                            // There is atleast one option to the current player to continue in this turn
                            currentPlayerCanContinueToPlayThisTurn(i_OtheloGameBoard, out positionFromUserInTheBoard);

                            /* In case it is possible the current player to continue and he want to put his signal in empty position on the board,
                             * so now you have to check if it's legal */

                            while (s_OtheloGamePolicy.CheckTheUserChoiseIsLegal(s_CurrentSignalTurn, i_OtheloGameBoard, positionFromUserInTheBoard) != v_UserChoiseIsLegal)
                            {
                                // In case the user chose illegal position - try insert new position
                                Console.WriteLine("Illegal position!!! You can put your signal only if you block the other player!");
                                currentPlayerCanContinueToPlayThisTurn(i_OtheloGameBoard, out positionFromUserInTheBoard);
                            }

                            // In case the position from user is legal - so do it!
                            s_OtheloGamePolicy.PutSignalInTheRequiredUserPositionOnBoard(i_OtheloGameBoard, s_CurrentSignalTurn, positionFromUserInTheBoard);
                        }
                        else if (s_CurrentSignalTurn == k_SecondPlayerSignal && i_SecondPlayer.StateGame == OtheloGameBoard.eGameTypes.Computer)
                        {  // In case it's second player turn and it's the COMPUTER
                            s_OtheloGamePolicy.PutAutomaticSignalOfCompuerOnBoard(i_OtheloGameBoard, s_CurrentSignalTurn);
                            System.Threading.Thread.Sleep(k_TimeToDelay);
                        }
                    }
                    else
                    { // In case the current player has nothing to do
                        currentPlayerCanPlayThisTurn = !currentPlayerCanPlayThisTurn;
                    }

                    /* In case there isn't possible way to current player to continue this turn - so move to the other player
                     * We arrive here also when the current player finish his turn and we continue to the other player*/

                    if (checkTheTwoPlayersCanNotMoveInTheGame(i_OtheloGameBoard, i_SecondPlayer) == v_TwoPlayersCanNotMoveInTheGame)
                    {
                        printMassageInCaseTwoPlayersCanNotMoveInTheGame(i_OtheloGameBoard);
                        break;
                    }

                    changeTurnToTheOtherPlayer();
                }

                // No free place on board game or no one from the players can play - so finish the current game and display the points status
                noFreePlaceOnBoardOrNoOneCanPlaySoFinishTheGame(i_FirstPlayer, i_SecondPlayer, i_OtheloGameBoard);

                if (askAboutAnotherGameWithTheSamePlayer() != v_WantToPlayAnotherGameWithTheSamePlayer)
                {
                    printMsgAboutLeaveTheGame();

                    wantStartNewGame = !wantStartNewGame; // Dont start an new game
                }
                else
                { // Want to start an new game
                    startNewGame(i_OtheloGameBoard);
                }
            }
        }
Beispiel #27
0
        private void noFreePlaceOnBoardOrNoOneCanPlaySoFinishTheGame(OtheloGamePlayer i_FirstPlayer, OtheloGamePlayer i_SecondPlayer, OtheloGameBoard i_OtheloGameBoard)
        {
            i_OtheloGameBoard.CountAndUpdateHowManySignalsOnBoardFromAnyKind();

            printWhoIsTheWinnerOfTheCurrentGame(i_FirstPlayer, i_SecondPlayer, i_OtheloGameBoard);
        }
Beispiel #28
0
        private void checkTheInputColumnLetterPosition(ref string io_StrUserColumnLetterPosition, OtheloGameBoard i_OtheloGameBoard)
        {
            const bool v_UserInsertLegalColumnLetterPosition = true;

            checkIfUserInputWantToExitFromGame(io_StrUserColumnLetterPosition);

            while (i_OtheloGameBoard.CheckTheInputColumnLetterIsNotOutOfBoundsOfTheGameBoard(io_StrUserColumnLetterPosition) != v_UserInsertLegalColumnLetterPosition)
            {
                Console.WriteLine(@"
                Wrong input column letter!!! Out of game board bounds
                Enter again column letter value");

                io_StrUserColumnLetterPosition = Console.ReadLine();

                checkIfUserInputWantToExitFromGame(io_StrUserColumnLetterPosition);
            }
        }
Beispiel #29
0
        private bool checkIfLegalMovesMatrixEmptyFromCurrentSignalTurn(char i_CurrentSignalTurn, OtheloGameBoard i_OtheloGameBoard)
        {
            bool legalMovesMatrixEmptyFromCurrentSignalTurn = true;

            for (int i = 0; i < i_OtheloGameBoard.OtheloGameBoardMatrixDimension; i++)
            {
                for (int j = 0; j < i_OtheloGameBoard.OtheloGameBoardMatrixDimension; j++)
                {
                    /* In case the 'LegalMovesMatrix' contains atleast one signal type -
                     * so it's mean that the current player can play this turn */

                    if (this.m_AllCurrentLegalMovesMatrix[i, j] == i_CurrentSignalTurn)
                    {
                        legalMovesMatrixEmptyFromCurrentSignalTurn = !legalMovesMatrixEmptyFromCurrentSignalTurn;
                        i = i_OtheloGameBoard.OtheloGameBoardMatrixDimension;
                        break;
                    }
                }
            }

            return(legalMovesMatrixEmptyFromCurrentSignalTurn);
        }
Beispiel #30
0
 private void createCurrentLegalMovesMatrix(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, OtheloGamePlayer i_SecondPlayer)
 {
     fillCurrentLegalMovesMatrix(i_OtheloGameBoard, i_CurrentSignalTurn, i_SecondPlayer);
 }