fafejto
no way to compare when less than two revisions
Különbségek
A kiválasztott változat és az aktuális verzió közötti különbségek a következők.
— | fafejto [2015/12/30 20:47] (aktuális) – létrehozva truth | ||
---|---|---|---|
Sor 1: | Sor 1: | ||
+ | =====Mágus fafejtő===== | ||
+ | Ha mágustanonc vagy és meggyűlt a bajod a varázsbot [[magikus_fa|megszerzésével]], | ||
+ | * Linux - [[https:// | ||
+ | * Windows - [[https:// | ||
+ | ====Forráskód==== | ||
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #ifdef linux | ||
+ | #define BCYAN " | ||
+ | #define GREY " | ||
+ | #define RED " | ||
+ | #define RESET " | ||
+ | #else | ||
+ | #define BCYAN "" | ||
+ | #define GREY "" | ||
+ | #define RED "" | ||
+ | #define RESET "" | ||
+ | #endif | ||
+ | |||
+ | int initial[6], actual[6], goal[6], order[6]; | ||
+ | int addition[5][6] = { | ||
+ | { 0, 1, 2, 1, 3, 0 }, | ||
+ | { 1, 0, 0, 1, 1, 1 }, | ||
+ | { 1, 0, 1, 0, 0, 0 }, | ||
+ | { 1, 0, 1, 1, 0, 0 }, | ||
+ | { 1, 0, 1, 0, 0, 1 } | ||
+ | }; | ||
+ | |||
+ | void print_help() { | ||
+ | printf( | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | |||
+ | void print_status() { | ||
+ | int i = 0; | ||
+ | | ||
+ | while(i < 6) fputc(actual[i++]+' | ||
+ | } | ||
+ | |||
+ | void info(char *s) { | ||
+ | printf(" | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | void hiba(char *s) { | ||
+ | printf(" | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | int isnum(char c) { | ||
+ | return c > 47 && c < 58 ? 1 : 0; | ||
+ | } | ||
+ | |||
+ | void numinc(int (*prod)[6], int loc) { | ||
+ | int i; | ||
+ | | ||
+ | for(i = 0;i < 6;i++) { | ||
+ | (*prod)[i] += addition[loc][i]; | ||
+ | if((*prod)[i] > 5) (*prod)[i] -= 6; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void shift_hor(int (*prod)[6]) { | ||
+ | int tmp; | ||
+ | | ||
+ | tmp = (*prod)[2]; | ||
+ | (*prod)[2] = (*prod)[1], (*prod)[1] = (*prod)[0], (*prod)[0] = tmp; | ||
+ | tmp = (*prod)[3]; | ||
+ | (*prod)[3] = (*prod)[4], (*prod)[4] = (*prod)[5], (*prod)[5] = tmp; | ||
+ | } | ||
+ | |||
+ | void rotate(int loc1, int loc2, int loc3, int spec) { | ||
+ | int i, sub; | ||
+ | | ||
+ | if(actual[loc1] != goal[loc2]) { | ||
+ | if((sub = goal[loc2]-actual[loc1]) < 0) sub += 6; | ||
+ | printf(" | ||
+ | print_status(); | ||
+ | for(i = 0;i < sub;i++) numinc(& | ||
+ | fputs(" | ||
+ | if(spec) { | ||
+ | printf(" | ||
+ | print_status(); | ||
+ | for(i = 0;i < 6-sub;i++) numinc(& | ||
+ | fputs(" | ||
+ | } | ||
+ | } | ||
+ | printf(" | ||
+ | print_status(); | ||
+ | shift_hor(& | ||
+ | fputs(" | ||
+ | getchar(), fputc(' | ||
+ | } | ||
+ | |||
+ | void line_eval(char *msg, int (*prod)[6]) { | ||
+ | char buf[256]; | ||
+ | int i; | ||
+ | | ||
+ | do { | ||
+ | printf("> | ||
+ | fgets(buf, | ||
+ | if(strlen(buf) != 7) { | ||
+ | hiba(" | ||
+ | continue; | ||
+ | } | ||
+ | for(i = 0;i < 6;i++) { | ||
+ | if(isnum(buf[i])) (*prod)[i] = buf[i]-' | ||
+ | else { | ||
+ | hiba(" | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | } while(i != 6); | ||
+ | } | ||
+ | |||
+ | int main() { | ||
+ | int i, k, tmp[6], size = sizeof(initial); | ||
+ | | ||
+ | printf(" | ||
+ | print_help(); | ||
+ | | ||
+ | line_eval(" | ||
+ | line_eval(" | ||
+ | | ||
+ | fputc(' | ||
+ | for(i = 1;i < 7;i++) { | ||
+ | printf("# | ||
+ | line_eval(" | ||
+ | | ||
+ | for(k = 1;k < 6;k++) { | ||
+ | if(order[k]) continue; | ||
+ | memcpy(& | ||
+ | if(!memcmp(actual, | ||
+ | order[k] = i; | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | if(k == 6) { | ||
+ | memcpy(& | ||
+ | if(!memcmp(actual, | ||
+ | else { | ||
+ | info(" | ||
+ | return 1; | ||
+ | } | ||
+ | } | ||
+ | memcpy(& | ||
+ | } | ||
+ | | ||
+ | fputs(" | ||
+ | rotate(0, | ||
+ | rotate(0, | ||
+ | rotate(0, | ||
+ | rotate(3, | ||
+ | rotate(3, | ||
+ | rotate(3, | ||
+ | | ||
+ | if(!memcmp(goal, | ||
+ | else { | ||
+ | info(" | ||
+ | return 1; | ||
+ | } | ||
+ | | ||
+ | printf( | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | getchar(); | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </ |
fafejto.txt · Utolsó módosítás: 2015/12/30 20:47 szerkesztette: truth