Felhasználói eszközök

Eszközök a webhelyen


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]], akkor segítségképp használhatod a következő konzolos programot:
 +  * Linux - [[https://www.dropbox.com/s/l06n7klr9lowjmo/fafejto?dl=1|https://www.dropbox.com/s/l06n7klr9lowjmo/fafejto?dl=1]]
 +  * Windows - [[https://www.dropbox.com/s/agw65mcusq3hnlp/fafejto.exe?dl=1|https://www.dropbox.com/s/agw65mcusq3hnlp/fafejto.exe?dl=1]]
  
 +====Forráskód====
 +<code c>
 +#include <stdio.h>
 +#include <string.h>
 +
 +#ifdef linux
 +#define BCYAN "\x1b[36;1m"
 +#define GREY  "\x1b[30;1m"
 +#define RED   "\x1b[31m"
 +#define RESET "\x1b[0m"
 +#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(
 +  "  Ezen program olyan magusoknak kinal segitseget, akik meg nem rendelkeznek\n"
 +  "  varazsbottal.\n"
 +  "  Elso lepeskent el kell menned a magikus fahoz, aminek utvonala fotertol:\n"
 +  "  [ "BCYAN"#14 e;#2 k;fa"RESET" ]\n"
 +  "  Ezt kovetoen a "BCYAN"nez tabla"RESET" parancs beirasaval lathatova valik relacios\n"
 +  "  jelek kozott a kirakando szam, alatta pedig a jelenlegi.\n\n");
 +}
 +
 +void print_status() {
 +  int i = 0;
 +  
 +  while(i < 6) fputc(actual[i++]+'0',stdout);
 +}
 +
 +void info(char *s) {
 +  printf("%s%%%s : %s\n",GREY,RESET,s);
 +  return;
 +}
 +
 +void hiba(char *s) {
 +  printf("%s%%%s : %s\n",RED,RESET,s);
 +  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("  |> '%s#%d gomb %d%s' | ",BCYAN,sub,order[loc3+1],RESET);
 +    print_status();
 +    for(i = 0;i < sub;i++) numinc(&actual,loc3);
 +    fputs(" -> ",stdout), print_status(), fputc('\n',stdout);
 +    if(spec) {
 +      printf("  |> '%s#%d gomb %d%s' | ",BCYAN,6-sub,order[3],RESET);
 +      print_status();
 +      for(i = 0;i < 6-sub;i++) numinc(&actual,2);
 +      fputs(" -> ",stdout), print_status(), fputc('\n',stdout);
 +    }
 +  }
 +  printf("  |> '%s#%d gomb %d%s' | ",BCYAN,1,order[0],RESET);
 +  print_status();
 +  shift_hor(&actual);
 +  fputs(" -> ",stdout), print_status(), fputs("\n(enter) ",stdout);
 +  getchar(), fputc('\n',stdout);
 +}
 +
 +void line_eval(char *msg, int (*prod)[6]) {
 +  char buf[256];
 +  int i;
 +  
 +  do {
 +    printf("> %s ",msg);
 +    fgets(buf,256,stdin), i = 0;
 +    if(strlen(buf) != 7) {
 +      hiba("a bemeneti ertek nem 6 jegyu szam.");
 +      continue;
 +    }
 +    for(i = 0;i < 6;i++) {
 +      if(isnum(buf[i])) (*prod)[i] = buf[i]-'0';
 +      else {
 +        hiba("a string erteke nem numerikus.");
 +        break;
 +      }
 +    }
 +  } while(i != 6);
 +}
 +
 +int main() {
 +  int i, k, tmp[6], size = sizeof(initial);
 +  
 +  printf("magus fafejto\ncompiled on 1230\nby %sstewie@ev%s\n\n",RED,RESET);
 +  print_help();
 +  
 +  line_eval("a kirakando szam:",&goal);
 +  line_eval("az aktualis szam:",&initial);
 +  
 +  fputc('\n',stdout);
 +  for(i = 1;i < 7;i++) {
 +    printf("# ird be, hogy '%sgomb %d%s'.\n",BCYAN,i,RESET);
 +    line_eval("az aktualis szam:",&actual);
 +    
 +    for(k = 1;k < 6;k++) {
 +      if(order[k]) continue;
 +      memcpy(&tmp,&initial,size), numinc(&tmp,k-1);
 +      if(!memcmp(actual,tmp,size)) {
 +        order[k] = i;
 +        break;
 +      }
 +    }
 +    if(k == 6) {
 +      memcpy(&tmp,&initial,size), shift_hor(&tmp);
 +      if(!memcmp(actual,tmp,size)) order[0] = i;
 +      else {
 +        info("nincs megoldas.");
 +        return 1;
 +      }
 +    }
 +    memcpy(&initial,&actual,size);
 +  }
 +  
 +  fputs("\n  Lepesek:\n\n",stdout);
 +  rotate(0,0,1,0);
 +  rotate(0,2,1,0);
 +  rotate(0,1,1,0);
 +  rotate(3,3,3,1);
 +  rotate(3,4,3,1);
 +  rotate(3,5,3,1);
 +  
 +  if(!memcmp(goal,actual,size)) info("sikerult megoldani!");
 +  else {
 +    info("nincs megoldas.");
 +    return 1;
 +  }
 +  
 +  printf(
 +  "\n"
 +  "  Most mar csak annyi a teendod, hogy nyugat fele haladsz tovabb es felveszed\n"
 +  "  a tekercset, onnan pedig eszak fele talalod meg a kifele vezeto utat, a\n"
 +  "  tekercset pedig a hallban odaadhatod Kyra-nak, aki cserebe megtanitja a\n"
 +  "  varazsbotot.\n\n");
 +  getchar();
 +  return 0;
 +}
 +
 +</code>
fafejto.txt · Utolsó módosítás: 2015/12/30 20:47 szerkesztette: truth

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki