Esempio n. 1
0
        private int fullBoardCheck(GameBoard i_Board, GameEngien.ePlayers i_CurrenPlayer)
        {
            int       evalue = 0, o_NumOfBlackDiscs = 0, o_NumOfwhiteDiscs = 0;
            const int winForSure = 1000000000;

            i_Board.CalcPlayersScore(out o_NumOfBlackDiscs, out o_NumOfwhiteDiscs);

            if (o_NumOfBlackDiscs + o_NumOfwhiteDiscs == i_Board.Size * i_Board.Size)
            {
                if (o_NumOfBlackDiscs > o_NumOfwhiteDiscs && i_CurrenPlayer == GameEngien.ePlayers.FirstPlayer)
                {
                    evalue += winForSure;
                }
                else if (o_NumOfBlackDiscs > o_NumOfwhiteDiscs && i_CurrenPlayer == GameEngien.ePlayers.SecondPlayer)
                {
                    evalue -= winForSure;
                }
                else if (o_NumOfBlackDiscs < o_NumOfwhiteDiscs && i_CurrenPlayer == GameEngien.ePlayers.SecondPlayer)
                {
                    evalue += winForSure;
                }
                else
                {
                    evalue -= winForSure;
                }
            }

            return(evalue);
        }
Esempio n. 2
0
        private int subCheck(GameBoard i_Board, GameEngien.ePlayers i_CurrenPlayer)
        {
            int NumOfBlackDiscs = 0, NumOfwhiteDiscs = 0, SubOfDiscs = 0, evalue = 0;

            i_Board.CalcPlayersScore(out NumOfBlackDiscs, out NumOfwhiteDiscs);
            SubOfDiscs = NumOfBlackDiscs - NumOfwhiteDiscs;

            if (i_CurrenPlayer == GameEngien.ePlayers.FirstPlayer)
            {
                evalue += SubOfDiscs;
            }
            else
            {
                evalue -= SubOfDiscs;
            }

            return(evalue);
        }
Esempio n. 3
0
        public void StartGame()
        {
            bool restartGame = true;

            while (restartGame)
            {
                GameUi gameUi = new GameUi();
                gameUi.LaunchMenu();
                GameBoard       gameBoard = new GameBoard((int)gameUi.MatrixSize);
                Point           userCordInput;
                GameUi.ePlayers currentPlayer = GameUi.ePlayers.FirstPlayer;
                bool            continueGame = true;
                int             gameItrator = 0;
                int             thereNoOptionsForXPlayers = 0;
                List <Point>    moveOptions = null;
                bool            isLastTurnWasOk = true;
                int             player1Score = 0, player2Score = 0;
                while (continueGame)
                {
                    if (gameBoard.IsThereOptionsToPlay(currentPlayer, ref moveOptions))
                    {
                        if ((gameUi.GameMode == GameUi.eGameMode.PVc && currentPlayer == GameUi.ePlayers.SecondPlayer) || gameUi.GameMode == GameUi.eGameMode.CVc)
                        {
                            userCordInput = m_PcAi.AiTurn(gameBoard, currentPlayer);
                        }
                        else
                        {
                            gameBoard.CalcPlayersScore(out player1Score, out player2Score);
                            userCordInput = gameUi.NextTurn(gameBoard.CreatePrintingBoard(moveOptions), currentPlayer, isLastTurnWasOk, player1Score, player2Score);
                        }

                        if (gameBoard.TryAddDiscToLocation(userCordInput.x, userCordInput.y, (Disc.eColors)currentPlayer))
                        {
                            gameItrator++;
                            isLastTurnWasOk = true;
                        }
                        else
                        {
                            isLastTurnWasOk = false;
                        }

                        thereNoOptionsForXPlayers = 0;
                    }
                    else
                    {
                        thereNoOptionsForXPlayers++;
                        gameItrator++;
                    }

                    if (gameItrator % 2 == 0)
                    {
                        currentPlayer = GameUi.ePlayers.FirstPlayer;
                    }
                    else
                    {
                        currentPlayer = GameUi.ePlayers.SecondPlayer;
                    }

                    continueGame = thereNoOptionsForXPlayers < 2;
                }

                gameBoard.CalcPlayersScore(out player1Score, out player2Score);
                gameUi.GameOver(gameBoard.CreatePrintingBoard(moveOptions), player1Score, player2Score, ref restartGame);
            }
        }