Example #1
0
        public static GameAIAbstract GetGameAI(GameAIType AIType, TicTacToeBoard board)
        {
            GameAIAbstract ai = null;

            switch (AIType)
            {
            case GameAIType.Simple1:
                ai = new GameAISimple1(board);
                break;

            case GameAIType.Simple2:
                ai = new GameAISimple2(board);
                break;

            case GameAIType.Position:
                ai = new GameAIPosition(board);
                break;

            case GameAIType.Static1:
                ai = new GameAIStatic1(board);
                break;

            case GameAIType.Rule:
                ai = new GameAIRule(board);
                break;

            case GameAIType.Minimax:
                ai = new GameAIMinimax(board);
                break;
            }

            return(ai);
        }
Example #2
0
        public TicTacToeBoard(TicTacToeBoard otherBoard)
        {
            board = new TicTacToeSign[3, 3];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    board[i, j] = otherBoard.GetSign(i, j);
                }
            }
        }
Example #3
0
        private int PlayMax(TicTacToeBoard prevBoard, TicTacToeSign sign)
        {
            int max = -1;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (prevBoard.CorrectMove(i, j))
                    {
                        TicTacToeBoard newBoard = new TicTacToeBoard(prevBoard);
                        newBoard.SetSign(i, j, sign);

                        Steps++;

                        TicTacToeResult result = newBoard.Winner();

                        if (result != TicTacToeResult.None)
                        {
                            if (result == TicTacToeResult.Draw)
                            {
                                if (max < 0)
                                {
                                    max = 0;
                                }
                            }
                            else
                            {
                                max = 1;
                            }
                        }
                        else
                        {
                            int max1 = PlayMin(newBoard, TicTacToeHelper.Opponent(sign));

                            if (max1 > max)
                            {
                                max = max1;
                            }
                        }
                    }
                }
            }

            return(max);
        }
Example #4
0
 public GameAISimple1(TicTacToeBoard board)
     : base(board)
 {
 }
Example #5
0
 public GameAIAbstract(TicTacToeBoard board)
 {
     this.board = board;
     this.steps = 0;
 }
Example #6
0
 public GameAIMinimax(TicTacToeBoard board)
     : base(board)
 {
     BestResult = 0;
 }
Example #7
0
        public override bool GetNextMove(TicTacToeSign sign, out int row, out int column)
        {
            row    = -1;
            column = -1;

            Steps = 0;
            int max = -1;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (board.CorrectMove(i, j))
                    {
                        TicTacToeBoard newBoard = new TicTacToeBoard(board);
                        newBoard.SetSign(i, j, sign);

                        Steps++;

                        TicTacToeResult result = newBoard.Winner();

                        if (result != TicTacToeResult.None)
                        {
                            if (result == TicTacToeResult.Draw)
                            {
                                if (max < 0)
                                {
                                    max    = 0;
                                    row    = i;
                                    column = j;
                                }
                            }
                            else
                            {
                                max    = 1;
                                row    = i;
                                column = j;
                            }
                        }
                        else
                        {
                            int max1 = PlayMin(newBoard, TicTacToeHelper.Opponent(sign));

                            if (max1 > max)
                            {
                                max    = max1;
                                row    = i;
                                column = j;
                            }
                        }
                    }
                }
            }

            Debug.WriteLine(String.Format("Sor: {0} Oszlop: {1} Érték: {2} Vizsgálatok: {3}", row, column, max, Steps));
            // MessageBox.Show(String.Format("Sor: {0} Oszlop: {1} Érték: {2} Vizsgálatok: {3}", row, column, max, count));

            BestResult = max;

            return(row != -1);
        }
Example #8
0
 public GameAIPosition(TicTacToeBoard board)
     : base(board)
 {
 }
Example #9
0
 public GameAIStatic1(TicTacToeBoard board)
     : base(board)
 {
 }
Example #10
0
 public GameAIRule(TicTacToeBoard board)
     : base(board)
 {
 }