Ejemplo n.º 1
0
        public GameState(State s, Board b, Player p, GameState parent, Cell c, Boolean mp)
        {
            maxPlayer = mp;
            state = s;
            cell = c;
            board = b;
            player = p;
            this.parent = parent;
            children = new List<GameState>();
            Region.findConnectedCells(b);
            b.UpdateCellObservers();

            if(MiniMaxTree.TerminalTest(cell) && state != GameState.State.initial)
            {
                state = GameState.State.terminal;

                if (maxPlayer)
                {
                    heuristicValue = MiniMaxTree.MIN_VALUE;
                }
                else
                    heuristicValue = MiniMaxTree.MAX_VALUE;
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.Write("Board Width? ");
            colNum = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();

            Console.Write("Board Height? ");
            rowNum = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();

            Console.Write("Connect? ");
            r = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("1: Human vs Human");
            Console.WriteLine("2: Human vs AI");
            Console.WriteLine("3: AI vs AI");
            Console.Write("Select Players: ");
            int choice = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();

            Board board = new Board(rowNum, colNum, r);
            Region.findConnectedCells(board);
            board.UpdateCellObservers();

            Player p1 = null;
            Player p2 = null;

            switch (choice)
            {
                case 1:
                    p1 = new HumanPlayer();
                    p1.setAsRed();
                    p2 = new HumanPlayer();
                    p2.setAsBlack();
                    break;

                case 2:
                    Console.WriteLine("1: Human 2: AI");
                    Console.Write("Who will go first? ");
                    choice = Convert.ToInt32(Console.ReadLine());
                    if(choice == 1)
                    {
                        p1 = new HumanPlayer();
                        p1.setAsRed();
                        p2 = new AIPlayer();
                        p2.setAsBlack();
                    }
                    else
                    {
                        p1 = new AIPlayer();
                        p1.setAsRed();
                        p2 = new HumanPlayer();
                        p2.setAsBlack();
                    }
                    p1.setOpponent(p2);
                    p2.setOpponent(p1);
                    break;

                case 3:
                    break;

            }

            int turn = RED;

            while(!board.isGameOver())
            {
                switch (turn)
                {
                    case RED:
                        p1.Move(board);
                        turn = BLACK;
                        break;
                    case BLACK:
                        p2.Move(board);
                        turn = RED;
                        break;
                }
            }

            Console.Read();
        }