예제 #1
0
        private int maxMin(GameBoard i_Board, GameEngien.ePlayers i_CurrenPlayer, int i_Depht, int i_MaxDeapth)
        {
            if (i_Depht == i_MaxDeapth)
            {
                return(evaluation(i_Board, i_CurrenPlayer));
            }
            else
            {
                List <Point>        moveOptions     = null;
                List <int>          sonsEvaluations = new List <int>();
                GameEngien.ePlayers OtherPlayer;

                if (i_CurrenPlayer == GameEngien.ePlayers.FirstPlayer)
                {
                    OtherPlayer = GameEngien.ePlayers.SecondPlayer;
                }
                else
                {
                    OtherPlayer = GameEngien.ePlayers.FirstPlayer;
                }

                if (i_Board.IsThereOptionsToPlay(i_CurrenPlayer, ref moveOptions))
                {
                    foreach (Point location in moveOptions)
                    {
                        sonsEvaluations.Add(maxMin(i_Board.BoardDuplicatewithNewPoint(i_Board, location, i_CurrenPlayer), OtherPlayer, i_Depht + 1, i_MaxDeapth));
                    }

                    if (i_Depht % 2 == 1)
                    {
                        return(returnMaxInt(sonsEvaluations));
                    }
                    else
                    {
                        return(returnMinInt(sonsEvaluations));
                    }
                }
                else
                {
                    return(0);
                }
            }
        }
예제 #2
0
        public Point AiTurn(GameBoard i_Board, GameEngien.ePlayers i_CurrenPlayer)
        {
            GameEngien.ePlayers OtherPlayer;
            Point        returnTurn      = null;
            List <Point> moveOptions     = null;
            List <int>   sonsEvaluations = new List <int>();

            if (i_CurrenPlayer == GameEngien.ePlayers.FirstPlayer)
            {
                OtherPlayer = GameEngien.ePlayers.SecondPlayer;
            }
            else
            {
                OtherPlayer = GameEngien.ePlayers.FirstPlayer;
            }

            if (i_Board.IsThereOptionsToPlay(i_CurrenPlayer, ref moveOptions))
            {
                foreach (Point location in moveOptions)
                {
                    sonsEvaluations.Add(maxMin(i_Board.BoardDuplicatewithNewPoint(i_Board, location, i_CurrenPlayer), OtherPlayer, 1, 6));
                }
            }

            int maxvalue = returnMaxInt(sonsEvaluations);

            for (int i = 0; i < sonsEvaluations.Count; i++)
            {
                if (sonsEvaluations[i] == maxvalue)
                {
                    returnTurn = moveOptions[i];
                }
            }

            return(returnTurn);
        }
예제 #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);
            }
        }