private static void displayResult(SolverResult result, bool displayAll) { Console.WriteLine(); if (displayAll || result.ResultSequence.Count <= RESULT_STATES_PARTLY_DISPLAY_COUNT * 2) { foreach (var state in result.ResultSequence) { GridLogger.Log(result.Height, result.Width, state); } } else { for (int i = 0; i < RESULT_STATES_PARTLY_DISPLAY_COUNT; i++) { GridLogger.Log(result.Height, result.Width, result.ResultSequence[i]); } Console.WriteLine("."); Console.WriteLine("."); Console.WriteLine("."); Console.WriteLine("Other {0} states.", result.ResultSequence.Count - RESULT_STATES_PARTLY_DISPLAY_COUNT * 2); Console.WriteLine("."); Console.WriteLine("."); Console.WriteLine("."); for (int i = result.ResultSequence.Count - RESULT_STATES_PARTLY_DISPLAY_COUNT - 1; i < result.ResultSequence.Count; i++) { GridLogger.Log(result.Height, result.Width, result.ResultSequence[i]); } } }
/// <summary> /// Returns false if the input was wrong. /// </summary> public static bool ProcessUserInput(IInputMethod inputMethod, out SolverInput solverInputModel) { solverInputModel = null; int maxIterationsCount = 0; int width = 0; int height = 0; int[,] startState = null; int[,] finalState = null; try { Console.Write("Max iterations count: "); maxIterationsCount = Math.Abs(int.Parse(inputMethod.ReadLine())); Console.Write("Width: "); width = Math.Abs(int.Parse(inputMethod.ReadLine())); Console.Write("Height: "); height = Math.Abs(int.Parse(inputMethod.ReadLine())); startState = new int[height, width]; finalState = new int[height, width]; Console.WriteLine(); Console.WriteLine("Max iterations count: {0}", maxIterationsCount); Console.WriteLine("Width: {0}", width); Console.WriteLine("Height: {0}", height); Console.WriteLine(); Console.WriteLine("Insert the start state (line format - \"val1, val2, ...\" eg. 0, 1, 2):"); Console.WriteLine("Value {0} is the empty space.", Solver.EMPTY_SPACE_REPRESENTATION); processGridInput(inputMethod, width, height, startState); Console.WriteLine(); GridLogger.Log(width, height, startState.Convert2dArray2Sequence()); Console.WriteLine("Insert the final state:"); processGridInput(inputMethod, width, height, finalState); Console.WriteLine(); GridLogger.Log(width, height, finalState.Convert2dArray2Sequence()); } catch (Exception e) { Console.WriteLine(string.Format("Error: {0}", e.Message)); return(false); } solverInputModel = new SolverInput(maxIterationsCount, width, height, startState, finalState); return(true); }