Example #1
0
 public LightsOut(int N)
 {
     this.N = N;
     LightsMatrix = new Light[N, N];
     Init();
     ConnectNodes();
     cnt = 0;
 }
Example #2
0
 private void ToggleLightAdjecent(Light light)
 {
     if (light != null)
     {
         ToggleLight(light);
     }
 }
Example #3
0
 private void ToggleLight(Light light)
 {
     light.Switch = (light.Switch == Switch.Off ? Switch.On : Switch.Off);
 }
Example #4
0
 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,
             };
         }
     }
 }
Example #5
0
 //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;
 }
Example #6
0
        private static bool SolveLightsOut(Light[,] LightsArray, int N)
        {
            LightsOutSolver.InitLightsOutSolver(N);

            return LightsOutSolver.solve(ConvertLightsToInt(LightsArray, N));
        }
Example #7
0
        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;
        }