diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2020-07-20 10:22:28 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2020-07-20 10:22:28 +0200 |
| commit | 40352f018b29e8aea9a804dd1240ea8374c39db8 (patch) | |
| tree | eed21b2f8b5b8f976261ab804e357218f69105c7 /src | |
| parent | e1ebff51092baf5581b728baec05c52c4bb3445e (diff) | |
| download | nissy-40352f018b29e8aea9a804dd1240ea8374c39db8.tar.gz nissy-40352f018b29e8aea9a804dd1240ea8374c39db8.zip | |
Added more scramble options, scramble doc
Diffstat (limited to '')
| -rwxr-xr-x | src/compile.sh | 1 | ||||
| -rw-r--r-- | src/main.c | 48 |
2 files changed, 39 insertions, 10 deletions
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 @@ | |||
| 1 | gcc -Wall -Wextra -O3 -std=c99 -o ../nissy -g *.c | ||
| @@ -12,8 +12,8 @@ | |||
| 12 | char *commands[][10] = { | 12 | char *commands[][10] = { |
| 13 | {"help", "[COMMAND]", | 13 | {"help", "[COMMAND]", |
| 14 | "Print this help, or a help page for COMMAND."}, | 14 | "Print this help, or a help page for COMMAND."}, |
| 15 | {"scramble", "", | 15 | {"scramble", "[OPTIONS]", |
| 16 | "Prints a random-state scramble"}, | 16 | "Prints a random-state scramble."}, |
| 17 | {"save", "[MOVES|@ID|$ID]", | 17 | {"save", "[MOVES|@ID|$ID]", |
| 18 | "Save or copy a scramble."}, | 18 | "Save or copy a scramble."}, |
| 19 | {"change", "$ID1 [MOVES|$ID2|@ID2]", | 19 | {"change", "$ID1 [MOVES|$ID2|@ID2]", |
| @@ -124,7 +124,7 @@ void help_cmd(int n, char cmdtok[][100]) { | |||
| 124 | if (n == 1) { | 124 | if (n == 1) { |
| 125 | printf("\n"); | 125 | printf("\n"); |
| 126 | for (int i = 0; commands[i][0][0]; i++) | 126 | for (int i = 0; commands[i][0][0]; i++) |
| 127 | printf("%-10s%-20s%s\n", commands[i][0], commands[i][1], commands[i][2]); | 127 | printf("%-10s%-25s%s\n", commands[i][0], commands[i][1], commands[i][2]); |
| 128 | printf("\n"); | 128 | printf("\n"); |
| 129 | printf("Type \'help\' followed by a command for a detailed help page.\n"); | 129 | printf("Type \'help\' followed by a command for a detailed help page.\n"); |
| 130 | printf("Type \'help nissy\' for a general user guide.\n"); | 130 | printf("Type \'help nissy\' for a general user guide.\n"); |
| @@ -145,24 +145,54 @@ void help_cmd(int n, char cmdtok[][100]) { | |||
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | void scramble_cmd(int n, char cmdtok[][100]) { | 147 | void scramble_cmd(int n, char cmdtok[][100]) { |
| 148 | if (n > 1 || cmdtok[0][0] != 's') { /* Second case avoids warning */ | 148 | int c = 0, e = 0, dr = 0; |
| 149 | |||
| 150 | if (n > 2 || cmdtok[0][0] != 's') { /* Second case avoids warning */ | ||
| 149 | printf("scramble: wrong syntax\n"); | 151 | printf("scramble: wrong syntax\n"); |
| 150 | return; | 152 | return; |
| 153 | } else if (n == 2) { | ||
| 154 | if (!strcmp(cmdtok[1], "c")) { | ||
| 155 | c = 1; | ||
| 156 | } else if (!strcmp(cmdtok[1], "e")) { | ||
| 157 | e = 1; | ||
| 158 | } else if (!strcmp(cmdtok[1], "dr")) { | ||
| 159 | dr = 1; | ||
| 160 | } else { | ||
| 161 | printf("scramble: wrong syntax\n"); | ||
| 162 | return; | ||
| 163 | } | ||
| 151 | } | 164 | } |
| 152 | 165 | ||
| 166 | int scram[2][30]; | ||
| 167 | |||
| 153 | srand(time(NULL)); | 168 | srand(time(NULL)); |
| 154 | int eofb = rand() % pow2to11; | 169 | int eofb = rand() % pow2to11; |
| 155 | int coud = rand() % pow3to7; | 170 | int coud = rand() % pow3to7; |
| 156 | int ep = rand() % factorial12; | 171 | int ep = rand() % factorial12; |
| 157 | int cp = rand() % factorial8; | 172 | int cp = rand() % factorial8; |
| 158 | while (perm_sign_int(ep, 12) != perm_sign_int(cp, 8)) | 173 | |
| 159 | ep = (ep+1) % factorial12; | 174 | if (c) { |
| 175 | eofb = ep = 0; | ||
| 176 | } else if (e) { | ||
| 177 | coud = cp = 0; | ||
| 178 | } else if (dr) { | ||
| 179 | eofb = coud = 0; | ||
| 180 | int epud = rand() % factorial8; | ||
| 181 | int epe = rand() % factorial4; | ||
| 182 | int ep_arr[12]; | ||
| 183 | epud_int_to_array(epud, ep_arr); | ||
| 184 | epe_int_to_array(epe, ep_arr); | ||
| 185 | ep = ep_array_to_int(ep_arr); | ||
| 186 | while (perm_sign_int(ep, 12) != perm_sign_int(cp, 8)) | ||
| 187 | cp = (cp+1) % factorial8; | ||
| 188 | } else { | ||
| 189 | while (perm_sign_int(ep, 12) != perm_sign_int(cp, 8)) | ||
| 190 | cp = (cp+1) % factorial8; | ||
| 191 | } | ||
| 160 | 192 | ||
| 193 | reach_state(eofb, coud, ep, cp, scram); | ||
| 161 | /* Debug */ | 194 | /* Debug */ |
| 162 | /* printf("State: %d %d %d %d\n", eofb, coud, ep, cp); */ | 195 | /* printf("State: %d %d %d %d\n", eofb, coud, ep, cp); */ |
| 163 | |||
| 164 | int scram[2][30]; | ||
| 165 | reach_state(eofb, coud, ep, cp, scram); | ||
| 166 | print_results(1, scram); | 196 | print_results(1, scram); |
| 167 | } | 197 | } |
| 168 | 198 | ||
