示例#1
0
        private void computerTurn()
        {
            AILogic ai              = new AILogic();
            Random  rand            = new Random();
            int     colToBeInserted = 0;
            int     numOfCols       = m_Game.GetNumOfCols();

            //// Column choosed.
            colToBeInserted = ai.AIManager(this.m_Game);

            while (!ValidateColumn(colToBeInserted))
            {
                /// Column choosed.
                /// We left the rand here, as a "Fail-Safe" procedure . please pay attion for this point.

                colToBeInserted = rand.Next(0, numOfCols);
            }

            //// only if a legal column....(have to a legal one at this point..^^^^)
            InsertChip(new Chip(ePlayerNum.Computer), colToBeInserted);
            Screen.Clear();
            PrintBoard();

            if (CheckForAWin(colToBeInserted, ePlayerNum.Computer, true))
            {
                this.m_Game.IncreasePointsByOne(ePlayerNum.Computer);
                this.m_Game.LastRoundWinner = ePlayerNum.Computer;

                this.PrintGameStatus();

                exitMenu(ePlayerNum.Player1);

                this.clearBoard();
            }
            else
            {
                ////Tie - because if the other player has won - it should dealt in his turn.
            }
        }
示例#2
0
        private void computerTurn()
        {
            AILogic ai              = new AILogic();
            Random  rand            = new Random();
            int     colToBeInserted = 0;
            int     numOfCols       = m_GameManager.GetNumOfCols();

            //// Column choosed.
            colToBeInserted = ai.AIManager(this.m_GameManager);

            // $G$ NTT-002 (-10) You shouldn't use while for game routin. WinForm project is events oriented.
            while (!ValidateColumn(colToBeInserted))
            {
                /// Column choosed.
                /// We left the rand here, as a "Fail-Safe" procedure . please pay attion for this point.

                // $G$ DSN-002 (-20) No UI seperation! This class merge the Logic board with the Visual board (UserControl) of the game...
                colToBeInserted = rand.Next(0, numOfCols);
            }

            insertSelection(colToBeInserted, ePlayerNum.Computer);

            updateButtonsAvailability();
        }