示例#1
0
        public static void newGame(Grid game)
        {
            bool GameLoop = true;

            while (GameLoop)
            {
                game.displayGrid();
                Console.Write("Enter Move ( as 'x y' ): ");
                string   move  = Console.ReadLine();
                string[] coord = move.Split(' ');
                Int32    val;
                if ((coord.Length == 2) && (Int32.TryParse(coord[0], out val) && Int32.TryParse(coord[1], out val)) && game.checkMove(Int32.Parse(coord[0]), Int32.Parse(coord[1])))
                {
                    game.removeGroup(Int32.Parse(coord[0]), Int32.Parse(coord[1]));
                    game.Logger.addLog("MOVE: (" + coord[0] + "," + coord[1] + ")");
                    game.Logger.addLog("      --Points: " + game.calculatePoints());
                }
                else
                {
                    Console.WriteLine("Invalid Move! Try again!");
                }

                game.compressGrid();

                if (game.checkWin())
                {
                    GameLoop = false;
                    Console.WriteLine("You Win!");
                    game.Logger.addLog("GAME WIN: All bubbles eliminated");
                    game.Logger.addLog("FINAL POINTS: " + game.Points);
                    game.Logger.close();
                    Console.ReadLine();
                }
                else if (game.checkLocked())
                {
                    GameLoop = false;
                    //display final game board showing locked game
                    game.displayGrid();
                    Console.WriteLine("You Lose!");
                    game.Logger.addLog("GAME LOSS: Gameboard locked!");
                    game.Logger.addLog("FINAL POINTS: " + game.Points);
                    game.Logger.close();
                    Console.ReadLine();
                }
            }
        }
示例#2
0
        public double rankGrid(Grid board)
        {
            double rank    = 0;
            int    largest = 0;

            PriorityQueue <Group> moves = board.calculateGroupsQueue();

            if (!moves.isEmpty)
            {
                largest = moves.Dequeue().Bubbles;
            }

            int groups    = 0;
            int singles   = 0;
            int remaining = 0;

            while (!(moves.isEmpty) && (moves.Peek().Bubbles > 1))
            {
                groups++;
                remaining += moves.Dequeue().Bubbles;
            }

            singles    = moves.Count;
            remaining += singles;

            if (board.checkWin())
            {
                rank = (board.X * board.X) * 1000;
            }
            else if (board.checkLocked())
            {
                rank = 0 - singles;
            }
            else
            {
                rank = (remaining - singles) + largest;
            }


            return(rank);
        }
示例#3
0
        public static void newAIGame(Grid game)
        {
            bool             GameLoop = true;
            bool             list     = false;
            AI               blue     = new AI(50);
            Stack <MoveNode> moves    = new Stack <MoveNode>();

            if ((game.Colors <= 5 && game.X < 7) || (game.Colors < 4 && game.X <= 15))
            {
                MoveNode move = blue.solveTree(game);
                if (move != null)
                {
                    list = true;

                    while (move != null)
                    {
                        moves.Push(move);
                        move = move.PreviousMove;
                    }
                }
            }

            while (GameLoop)
            {
                int[] nextMove;
                game.displayGrid();



                if (list)
                {
                    nextMove = new int[2];
                    MoveNode cur = moves.Pop();
                    nextMove[0] = cur.Group.X;
                    nextMove[1] = cur.Group.Y;
                }
                else
                {
                    nextMove = blue.makeNextMove(game);
                }

                Console.WriteLine("AI makes the move (" + nextMove[0] + ", " + nextMove[1] + ")");

                game.removeGroup(nextMove[0], nextMove[1]);
                game.Logger.addLog("MOVE: (" + nextMove[0] + "," + nextMove[1] + ")");
                game.Logger.addLog("      --Points: " + game.calculatePoints());

                game.compressGrid();

                if (game.checkWin())
                {
                    GameLoop = false;
                    Console.WriteLine("You Win!");
                    game.Logger.addLog("GAME WIN: All bubbles eliminated");
                    game.Logger.addLog("FINAL POINTS: " + game.Points);
                    game.Logger.close();
                    Console.ReadLine();
                }
                else if (game.checkLocked())
                {
                    GameLoop = false;
                    //display final game board showing locked game
                    game.displayGrid();
                    Console.WriteLine("You Lose!");
                    game.Logger.addLog("GAME LOSS: Gameboard locked!");
                    game.Logger.addLog("FINAL POINTS: " + game.Points);
                    game.Logger.close();
                    Console.ReadLine();
                }
            }
        }
示例#4
0
        public double rankGrid(Grid board)
        {
            double rank = 0;
            int largest = 0;

            PriorityQueue<Group> moves = board.calculateGroupsQueue();
            if(!moves.isEmpty)
                largest = moves.Dequeue().Bubbles;

            int groups = 0;
            int singles = 0;
            int remaining = 0;

            while (!(moves.isEmpty) && (moves.Peek().Bubbles > 1))
            {
                groups++;
                remaining += moves.Dequeue().Bubbles;
            }

            singles = moves.Count;
            remaining += singles;

             if(board.checkWin())
             	rank = (board.X * board.X) *1000;
             else if (board.checkLocked())
             	rank  = 0 - singles;
             else
             	rank = (remaining - singles) + largest;

              	return rank;
        }
示例#5
0
        public static void newGame(Grid game)
        {
            bool GameLoop = true;

            while (GameLoop)
            {
                game.displayGrid();
                Console.Write("Enter Move ( as 'x y' ): ");
                string move = Console.ReadLine();
                string[] coord = move.Split(' ');
                Int32 val;
                if((coord.Length==2) && (Int32.TryParse(coord[0], out val) && Int32.TryParse(coord[1], out val)) && game.checkMove(Int32.Parse(coord[0]), Int32.Parse(coord[1]))) {

                    game.removeGroup(Int32.Parse(coord[0]), Int32.Parse(coord[1]));
                    game.Logger.addLog("MOVE: (" + coord[0] + "," + coord[1] + ")");
                    game.Logger.addLog("      --Points: " + game.calculatePoints());

                } else
                {
                    Console.WriteLine("Invalid Move! Try again!");
                }

                game.compressGrid();

                if (game.checkWin())
                {
                    GameLoop = false;
                    Console.WriteLine("You Win!");
                    game.Logger.addLog("GAME WIN: All bubbles eliminated");
                    game.Logger.addLog("FINAL POINTS: " + game.Points);
                    game.Logger.close();
                    Console.ReadLine();
                } else if (game.checkLocked())
                {
                    GameLoop = false;
                    //display final game board showing locked game
                    game.displayGrid();
                    Console.WriteLine("You Lose!");
                    game.Logger.addLog("GAME LOSS: Gameboard locked!");
                    game.Logger.addLog("FINAL POINTS: " + game.Points);
                    game.Logger.close();
                    Console.ReadLine();
                }
            }
        }
示例#6
0
        public static void newAIGame(Grid game)
        {
            bool GameLoop = true;
            bool list  = false;
            AI blue = new AI(50);
            Stack<MoveNode> moves = new Stack<MoveNode>();

            if((game.Colors <= 5 && game.X <7) || (game.Colors < 4 && game.X <= 15))
            {
               		MoveNode move = blue.solveTree(game);
               		if(move != null)
               		{
               			list = true;

               			while(move != null)
               			{
               				moves.Push(move);
               				move = move.PreviousMove;
               			}

               		}
            }

            while (GameLoop)
            {
                int[] nextMove;
                game.displayGrid();

                if(list)
                {
                    nextMove = new int[2];
                    MoveNode cur = moves.Pop();
                    nextMove[0] = cur.Group.X;
                    nextMove[1] = cur.Group.Y;

                }
                else
                {
                    nextMove = blue.makeNextMove(game);
                }

                Console.WriteLine("AI makes the move (" + nextMove[0] + ", " + nextMove[1] + ")");

                game.removeGroup(nextMove[0], nextMove[1]);
                game.Logger.addLog("MOVE: (" + nextMove[0] + "," + nextMove[1] + ")");
                game.Logger.addLog("      --Points: " + game.calculatePoints());

                game.compressGrid();

                if (game.checkWin())
                {
                    GameLoop = false;
                    Console.WriteLine("You Win!");
                    game.Logger.addLog("GAME WIN: All bubbles eliminated");
                    game.Logger.addLog("FINAL POINTS: " + game.Points);
                    game.Logger.close();
                    Console.ReadLine();
                }
                else if (game.checkLocked())
                {
                    GameLoop = false;
                    //display final game board showing locked game
                    game.displayGrid();
                    Console.WriteLine("You Lose!");
                    game.Logger.addLog("GAME LOSS: Gameboard locked!");
                    game.Logger.addLog("FINAL POINTS: " + game.Points);
                    game.Logger.close();
                    Console.ReadLine();
                }
            }
        }