Przeglądaj źródła

fix: code cleanup, bug fix

RaZe 3 lat temu
rodzic
commit
a0395aedec
3 zmienionych plików z 10 dodań i 21 usunięć
  1. 0 1
      rubiks_cube_scrambler.c
  2. 10 17
      scrambler.c
  3. 0 3
      scrambler.h

+ 0 - 1
rubiks_cube_scrambler.c

@@ -54,7 +54,6 @@ static void draw_callback(Canvas *canvas, void *ctx)
     {
         genScramble();
         scrambleReplace();
-        valid();
         strcpy(scramble_str, printData());
         if (notifications_enabled)
         {

+ 10 - 17
scrambler.c

@@ -59,8 +59,8 @@ void scrambleReplace()
     // Initialize the mainScramble array with all the possible moves
     for (int i = 0; i < SLEN; i++)
     {
-        a.mainScramble[i][0] = moves[getRand(6, 0)];
-        a.mainScramble[i][1] = dir[getRand(3, 0)];
+        a.mainScramble[i][0] = moves[furi_hal_random_get() % 6];
+        a.mainScramble[i][1] = dir[furi_hal_random_get() % 3];
     }
 
     // Perform the Fisher-Yates shuffle
@@ -76,28 +76,21 @@ void scrambleReplace()
     // Select the first 10 elements as the scramble, using only the first three elements of the dir array
     for (int i = 0; i < SLEN; i++)
     {
-        a.mainScramble[i][1] = dir[rand() % 3];
+        a.mainScramble[i][1] = dir[furi_hal_random_get() % 3];
+    }
+     for (int i = 1; i < SLEN; i++) {
+        while ( a.mainScramble[i][0] == a.mainScramble[i - 2][0] || a.mainScramble[i][0] == a.mainScramble[i - 1][0]) {
+            a.mainScramble[i][0] = moves[furi_hal_random_get()%5];
+        }
     }
 }
 
 
 
 
-void valid() {
-    for (int i = 2; i < SLEN; i++) {
-        while ( a.mainScramble[i][0] == a.mainScramble[i - 2][0] || a.mainScramble[i][0] == a.mainScramble[i - 1][0]) {
-            a.mainScramble[i][0] = moves[rand()%5];
-        }
-    }
-    // Scramble generation complete
-}
 
-int getRand(int upr, int lwr)
-{
-	int randNum;
-	randNum = (rand() % (upr - lwr + 1)) + lwr;
-	return randNum;
-}
+
+
 // Let this function be here for now till I find out what is causing the extra space bug in the scrambles
 void remove_double_spaces(char *str) {
   int i, j;

+ 0 - 3
scrambler.h

@@ -1,6 +1,3 @@
 void scrambleReplace ();
 void genScramble ();
-void valid ();
-int getRand (int upr,int lwr);
 char *printData ();
-void writeToFile ();