// Requires args[0] to be the path of a valid input file static void Main(string[] args) { HueDrop problem = new HueDrop( new StreamReader(new FileStream(args[0], FileMode.Open))); int numMoves = 0; while (numMoves <= moveLimit) { char nextColour = findNextColour(problem); Console.Write(nextColour.ToString() + " "); if (problem.checkColour(nextColour)) { break; } numMoves++; } Console.Write("\n"); if (numMoves > moveLimit) { Console.WriteLine("No solution found"); } problem.printBoard(); Console.ReadLine(); }
public HueDrop(HueDrop original) { target = original.target; height = original.getDimensions()[0]; width = original.getDimensions()[1]; board = new char[height][]; for (int row = 0; row < height; row++) { board[row] = new char[width]; for (int col = 0; col < width; col++) { board[row][col] = original.getBoard()[row][col]; } } }
private static char findNextColour(HueDrop game) { char originColour = game.getBoard()[0][0]; List <int[]> leafTiles = new List <int[]>(); Stack <int[]> toCheck = new Stack <int[]>(); List <int[]> visited = new List <int[]>(); toCheck.Push(new [] { 0, 0 }); while (toCheck.Count != 0) { int[] current = toCheck.Pop(); Dictionary <int[], char> adj = game.adjTiles(current.ToList()); game.getBoard()[current[0]][current[1]] = 'X'; foreach (int[] coord in adj.Keys) { if (adj[coord] == originColour) { toCheck.Push(coord); visited.Add(coord); } } } Dictionary <char, int> leafColours = new Dictionary <char, int>(); foreach (char colour in colourList) { HueDrop currGame = new HueDrop(game); currGame.changeColour(colour); leafColours.Add(colour, currGame.changeColour('X')); } int max = game.changeColour(game.target); char maxCol = game.target; foreach (char colour in leafColours.Keys) { if (leafColours[colour] > max) { max = leafColours[colour]; maxCol = colour; } } return(maxCol); }