private Assembly Compile(bool fireChanged) { var assembly = base.Compile(); var types = assembly.GetTypes(); if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x))) { throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + "The problem definition must be a subclass of CompiledProblemDefinition."); } if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1) { throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + "Only one subclass of CompiledProblemDefinition is allowed."); } CompiledProblemDefinition inst; try { inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x))); } catch (Exception e) { compiledProblemDefinition = null; throw new ProblemDefinitionScriptException("Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e); } try { inst.vars = new Variables(VariableStore); inst.Initialize(); } catch (Exception e) { compiledProblemDefinition = null; throw new ProblemDefinitionScriptException("Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e); } try { compiledProblemDefinition = inst; if (fireChanged) { OnProblemDefinitionChanged(); } } catch (Exception e) { compiledProblemDefinition = null; throw new ProblemDefinitionScriptException("Using the problem definition in the problem failed." + Environment.NewLine + "Examine this error message carefully (often there is an issue with the defined encoding).", e); } codeChanged = false; return(assembly); }
protected override void OnCodeChanged() { base.OnCodeChanged(); compiledProblemDefinition = null; codeChanged = true; }
private Assembly Compile(bool fireChanged) { var assembly = base.Compile(); var types = assembly.GetTypes(); if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x))) throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + "The problem definition must be a subclass of CompiledProblemDefinition."); if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1) throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + "Only one subclass of CompiledProblemDefinition is allowed."); CompiledProblemDefinition inst; try { inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x))); } catch (Exception e) { compiledProblemDefinition = null; throw new ProblemDefinitionScriptException("Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e); } try { inst.vars = new Variables(VariableStore); inst.Initialize(); } catch (Exception e) { compiledProblemDefinition = null; throw new ProblemDefinitionScriptException("Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e); } try { compiledProblemDefinition = inst; if (fireChanged) OnProblemDefinitionChanged(); } catch (Exception e) { compiledProblemDefinition = null; throw new ProblemDefinitionScriptException("Using the problem definition in the problem failed." + Environment.NewLine + "Examine this error message carefully (often there is an issue with the defined encoding).", e); } codeChanged = false; return assembly; }
public SolveResult Solve(IProblemDefinition gridToSolve) { var iterativeSolver = new RecursiveSolver(gridToSolve.PossibilitiesSquareGrid); return iterativeSolver.Solve(gridToSolve.StartingKnownSquares); }