source: cpp/frams/_demos/geneprops_test.cpp

Last change on this file was 1260, checked in by Maciej Komosinski, 10 months ago

Cosmetic

File size: 3.3 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, AllChange05, ExperimentalExponential };
83        Function fun = AllChange05;
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 'n': fun = AllChange05; break;
94                        case 'e': fun = ExperimentalExponential; break;
95                        case 'h': printf("%s args: [modifier [max_count]] (one of " F14_MODIFIERS ")\n"
96                                "\t-l = legacy function\n"
97                                "\t-n = modern, change=0.5, normalizeBiol4 disabled\n"
98                                "\t-e = experimental exponential function\n", argv[0]);
99                                return 0;
100                        default: fprintf(stderr, "%s: invalid option: %s\n", argv[0], arg); return 2;
101                        }
102                else
103                        switch (argpos++)
104                        {
105                        case 0: modifier = arg[0]; break;
106                        case 1: maxcount = atoi(arg); break;
107                        default: fprintf(stderr, "%s: too many arguments: %s\n", argv[0], arg); return 2;
108                        }
109        }
110
111        char modifier_u = toupper(modifier);
112        char modifier_l = tolower(modifier);
113
114        GenePropsOps_Exponential exponential_ops;
115        GenePropsOps_Legacy legacy_ops;
116        GenePropsOps_AllChange05 allchange05_ops;
117        GenePropsOps *ops;
118
119        switch (fun)
120        {
121        case Legacy: ops = &legacy_ops; break;
122        case ExperimentalExponential:  ops = &exponential_ops; break;
123        case AllChange05:  ops = &allchange05_ops; break;
124        default: ops = NULL;
125        }
126
127        char *tmp = new char[maxcount + 1];
128        for (int count = 0; count <= maxcount; count++)
129        {
130                int N = 1 << count;
131                for (int i = 0; i < N; i++)
132                {
133                        GeneProps props;
134                        for (int c = 0; c < count; c++)
135                        {
136                                char m = ((1 << c) & i) ? modifier_u : modifier_l;
137                                tmp[c] = m;
138                                props.executeModifier(m, ops);
139                        }
140                        if (count > 0)
141                                tmp[count] = 0;
142                        else
143                        {
144                                tmp[0] = '-'; tmp[1] = 0;
145                        }
146                        double value = genePropsValueForModifier(props, modifier);
147                        printf("%s\t%g\n", tmp, value);
148                }
149        }
150
151        return 0;
152}
Note: See TracBrowser for help on using the repository browser.