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(); } } }
public MoveNode[] expandNodes(Grid board, MoveNode last, int ply) { List <MoveNode> nodes = new List <MoveNode>(); List <Group> moves = board.calculateGroups(); foreach (Group move in moves) { Grid b = board.copy(); if (b.checkMove(move.X, move.Y)) { b.removeGroup(move.X, move.Y); b.compressGrid(); nodes.Add(new MoveNode(move, rankGrid(b), ply, b, last)); } } return(nodes.ToArray()); }
public List <Group> calculateGroups() { Grid temp = this.copy(); List <Group> result = new List <Group>(); for (int x = 1; x <= this.x; x++) { for (int y = 1; y <= this.x; y++) { if (temp.grid[x, y] != "E") { int count = temp.currentRemoved; temp.removeGroup(x, y); count = temp.currentRemoved - count; result.Add(new Group(x, y, count)); } } } return(result); }
public PriorityQueue <Group> calculateGroupsQueue() { Grid temp = this.copy(); PriorityQueue <Group> result = new PriorityQueue <Group>(); for (int x = 1; x <= this.x; x++) { for (int y = 1; y <= this.x; y++) { if (temp.grid[x, y] != "E") { int count = temp.currentRemoved; temp.removeGroup(x, y); count = temp.currentRemoved - count; result.Enqueue(new Group(x, y, count)); } } } return(result); }
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(); } } }
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(); } } }
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(); } } }