示例#1
0
        private void updateStatus(eCurrentDiskMode i_DiskMode)
        {
            const string k_DiskSign = "O";

            if (i_DiskMode == eCurrentDiskMode.NotExist)
            {
                BackColor = Color.Empty;
                Text      = string.Empty;
                Enabled   = false;
            }
            else if (i_DiskMode == eCurrentDiskMode.Black)
            {
                BackColor = Color.Black;
                Text      = k_DiskSign;
                ForeColor = Color.White;
                Enabled   = true;
            }
            else if (i_DiskMode == eCurrentDiskMode.White)
            {
                BackColor = Color.White;
                Text      = k_DiskSign;
                ForeColor = Color.Black;
                Enabled   = true;
            }
            else if (i_DiskMode == eCurrentDiskMode.Green)
            {
                BackColor = Color.LimeGreen;
                Text      = string.Empty;
                ForeColor = Color.Black;
                Enabled   = true;
            }
        }
示例#2
0
 public void DiskUpdate(int i_Row, int i_Column, eCurrentDiskMode i_DiskMode)
 {
     if (r_Row == i_Row && r_Column == i_Column)
     {
         updateStatus(i_DiskMode);
     }
 }
示例#3
0
        private void checkGameStatusAfterEndOfTurn()
        {
            IsBlackTurn = !IsBlackTurn;
            eCurrentDiskMode currentColor = IsBlackTurn ? eCurrentDiskMode.Black : eCurrentDiskMode.White;
            bool             isPossibleForNextPlayerToPlay = false;

            for (int i = 1; i <= BoardLength && !isPossibleForNextPlayerToPlay; i++)
            {
                for (int j = 1; j <= BoardLength && !isPossibleForNextPlayerToPlay; j++)
                {
                    isPossibleForNextPlayerToPlay = isLegalPositionForNewDisk(i, j, currentColor);
                }
            }

            if (!isPossibleForNextPlayerToPlay)
            {
                IsBlackTurn  = !IsBlackTurn;
                currentColor = IsBlackTurn ? eCurrentDiskMode.Black : eCurrentDiskMode.White;
                for (int i = 1; i <= BoardLength && !isPossibleForNextPlayerToPlay; i++)
                {
                    for (int j = 1; j <= BoardLength && !isPossibleForNextPlayerToPlay; j++)
                    {
                        isPossibleForNextPlayerToPlay = isLegalPositionForNewDisk(i, j, currentColor);
                    }
                }

                if (!isPossibleForNextPlayerToPlay)
                {
                    GameOver = !GameOver;
                }
            }
        }
示例#4
0
 public ButtonOthelloDisk(int i_Row, int i_Column, eCurrentDiskMode i_DiskMode)
 {
     r_Row      = i_Row;
     r_Column   = i_Column;
     m_DiskMode = i_DiskMode;
     updateStatus(i_DiskMode);
 }
示例#5
0
        private void closeLine(eCurrentDiskMode i_ColorToClose, int i_RowLocationToAddDiskOnBoard, int i_ColumnLocationToAddDiskOnBoard, int i_RowDirection, int i_ColumnDirection)
        {
            OthelloGameDisk newDiskToAdd = new OthelloGameDisk();

            newDiskToAdd.DiskColor = i_ColorToClose;
            bool canWeCloseLine = false;

            while (isDiskInBoardRange(i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard) && !canWeCloseLine && this[i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard].DiskColor != eCurrentDiskMode.NotExist)
            {
                canWeCloseLine = this[i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard].DiskColor == i_ColorToClose;
                this[i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard] = newDiskToAdd;
                i_RowLocationToAddDiskOnBoard    += i_RowDirection;
                i_ColumnLocationToAddDiskOnBoard += i_ColumnDirection;
            }
        }
示例#6
0
        public eCurrentDiskMode GetOppositeDisk()
        {
            eCurrentDiskMode returnValue = eCurrentDiskMode.NotExist;

            if (DiskColor == eCurrentDiskMode.White)
            {
                returnValue = eCurrentDiskMode.Black;
            }
            else if (DiskColor == eCurrentDiskMode.Black)
            {
                returnValue = eCurrentDiskMode.White;
            }

            return(returnValue);
        }
示例#7
0
        private bool checkIfCanCloseLine(eCurrentDiskMode i_ColorToClose, int i_RowLocationToAddDiskOnBoard, int i_ColumnLocationToAddDiskOnBoard, int i_RowDirection, int i_ColumnDirection)
        {
            bool canWeCloseLine = false;

            i_RowLocationToAddDiskOnBoard    += i_RowDirection;
            i_ColumnLocationToAddDiskOnBoard += i_ColumnDirection;

            while (isDiskInBoardRange(i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard) && !canWeCloseLine && this[i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard].DiskColor != eCurrentDiskMode.NotExist)
            {
                canWeCloseLine = this[i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard].DiskColor == i_ColorToClose;
                i_RowLocationToAddDiskOnBoard    += i_RowDirection;
                i_ColumnLocationToAddDiskOnBoard += i_ColumnDirection;
            }

            return(canWeCloseLine);
        }
示例#8
0
        private void checkGameStatusAfterEndOfTurn()
        {
            IsBlackTurn = !IsBlackTurn;
            eCurrentDiskMode currentColor = IsBlackTurn ? eCurrentDiskMode.Black : eCurrentDiskMode.White;
            bool             isPossibleForNextPlayerToPlay = false;

            isPossibleForNextPlayerToPlay = checkIsItPossiableForNextPlayerToPlay(isPossibleForNextPlayerToPlay, currentColor);

            if (!isPossibleForNextPlayerToPlay)
            {
                IsBlackTurn  = !IsBlackTurn;
                currentColor = IsBlackTurn ? eCurrentDiskMode.Black : eCurrentDiskMode.White;

                isPossibleForNextPlayerToPlay = checkIsItPossiableForNextPlayerToPlay(isPossibleForNextPlayerToPlay, currentColor);

                if (!isPossibleForNextPlayerToPlay)
                {
                    updateCalculateScore();
                    GameOver = !GameOver;
                }
            }
        }
示例#9
0
        private void colorPossibleNextMove(eCurrentDiskMode i_CurrentDisk)
        {
            for (int i = 1; i <= BoardLength; i++)
            {
                for (int j = 1; j <= BoardLength; j++)
                {
                    if (this[i, j].DiskColor == eCurrentDiskMode.NotExist)
                    {
                        if (DiskUpdate != null)
                        {
                            DiskUpdate(i, j, eCurrentDiskMode.NotExist);
                        }
                    }

                    if (isLegalPositionForNewDisk(i, j, i_CurrentDisk))
                    {
                        if (DiskUpdate != null)
                        {
                            DiskUpdate(i, j, eCurrentDiskMode.Green);
                        }
                    }
                }
            }
        }
示例#10
0
        private bool isLegalPositionForNewDisk(int i_RowLocationToAddDiskOnBoard, int i_ColumnLocationToAddDiskOnBoard, eCurrentDiskMode i_DiskColorToAdd)
        {
            const int k_CurrentCell = 0;
            bool      isSurroundingEnviromentMakeItLegal = false;
            bool      isLegalRandgeAndNotOccupied        = i_DiskColorToAdd != eCurrentDiskMode.NotExist && isDiskInBoardRange(i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard);

            isLegalRandgeAndNotOccupied = isLegalRandgeAndNotOccupied ? (this[i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard].DiskColor == eCurrentDiskMode.NotExist) : isLegalRandgeAndNotOccupied;

            if (isLegalRandgeAndNotOccupied)
            {
                for (int i = -1; i <= 1 && !isSurroundingEnviromentMakeItLegal; i++)
                {
                    for (int j = -1; j <= 1 && !isSurroundingEnviromentMakeItLegal; j++)
                    {
                        if (i != k_CurrentCell || j != k_CurrentCell)
                        {
                            // First line check if is in BoardRange, Second line if the Disk Opposite color so we can close line
                            isSurroundingEnviromentMakeItLegal = isDiskInBoardRange(i_RowLocationToAddDiskOnBoard + i, i_ColumnLocationToAddDiskOnBoard + j);
                            isSurroundingEnviromentMakeItLegal = isSurroundingEnviromentMakeItLegal ? (this[i_RowLocationToAddDiskOnBoard + i, i_ColumnLocationToAddDiskOnBoard + j].GetOppositeDisk() == i_DiskColorToAdd) : isSurroundingEnviromentMakeItLegal;

                            // Check if we can Close line
                            isSurroundingEnviromentMakeItLegal = isSurroundingEnviromentMakeItLegal ? checkIfCanCloseLine(i_DiskColorToAdd, i_RowLocationToAddDiskOnBoard + i, i_ColumnLocationToAddDiskOnBoard + j, i, j) : isSurroundingEnviromentMakeItLegal;
                        }
                    }
                }
            }

            return(isSurroundingEnviromentMakeItLegal);
        }
示例#11
0
        private bool addNewDiskToBoard(int i_RowLocationToAddDiskOnBoard, int i_ColumnLocationToAddDiskOnBoard, eCurrentDiskMode i_DiskColorToAdd)
        {
            const bool v_IsTheLineFlipable = true;
            bool       isCurrentDiskDirectionNeedFliplop = !v_IsTheLineFlipable;
            bool       isPossibleToAddDisk = isLegalPositionForNewDisk(i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard, i_DiskColorToAdd);

            if (isPossibleToAddDisk)
            {
                this[i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard] = new OthelloGameDisk(i_DiskColorToAdd);

                for (int numberOfRowRunningOnFor = -1; numberOfRowRunningOnFor <= 1; numberOfRowRunningOnFor++)
                {
                    for (int numberOfColumnRunningOnFor = -1; numberOfColumnRunningOnFor <= 1; numberOfColumnRunningOnFor++)
                    {
                        if (numberOfRowRunningOnFor != 0 || numberOfColumnRunningOnFor != 0)
                        {
                            // FirstLine check if is in board range, 2nd line check if the disk is opposite color
                            isCurrentDiskDirectionNeedFliplop = isDiskInBoardRange(i_RowLocationToAddDiskOnBoard + numberOfRowRunningOnFor, i_ColumnLocationToAddDiskOnBoard + numberOfColumnRunningOnFor);
                            isCurrentDiskDirectionNeedFliplop = isCurrentDiskDirectionNeedFliplop ? (this[i_RowLocationToAddDiskOnBoard + numberOfRowRunningOnFor, i_ColumnLocationToAddDiskOnBoard + numberOfColumnRunningOnFor].GetOppositeDisk() == i_DiskColorToAdd) : isCurrentDiskDirectionNeedFliplop;

                            // Check if we can close line
                            isCurrentDiskDirectionNeedFliplop = isCurrentDiskDirectionNeedFliplop ? checkIfCanCloseLine(i_DiskColorToAdd, i_RowLocationToAddDiskOnBoard + numberOfRowRunningOnFor, i_ColumnLocationToAddDiskOnBoard + numberOfColumnRunningOnFor, numberOfRowRunningOnFor, numberOfColumnRunningOnFor) : isCurrentDiskDirectionNeedFliplop;
                            if (isCurrentDiskDirectionNeedFliplop)
                            {
                                closeLine(i_DiskColorToAdd, i_RowLocationToAddDiskOnBoard + numberOfRowRunningOnFor, i_ColumnLocationToAddDiskOnBoard + numberOfColumnRunningOnFor, numberOfRowRunningOnFor, numberOfColumnRunningOnFor);
                                isCurrentDiskDirectionNeedFliplop = !v_IsTheLineFlipable;
                            }
                        }
                    }
                }
            }

            return(isPossibleToAddDisk);
        }
示例#12
0
        private bool makeMove(int i_RowLocationToAddDiskOnBoard, int i_ColumnLocationToAddDiskOnBoard, eCurrentDiskMode i_DiskToMove)
        {
            bool isSuccessfullMove         = false;
            bool isRightTurn               = (IsBlackTurn && i_DiskToMove == eCurrentDiskMode.Black) || (!IsBlackTurn && i_DiskToMove == eCurrentDiskMode.White);
            bool isRightTurnAndNotGameOver = !GameOver && isRightTurn && addNewDiskToBoard(i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard, i_DiskToMove);

            if (isRightTurnAndNotGameOver)
            {
                isSuccessfullMove = !isSuccessfullMove;
                if (!IsBlackTurn && PlayerTwo.IsComputer && s_IsItHumanPlaying)
                {
                    CopyBoard();
                    Ex02.ConsoleUtils.Screen.Clear();
                    BoardForUi.PrintBoard();
                    s_IsItHumanPlaying = false;
                }

                checkGameStatusAfterEndOfTurn();
                while (!GameOver && IsBlackTurn && m_PlayerTwo.IsComputer && !MinMaxSimulation)
                {
                    computerMakeMoveDecsion();
                }
            }

            return(isSuccessfullMove);
        }
示例#13
0
 public OthelloGameDisk(eCurrentDiskMode i_OthelloDisk)
 {
     m_OthelloDisk = i_OthelloDisk;
 }
示例#14
0
        private bool checkIsItPossiableForNextPlayerToPlay(bool i_IsPossibleForNextPlayerToPlay, eCurrentDiskMode i_CurrentColor)
        {
            for (int i = 1; i <= BoardLength && !i_IsPossibleForNextPlayerToPlay; i++)
            {
                for (int j = 1; j <= BoardLength && !i_IsPossibleForNextPlayerToPlay; j++)
                {
                    i_IsPossibleForNextPlayerToPlay = isLegalPositionForNewDisk(i, j, i_CurrentColor);
                }
            }

            return(i_IsPossibleForNextPlayerToPlay);
        }
示例#15
0
        private bool makeMove(int i_RowLocationToAddDiskOnBoard, int i_ColumnLocationToAddDiskOnBoard, eCurrentDiskMode i_DiskToMove)
        {
            bool isSuccessfullMove         = false;
            bool isRightTurn               = (IsBlackTurn && i_DiskToMove == eCurrentDiskMode.Black) || (!IsBlackTurn && i_DiskToMove == eCurrentDiskMode.White);
            bool isRightTurnAndNotGameOver = !GameOver && isRightTurn && addNewDiskToBoard(i_RowLocationToAddDiskOnBoard, i_ColumnLocationToAddDiskOnBoard, i_DiskToMove);

            if (isRightTurnAndNotGameOver)
            {
                isSuccessfullMove = !isSuccessfullMove;
                checkGameStatusAfterEndOfTurn();
                while (!GameOver && IsBlackTurn && m_PlayerTwo.IsPlayerComputer && !MinMaxSimulation)
                {
                    computerMakeMoveDecsion();
                }

                if (!m_IsMinMaxSimulation)
                {
                    if (IsBlackTurn && !m_PlayerTwo.IsPlayerComputer)
                    {
                        colorPossibleNextMove(eCurrentDiskMode.Black);
                    }
                    else if (!IsBlackTurn && !m_PlayerOne.IsPlayerComputer)
                    {
                        colorPossibleNextMove(eCurrentDiskMode.White);
                    }
                }
            }

            return(isSuccessfullMove);
        }