예제 #1
0
        private int aiMinMaxAlgorithm(int i_Depth, out int o_RowOfBestMove, out int o_ColumnOfBestMove, OthelloGameLogic i_TheGameForNextMove)
        {
            o_RowOfBestMove    = -1;
            o_ColumnOfBestMove = -1;
            int rowOfBestMove    = -1;
            int columnOfBestMove = -1;
            int returnMaxScore   = int.MinValue;
            int blackScore;
            int whiteScore;
            int currentScoreFromRecursiveMove;
            OthelloGameLogic theNextLevelBoard;

            if (!i_TheGameForNextMove.GameOver)
            {
                for (int row = 1; row <= BoardLength; row++)
                {
                    for (int column = 1; column <= BoardLength; column++)
                    {
                        bool isLegalPosition = i_TheGameForNextMove.isLegalPositionForNewDisk(row, column, i_TheGameForNextMove.IsBlackTurn ? eCurrentDiskMode.Black : eCurrentDiskMode.White);
                        if (isLegalPosition)
                        {
                            theNextLevelBoard = new OthelloGameLogic(i_TheGameForNextMove);
                            theNextLevelBoard.MinMaxSimulation = true;

                            if (theNextLevelBoard.IsBlackTurn)
                            {
                                theNextLevelBoard.BlackMakeMove(row, column);
                            }
                            else
                            {
                                theNextLevelBoard.WhiteMakeMove(row, column);
                            }

                            theNextLevelBoard.CalculateScore(out blackScore, out whiteScore);
                            currentScoreFromRecursiveMove = blackScore - whiteScore;

                            if (i_Depth == 0 || theNextLevelBoard.GameOver)
                            {
                                o_RowOfBestMove    = row;
                                o_ColumnOfBestMove = column;
                            }
                            else
                            {
                                currentScoreFromRecursiveMove = aiMinMaxAlgorithm(i_Depth - 1, out rowOfBestMove, out columnOfBestMove, theNextLevelBoard);
                            }

                            if (currentScoreFromRecursiveMove > returnMaxScore)
                            {
                                returnMaxScore     = currentScoreFromRecursiveMove;
                                o_RowOfBestMove    = row;
                                o_ColumnOfBestMove = column;
                            }
                        }
                    }
                }
            }

            return(returnMaxScore);
        }
예제 #2
0
 // Constructor - the game form which runs a whole single game and computes the final score.
 public OthelloMainGameForm(bool i_VsHuman, int i_BoardSize)
 {
     r_BoardSize = i_BoardSize;
     r_VsHuman = i_VsHuman;
     m_MainOthelloLogic = new OthelloGameLogic(r_BoardSize, r_VsHuman);
     initMainOthelloForm();
     m_MainOthelloLogic.InitializeDefualtPoints();
     updateBoardButtons();
     this.ShowDialog();
 }
예제 #3
0
        public OthelloGameLogic(OthelloGameLogic i_GameToCopy)
        {
            r_BoardLength         = i_GameToCopy.r_BoardLength;
            m_IsGameOver          = i_GameToCopy.m_IsGameOver;
            m_IsBlackTurn         = i_GameToCopy.m_IsBlackTurn;
            m_PlayerOne           = i_GameToCopy.m_PlayerOne;
            m_PlayerTwo           = i_GameToCopy.m_PlayerTwo;
            m_TheOthelloBoardGame = new OthelloGameDisk[r_BoardLength, r_BoardLength];

            for (int row = 1; row <= r_BoardLength; row++)
            {
                for (int column = 1; column <= r_BoardLength; column++)
                {
                    this[row, column] = i_GameToCopy[row, column];
                }
            }
        }