source: cpp/frams/model/autoname.cpp @ 199

Last change on this file since 199 was 197, checked in by Maciej Komosinski, 11 years ago

GDK used by developers since 1999, distributed on the web since 2002

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 1999-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include "autoname.h"
6#include "common/nonstd_stl.h"
7#include <ctype.h>
8
9SString AutoName::makeName(Model &model)
10{
11SString t;
12t=firstName(model);
13t+=' ';
14t+=lastName(model);
15return t;
16}
17
18///////////////////////////
19
20static char* cat_syl(char* str,unsigned int x)
21{
22static char sp[]="bcdfghklmnprstwz",sa[]="aeiouy";
23x%=6*16;
24str[0]=sa[x%6];
25if (x>5)
26        {str[1]=sp[x/6]; str[2]=0; return str+2;}
27else
28        {str[1]=0; return str+1;}
29}
30
31SString AutoName::firstName(Model& model)
32{
33char buf[8];
34unsigned int s1=0,s2=0,s3=0;
35const char *x=model.getGeno().getGene();
36for (;*x;x++) { s1+=*x; s2=s2**x+*x; s3=(s3^*x)+*x; }
37char* t=buf;
38t=cat_syl(t,s1);
39t=cat_syl(t,s2);
40t=cat_syl(t,s3);
41buf[0]=(char)toupper(buf[0]);
42return SString(buf);
43}
44
45static void przeplatanka(char *out,char *in1,char *in2)
46{
47int d1=strlen(in1),d2=strlen(in2);
48int p1=0,p2=0;
49int pp=d1+d2;
50int i,p;
51if (d2<d1)
52        {
53        int t=d2; d2=d1; d1=t;
54        char *c=in1; in1=in2; in2=c;
55        }
56if (pp)
57for (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;
63}
64
65SString AutoName::lastName(Model& model)
66{
67char Sam[]="yeaou";
68char Sp[]="shtkdgmr";
69
70#define NAME_MAXLENBODY 5
71#define NAME_MAXLENBRAIN 5
72#define NAME_BODYLEN 0.8
73#define NAME_BRAINLEN 0.8
74#define NAME_BODYMASS 1.0
75#define NAME_BRAININP 1.0
76
77char naz[NAME_MAXLENBODY+NAME_MAXLENBRAIN+1];
78int poz,nextpoz,i;
79
80double w;
81int cialo=-1;
82int mozg=-1;
83
84char tmpc[NAME_MAXLENBODY+1],tmpm[NAME_MAXLENBRAIN+1];
85
86if (model.getPartCount()>0)
87{
88cialo=min((int)(sqrt(double(model.getPartCount())-1)*NAME_BODYLEN),NAME_MAXLENBODY-1);
89poz=0;
90for (i=0;i<=cialo;i++) // budowanie "opisu" ciala
91        {
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)];
96        }
97tmpc[i]=0;
98}
99else tmpc[0]=0;
100
101int wint;
102
103if (model.getNeuroCount()>0)
104{
105mozg=min((int)(sqrt((double)model.getNeuroCount())*NAME_BRAINLEN),NAME_MAXLENBRAIN-1);
106poz=0;
107for (i=0;i<=mozg;i++) // budowanie "opisu" mozgu
108        {
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)];
113        }
114tmpm[i]=0;
115}
116else tmpm[0]=0;
117
118if ((mozg+1) < ((cialo+2)/2))
119        {
120        for (i=mozg+1;i<=cialo/2;i++) tmpm[i]='i';
121        tmpm[i]=0;
122        }
123
124przeplatanka(naz,tmpc,tmpm);
125
126naz[0]=(char)toupper(naz[0]);
127return SString(naz);
128}
129
130
131
Note: See TracBrowser for help on using the repository browser.