Changeset 343 for cpp/frams/model/autoname.cpp
- Timestamp:
- 04/04/15 20:40:02 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/model/autoname.cpp
r286 r343 9 9 SString AutoName::makeName(Model &model) 10 10 { 11 SString t;12 t=firstName(model);13 t+=' ';14 t+=lastName(model);15 return t;11 SString t; 12 t = firstName(model); 13 t += ' '; 14 t += lastName(model); 15 return t; 16 16 } 17 17 18 18 /////////////////////////// 19 19 20 static char* cat_syl(char* str, unsigned int x)20 static char* cat_syl(char* str, unsigned int x) 21 21 { 22 static char sp[]="bcdfghklmnprstwz",sa[]="aeiouy"; 23 x%=6*16; 24 str[0]=sa[x%6]; 25 if (x>5) 26 {str[1]=sp[x/6]; str[2]=0; return str+2;} 27 else 28 {str[1]=0; return str+1;} 22 static char sp[] = "bcdfghklmnprstwz", sa[] = "aeiouy"; 23 x %= 6 * 16; 24 str[0] = sa[x % 6]; 25 if (x > 5) 26 { 27 str[1] = sp[x / 6]; str[2] = 0; return str + 2; 28 } 29 else 30 { 31 str[1] = 0; return str + 1; 32 } 29 33 } 30 34 31 35 SString AutoName::firstName(Model& model) 32 36 { 33 char buf[8]; 34 unsigned int s1=0,s2=0,s3=0; 35 const char *x=model.getGeno().getGene(); 36 for (;*x;x++) { s1+=*x; s2=s2**x+*x; s3=(s3^*x)+*x; } 37 char* t=buf; 38 t=cat_syl(t,s1); 39 t=cat_syl(t,s2); 40 t=cat_syl(t,s3); 41 buf[0]=(char)toupper(buf[0]); 42 return SString(buf); 37 char buf[8]; 38 unsigned int s1 = 0, s2 = 0, s3 = 0; 39 SString g = model.getGeno().getGene(); 40 const char *x = g; 41 for (; *x; x++) { s1 += *x; s2 = s2**x + *x; s3 = (s3^*x) + *x; } 42 char* t = buf; 43 t = cat_syl(t, s1); 44 t = cat_syl(t, s2); 45 t = cat_syl(t, s3); 46 buf[0] = (char)toupper(buf[0]); 47 return SString(buf); 43 48 } 44 49 45 static void przeplatanka(char *out, char *in1,char *in2)50 static void przeplatanka(char *out, char *in1, char *in2) 46 51 { 47 int d1=strlen(in1),d2=strlen(in2);48 int p1=0,p2=0;49 int pp=d1+d2;50 int i,p;51 if (d2<d1)52 int d1 = strlen(in1), d2 = strlen(in2); 53 int p1 = 0, p2 = 0; 54 int pp = d1 + d2; 55 int i, p; 56 if (d2 < d1) 52 57 { 53 int t=d2; d2=d1; d1=t;54 char *c=in1; in1=in2; in2=c;58 int t = d2; d2 = d1; d1 = t; 59 char *c = in1; in1 = in2; in2 = c; 55 60 } 56 if (pp)57 for (i=0;i<=pp;i++)58 {59 p=(i*d1)/pp-1; for (;p1<=p;p1++) *(out++)=*(in1++);60 p=(i*d2)/pp-1; for (;p2<=p;p2++) *(out++)=*(in2++);61 }62 *out=0;61 if (pp) 62 for (i = 0; i <= pp; i++) 63 { 64 p = (i*d1) / pp - 1; for (; p1 <= p; p1++) *(out++) = *(in1++); 65 p = (i*d2) / pp - 1; for (; p2 <= p; p2++) *(out++) = *(in2++); 66 } 67 *out = 0; 63 68 } 64 69 65 70 SString AutoName::lastName(Model& model) 66 71 { 67 char Sam[]="yeaou";68 char Sp[]="shtkdgmr";72 char Sam[] = "yeaou"; 73 char Sp[] = "shtkdgmr"; 69 74 70 75 #define NAME_MAXLENBODY 5 … … 75 80 #define NAME_BRAININP 1.0 76 81 77 char naz[NAME_MAXLENBODY+NAME_MAXLENBRAIN+1];78 int poz,nextpoz,i;82 char naz[NAME_MAXLENBODY + NAME_MAXLENBRAIN + 1]; 83 int poz, nextpoz, i; 79 84 80 double w;81 int cialo=-1;82 int mozg=-1;85 double w; 86 int cialo = -1; 87 int mozg = -1; 83 88 84 char tmpc[NAME_MAXLENBODY+1],tmpm[NAME_MAXLENBRAIN+1];89 char tmpc[NAME_MAXLENBODY + 1], tmpm[NAME_MAXLENBRAIN + 1]; 85 90 86 if (model.getPartCount()>0) 87 { 88 cialo=min((int)(sqrt(double(model.getPartCount())-1)*NAME_BODYLEN),NAME_MAXLENBODY-1); 89 poz=0; 90 for (i=0;i<=cialo;i++) // budowanie "opisu" ciala 91 if (model.getPartCount() > 0) 91 92 { 92 nextpoz=((model.getPartCount())*(i+1))/(cialo+1)-1; 93 w=1.0; 94 for (;poz<=nextpoz;poz++) w=max(w,model.getPart(poz)->mass); 95 tmpc[i]=Sp[min(int((w-1.0)*NAME_BODYMASS),int(sizeof(Sp))-2)]; 93 cialo = min((int)(sqrt(double(model.getPartCount()) - 1)*NAME_BODYLEN), NAME_MAXLENBODY - 1); 94 poz = 0; 95 for (i = 0; i <= cialo; i++) // budowanie "opisu" ciala 96 { 97 nextpoz = ((model.getPartCount())*(i + 1)) / (cialo + 1) - 1; 98 w = 1.0; 99 for (; poz <= nextpoz; poz++) w = max(w, model.getPart(poz)->mass); 100 tmpc[i] = Sp[min(int((w - 1.0)*NAME_BODYMASS), int(sizeof(Sp)) - 2)]; 101 } 102 tmpc[i] = 0; 96 103 } 97 tmpc[i]=0; 98 } 99 else tmpc[0]=0; 104 else tmpc[0] = 0; 100 105 101 int wint;106 int wint; 102 107 103 if (model.getNeuroCount()>0) 104 { 105 mozg=min((int)(sqrt((double)model.getNeuroCount())*NAME_BRAINLEN),NAME_MAXLENBRAIN-1); 106 poz=0; 107 for (i=0;i<=mozg;i++) // budowanie "opisu" mozgu 108 if (model.getNeuroCount() > 0) 108 109 { 109 nextpoz=(model.getNeuroCount()*(i+1))/(mozg+1)-1; 110 wint=0; 111 for (;poz<=nextpoz;poz++) wint=max(wint,model.getNeuro(poz)->getInputCount()); 112 tmpm[i]=Sam[min(int(wint*NAME_BRAININP),int(sizeof(Sam))-2)]; 110 mozg = min((int)(sqrt((double)model.getNeuroCount())*NAME_BRAINLEN), NAME_MAXLENBRAIN - 1); 111 poz = 0; 112 for (i = 0; i <= mozg; i++) // budowanie "opisu" mozgu 113 { 114 nextpoz = (model.getNeuroCount()*(i + 1)) / (mozg + 1) - 1; 115 wint = 0; 116 for (; poz <= nextpoz; poz++) wint = max(wint, model.getNeuro(poz)->getInputCount()); 117 tmpm[i] = Sam[min(int(wint*NAME_BRAININP), int(sizeof(Sam)) - 2)]; 118 } 119 tmpm[i] = 0; 113 120 } 114 tmpm[i]=0; 115 } 116 else tmpm[0]=0; 121 else tmpm[0] = 0; 117 122 118 if ((mozg+1) < ((cialo+2)/2))123 if ((mozg + 1) < ((cialo + 2) / 2)) 119 124 { 120 for (i=mozg+1;i<=cialo/2;i++) tmpm[i]='i';121 tmpm[i]=0;125 for (i = mozg + 1; i <= cialo / 2; i++) tmpm[i] = 'i'; 126 tmpm[i] = 0; 122 127 } 123 128 124 przeplatanka(naz,tmpc,tmpm);129 przeplatanka(naz, tmpc, tmpm); 125 130 126 naz[0]=(char)toupper(naz[0]);127 return SString(naz);131 naz[0] = (char)toupper(naz[0]); 132 return SString(naz); 128 133 } 129 130 131
Note: See TracChangeset
for help on using the changeset viewer.