Skip to content

Commit

Permalink
fix: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
RaZeSloth committed Jan 15, 2023
1 parent 9f8dbeb commit 710b08f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 58 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 @@ -53,7 +53,6 @@ static void draw_callback(Canvas *canvas, void *ctx)

if (scrambleStarted)
{
genScramble();
scrambleReplace();
strcpy(scramble_str, printData());
if (notifications_enabled)
Expand Down
63 changes: 7 additions & 56 deletions src/rubiks_cube_scrambler/scrambler.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,65 +12,37 @@ Authors: Tanish Bhongade and RaZe

// 6 moves along with direction
char moves[6] = {'R', 'U', 'F', 'B', 'L', 'D'};
char dir[4] = {' ', '\'', '2'};
char dir[4] = {'\'', '2'};
const int32_t SLEN = 20;
#define RESULT_SIZE 100
// Structure which holds main scramble

struct GetScramble
{
char mainScramble[25][3];
};
struct GetScramble a; // Its object

// Function prototypes to avoid bugs
void scrambleReplace();
void genScramble();
char *printData();

// Main function
/* int main(){
genScramble ();//Calling genScramble
scrambleReplace();//Calling scrambleReplace
valid();//Calling valid to validate the scramble
printData ();//Printing the final scramble
//writeToFile();//If you want to write to a file, please uncomment this
struct GetScramble a;

return 0;
} */

void genScramble()
{
// Stage 1
for (int32_t i = 0; i < SLEN; i++)
{
strcpy(a.mainScramble[i], "00");
}
// This makes array like this 00 00 00.......
}

void scrambleReplace()
{
// Stage 2
// Actual process begins here

// Initialize the mainScramble array with all the possible moves
for (int32_t i = 0; i < SLEN; i++)
{
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
/* // Perform the Fisher-Yates shuffle
for (int32_t i = 6 - 1; i > 0; i--)
{
int32_t j = rand() % (i + 1);
char temp[3];
strcpy(temp, a.mainScramble[i]);
strcpy(a.mainScramble[i], a.mainScramble[j]);
strcpy(a.mainScramble[j], temp);
}
} */

// Select the first 10 elements as the scramble, using only the first three elements of the dir array
// Select the first 10 elements as the scramble, using only the first two elements of the dir array
for (int32_t i = 0; i < SLEN; i++)
{
a.mainScramble[i][1] = dir[furi_hal_random_get() % 3];
Expand All @@ -82,24 +54,6 @@ void scrambleReplace()
}
}







// 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) {
int32_t i, j;
int32_t len = strlen(str);
for (i = 0, j = 0; i < len; i++, j++) {
if (str[i] == ' ' && str[i + 1] == ' ') {
i++;
}
str[j] = str[i];
}
str[j] = '\0';
}
char *printData()
{
static char result[RESULT_SIZE];
Expand All @@ -108,8 +62,5 @@ char *printData()
{
offset += snprintf(result + offset, RESULT_SIZE - offset, "%s ", a.mainScramble[loop]);
}
remove_double_spaces(result);
return result;
}


}
1 change: 0 additions & 1 deletion src/rubiks_cube_scrambler/scrambler.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
void scrambleReplace ();
void genScramble ();
char *printData ();

0 comments on commit 710b08f

Please sign in to comment.