Skip to content

Commit

Permalink
fix: code cleanup, bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RaZeSloth committed Jan 12, 2023
1 parent c9d2041 commit 556497a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/rubiks_cube_scrambler/rubiks_cube_scrambler.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ static void draw_callback(Canvas *canvas, void *ctx)
{
genScramble();
scrambleReplace();
valid();
strcpy(scramble_str, printData());
if (notifications_enabled)
{
Expand Down
27 changes: 10 additions & 17 deletions src/rubiks_cube_scrambler/scrambler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/rubiks_cube_scrambler/scrambler.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
void scrambleReplace ();
void genScramble ();
void valid ();
int getRand (int upr,int lwr);
char *printData ();
void writeToFile ();

0 comments on commit 556497a

Please sign in to comment.