diff options
Diffstat (limited to '')
| -rw-r--r-- | src/main.c | 29 |
1 files changed, 27 insertions, 2 deletions
| @@ -1,6 +1,7 @@ | |||
| 1 | /* blabla */ | 1 | /* blabla */ |
| 2 | #include <stdio.h> | 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
| 4 | #include <time.h> | ||
| 4 | #include "utils.h" | 5 | #include "utils.h" |
| 5 | #include "coordinates.h" | 6 | #include "coordinates.h" |
| 6 | #include "io.h" | 7 | #include "io.h" |
| @@ -11,6 +12,8 @@ | |||
| 11 | char *commands[][10] = { | 12 | char *commands[][10] = { |
| 12 | {"help", "[COMMAND]", | 13 | {"help", "[COMMAND]", |
| 13 | "Print this help, or a help page for COMMAND."}, | 14 | "Print this help, or a help page for COMMAND."}, |
| 15 | {"scramble", "", | ||
| 16 | "Prints a random-state scramble"}, | ||
| 14 | {"save", "[MOVES|@ID|$ID]", | 17 | {"save", "[MOVES|@ID|$ID]", |
| 15 | "Save or copy a scramble."}, | 18 | "Save or copy a scramble."}, |
| 16 | {"change", "$ID1 [MOVES|$ID2|@ID2]", | 19 | {"change", "$ID1 [MOVES|$ID2|@ID2]", |
| @@ -141,6 +144,28 @@ void help_cmd(int n, char cmdtok[][100]) { | |||
| 141 | } | 144 | } |
| 142 | } | 145 | } |
| 143 | 146 | ||
| 147 | void scramble_cmd(int n, char cmdtok[][100]) { | ||
| 148 | if (n > 1 || cmdtok[0][0] != 's') { /* Second case avoids warning */ | ||
| 149 | printf("scramble: wrong syntax\n"); | ||
| 150 | return; | ||
| 151 | } | ||
| 152 | |||
| 153 | srand(time(NULL)); | ||
| 154 | int eofb = rand() % pow2to11; | ||
| 155 | int coud = rand() % pow3to7; | ||
| 156 | int ep = rand() % factorial12; | ||
| 157 | int cp = rand() % factorial8; | ||
| 158 | while (perm_sign_int(ep, 12) != perm_sign_int(cp, 8)) | ||
| 159 | ep = (ep+1) % factorial12; | ||
| 160 | |||
| 161 | /* Debug */ | ||
| 162 | /* 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); | ||
| 167 | } | ||
| 168 | |||
| 144 | void save_cmd(int n, char cmdtok[][100]) { | 169 | void save_cmd(int n, char cmdtok[][100]) { |
| 145 | int scram[255]; | 170 | int scram[255]; |
| 146 | if (n == 1) { | 171 | if (n == 1) { |
| @@ -534,7 +559,7 @@ void dr_cmd(int n, char cmdtok[][100]) { | |||
| 534 | int dr_list[m+5][30], ndr; | 559 | int dr_list[m+5][30], ndr; |
| 535 | if (from) { | 560 | if (from) { |
| 536 | ndr = drfrom_scram_spam(scram_unnissed, dr_list, from, fb, rl, ud, | 561 | ndr = drfrom_scram_spam(scram_unnissed, dr_list, from, fb, rl, ud, |
| 537 | m, b, niss, hide); | 562 | m, b, niss, hide); |
| 538 | if (ndr == -1) { | 563 | if (ndr == -1) { |
| 539 | printf("dr: from given, but EO not found (possibly other error).\n"); | 564 | printf("dr: from given, but EO not found (possibly other error).\n"); |
| 540 | return; | 565 | return; |
| @@ -761,7 +786,7 @@ void exit_quit_cmd(int n, char cmdtok[][100]) { | |||
| 761 | } | 786 | } |
| 762 | 787 | ||
| 763 | void (*cmd_list[])(int n, char cmdtok[][100]) = { | 788 | void (*cmd_list[])(int n, char cmdtok[][100]) = { |
| 764 | help_cmd, save_cmd, change_cmd, print_cmd, | 789 | help_cmd, scramble_cmd, save_cmd, change_cmd, print_cmd, |
| 765 | add_cmd, invert_cmd, unniss_cmd, pic_cmd, | 790 | add_cmd, invert_cmd, unniss_cmd, pic_cmd, |
| 766 | solve_cmd, replace_cmd, | 791 | solve_cmd, replace_cmd, |
| 767 | eo_cmd, dr_cmd, htr_cmd, | 792 | eo_cmd, dr_cmd, htr_cmd, |
