예제 #1
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);
        }
예제 #2
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;
            }
        }
예제 #3
0
        public void StartNextRound()
        {
            m_IsBlackTurn = false;
            m_IsGameOver  = false;
            int middleOfBoard = BoardLength / 2;

            for (int i = 1; i <= BoardLength; i++)
            {
                for (int j = 1; j <= BoardLength; j++)
                {
                    this[i, j] = new OthelloGameDisk(eCurrentDiskMode.NotExist);
                }
            }

            this[middleOfBoard, middleOfBoard]         = new OthelloGameDisk(eCurrentDiskMode.White);
            this[middleOfBoard + 1, middleOfBoard]     = new OthelloGameDisk(eCurrentDiskMode.Black);
            this[middleOfBoard + 1, middleOfBoard + 1] = new OthelloGameDisk(eCurrentDiskMode.White);
            this[middleOfBoard, middleOfBoard + 1]     = new OthelloGameDisk(eCurrentDiskMode.Black);
        }