public LightsOut(int N) { this.N = N; LightsMatrix = new Light[N, N]; Init(); ConnectNodes(); cnt = 0; }
private void ToggleLightAdjecent(Light light) { if (light != null) { ToggleLight(light); } }
private void ToggleLight(Light light) { light.Switch = (light.Switch == Switch.Off ? Switch.On : Switch.Off); }
private void Init() { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { LightsMatrix[i, j] = new Light() { Switch = Switch.Off, Row = i, Column = j, }; } } }
//compare two Martix of lights private bool CompareMatrixes(Light[,] firtsdMatrix, Light[,] secondMatrix) { for(int i = 0; i< N; i++) for (int j = 0; j < N; j++) if(firtsdMatrix[i,j] != secondMatrix[i,j]) return false; return true; }
private static bool SolveLightsOut(Light[,] LightsArray, int N) { LightsOutSolver.InitLightsOutSolver(N); return LightsOutSolver.solve(ConvertLightsToInt(LightsArray, N)); }
private static int[][] ConvertLightsToInt(Light[,] lightsArray, int N) { int[][] arr = new int[N][]; for (int i = 0; i < N; i++) arr[i] = new int[N]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) arr[i][j] = (lightsArray[i, j].Switch == Switch.Off ? 0 : 1); return arr; }