source: cpp/frams/_demos/geneprops_test.cpp @ 1259

Last change on this file since 1259 was 1242, checked in by Maciej Komosinski, 2 years ago

Changed the default behavior of modifier genes in f1 and f4 to GenePropsOps_New05: the coefficient of change is set to 0.5 for all properties and for both increase and decrease, which ensures an equal distribution of target property values with a relatively fast convergence to minimal and maximal values; the four "biological" properties are no longer aggregated and normalized

File size: 3.4 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#include <frams/genetics/geneprops.h>
6
7/*
8Testing the influence of Framsticks f1/f4 modifier sequences. See also geneprops_graph.py
9
10Examples:
11
12- new experimental friction:
13$ ./geneprops_test f 3 -e | sort -n -k 2
14
15fff     0.0158037
16ff      0.0366025
17Fff     0.0639754
18f       0.1
19fFf     0.147411
20Ff      0.209808
21FFf     0.291926
22-       0.4
23ffF     0.542233
24fF      0.729423
25FfF     0.975778
26F       1.3
27fFF     1.7267
28FF      2.28827
29FFF     3.02733
30
31
32- legacy friction:
33$ ./geneprops_test f 3 -l | sort -n -k 2
34
35fff     0.2048
36ff      0.256
37f       0.32
38-       0.4
39Fff     0.7168
40fFf     0.8448
41Ff      0.896
42ffF     1.0048
43fF      1.056
44F       1.12
45FFf     1.3568
46FfF     1.5168
47fFF     1.6448
48FF      1.696
49FFF     2.1568
50
51
52*/
53
54double genePropsValueForModifier(GeneProps& gp, char modifier)
55{
56        switch (toupper(modifier))
57        {
58        case 'L': return gp.length; break;
59        case 'W': return gp.weight; break;
60        case 'F': return gp.friction; break;
61        case 'C': return gp.curvedness; break;
62        case 'Q': return gp.twist; break;
63        case 'E': return gp.energy; break;
64
65        case 'A': return gp.assimilation; break;
66        case 'I': return gp.ingestion; break;
67        case 'S': return gp.stamina; break;
68        case 'M': return gp.muscle_power; break;
69
70        case 'D': return gp.cred; break;
71        case 'G': return gp.cgreen; break;
72        case 'B': return gp.cblue;  break;
73        }
74        return 0;
75}
76
77int main(int argc, char *argv[])
78{
79        char modifier = 'L';
80        int maxcount = 4;
81
82        enum Function { Legacy, RecreatedLegacy, New05, NewExponential };
83        Function fun = Legacy;
84
85        int argpos = 0;
86        for (int i = 1; i < argc; i++)
87        {
88                const char* arg = argv[i];
89                if (arg[0] == '-')
90                        switch (arg[1])
91                        {
92                        case 'l': fun = Legacy; break;
93                        case 'r': fun = RecreatedLegacy; break;
94                        case 'n': fun = New05; break;
95                        case 'e': fun = NewExponential; break;
96                        case 'h': printf("%s args: [modifier [max_count]] (one of " F14_MODIFIERS ")\n"
97                                "\t-l = legacy function\n"
98                                "\t-r = recreated legacy function\n"
99                                "\t-n = new, change=0.5, normalizeBiol4 disabled\n"
100                                "\t-e = new exponential function\n", argv[0]);
101                                return 0;
102                        default: fprintf(stderr, "%s: invalid option: %s\n", argv[0], arg); return 2;
103                        }
104                else
105                        switch (argpos++)
106                        {
107                        case 0: modifier = arg[0]; break;
108                        case 1: maxcount = atoi(arg); break;
109                        default: fprintf(stderr, "%s: too many arguments: %s\n", argv[0], arg); return 2;
110                        }
111        }
112
113        char modifier_u = toupper(modifier);
114        char modifier_l = tolower(modifier);
115
116        GenePropsOps_Exponential exponential_ops;
117        GenePropsOps_Old recreated_ops;
118        GenePropsOps_New05 new05_ops;
119        GenePropsOps *ops;
120
121        switch (fun)
122        {
123        case RecreatedLegacy: ops = &recreated_ops; break;
124        case NewExponential:  ops = &exponential_ops; break;
125        case New05:  ops = &new05_ops; break;
126        default: ops = NULL;
127        }
128
129        char *tmp = new char[maxcount + 1];
130        for (int count = 0; count <= maxcount; count++)
131        {
132                int N = 1 << count;
133                for (int i = 0; i < N; i++)
134                {
135                        GeneProps props;
136                        for (int c = 0; c < count; c++)
137                        {
138                                char m = ((1 << c) & i) ? modifier_u : modifier_l;
139                                tmp[c] = m;
140                                if (fun == Legacy)
141                                        props.executeModifier_Legacy(m);
142                                else
143                                        props.executeModifier(m, ops);
144                        }
145                        if (count > 0)
146                                tmp[count] = 0;
147                        else
148                        {
149                                tmp[0] = '-'; tmp[1] = 0;
150                        }
151                        double value = genePropsValueForModifier(props, modifier);
152                        printf("%s\t%g\n", tmp, value);
153                }
154        }
155
156        return 0;
157}
Note: See TracBrowser for help on using the repository browser.