From 40352f018b29e8aea9a804dd1240ea8374c39db8 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 20 Jul 2020 10:22:28 +0200 Subject: Added more scramble options, scramble doc --- README.md | 7 +++---- compile.sh | 1 + docs/scramble.txt | 22 ++++++++++++++++++++++ nissy | Bin 518520 -> 520584 bytes src/compile.sh | 1 - src/main.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 6 files changed, 65 insertions(+), 14 deletions(-) create mode 100755 compile.sh create mode 100644 docs/scramble.txt delete mode 100755 src/compile.sh diff --git a/README.md b/README.md index 581f36c..1278b31 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,12 @@ compiler to use the [C99 standard](https://en.wikipedia.org/wiki/C99). For example, on a Linux system with GCC installed: ``` -cd path/to/nissy/src -gcc -O3 -std=c99 -o ../nissy *.c -cd .. +cd path/to/nissy +gcc -O3 -std=c99 -o nissy ./src/*.c ./nissy ``` -You can also use the script compile.sh in the src folder, which executes that +You can also use the script compile.sh, which executes that gcc line (with a few extra options). ## Tips diff --git a/compile.sh b/compile.sh new file mode 100755 index 0000000..4e14a0b --- /dev/null +++ b/compile.sh @@ -0,0 +1 @@ +gcc -Wall -Wextra -O3 -std=c99 -o nissy -g ./src/*.c diff --git a/docs/scramble.txt b/docs/scramble.txt new file mode 100644 index 0000000..dad8ba7 --- /dev/null +++ b/docs/scramble.txt @@ -0,0 +1,22 @@ + +HELP PAGE FOR COMMAND scramble + +SYNTAX +scramble [OPTIONS] + +DESCRIPTION +Produces a random-state scramble. There are options to get a corners-only, +edges-only or dr-state scramble. + +OPTIONS +c Scrambles corners only (edges are solved). +e Scrambles edges only (corners are solved). +dr DR-state scramble. The DR is always on the U/D axis. + + +EXAMPLES +scramble + Gives a random-state scramble +scramble dr + Gives a random-DR-state scramble + diff --git a/nissy b/nissy index 2ff6c82..2265a77 100755 Binary files a/nissy and b/nissy differ diff --git a/src/compile.sh b/src/compile.sh deleted file mode 100755 index 49d655e..0000000 --- a/src/compile.sh +++ /dev/null @@ -1 +0,0 @@ -gcc -Wall -Wextra -O3 -std=c99 -o ../nissy -g *.c diff --git a/src/main.c b/src/main.c index 125e4ec..d68f4af 100644 --- a/src/main.c +++ b/src/main.c @@ -12,8 +12,8 @@ char *commands[][10] = { {"help", "[COMMAND]", "Print this help, or a help page for COMMAND."}, - {"scramble", "", - "Prints a random-state scramble"}, + {"scramble", "[OPTIONS]", + "Prints a random-state scramble."}, {"save", "[MOVES|@ID|$ID]", "Save or copy a scramble."}, {"change", "$ID1 [MOVES|$ID2|@ID2]", @@ -124,7 +124,7 @@ void help_cmd(int n, char cmdtok[][100]) { if (n == 1) { printf("\n"); for (int i = 0; commands[i][0][0]; i++) - printf("%-10s%-20s%s\n", commands[i][0], commands[i][1], commands[i][2]); + printf("%-10s%-25s%s\n", commands[i][0], commands[i][1], commands[i][2]); printf("\n"); printf("Type \'help\' followed by a command for a detailed help page.\n"); printf("Type \'help nissy\' for a general user guide.\n"); @@ -145,24 +145,54 @@ void help_cmd(int n, char cmdtok[][100]) { } void scramble_cmd(int n, char cmdtok[][100]) { - if (n > 1 || cmdtok[0][0] != 's') { /* Second case avoids warning */ + int c = 0, e = 0, dr = 0; + + if (n > 2 || cmdtok[0][0] != 's') { /* Second case avoids warning */ printf("scramble: wrong syntax\n"); return; + } else if (n == 2) { + if (!strcmp(cmdtok[1], "c")) { + c = 1; + } else if (!strcmp(cmdtok[1], "e")) { + e = 1; + } else if (!strcmp(cmdtok[1], "dr")) { + dr = 1; + } else { + printf("scramble: wrong syntax\n"); + return; + } } + int scram[2][30]; + srand(time(NULL)); int eofb = rand() % pow2to11; int coud = rand() % pow3to7; int ep = rand() % factorial12; int cp = rand() % factorial8; - while (perm_sign_int(ep, 12) != perm_sign_int(cp, 8)) - ep = (ep+1) % factorial12; + + if (c) { + eofb = ep = 0; + } else if (e) { + coud = cp = 0; + } else if (dr) { + eofb = coud = 0; + int epud = rand() % factorial8; + int epe = rand() % factorial4; + int ep_arr[12]; + epud_int_to_array(epud, ep_arr); + epe_int_to_array(epe, ep_arr); + ep = ep_array_to_int(ep_arr); + while (perm_sign_int(ep, 12) != perm_sign_int(cp, 8)) + cp = (cp+1) % factorial8; + } else { + while (perm_sign_int(ep, 12) != perm_sign_int(cp, 8)) + cp = (cp+1) % factorial8; + } + reach_state(eofb, coud, ep, cp, scram); /* Debug */ /* printf("State: %d %d %d %d\n", eofb, coud, ep, cp); */ - - int scram[2][30]; - reach_state(eofb, coud, ep, cp, scram); print_results(1, scram); } -- cgit v1.3