add unfinished bmpImage implementation
[openc2e.git] / oldBrain.cpp
blob39bfef1d821298d8c6e48ff3e36261fba90502ee
1 /*
2 * oldBrain.cpp
3 * openc2e
5 * Created by Alyssa Milburn on Mon Aug 13 2007.
6 * Copyright (c) 2007 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #include "oldBrain.h"
21 #include "Creature.h"
24 * svrule examples:
26 * * creatures 1:
27 * output:TRUE:input
29 * * creatures 2:
30 * random:0:chem 5:PLUS:state
31 * state:PLUS:type 0:MINUS:type 1
32 * input:TRUE:output:TRUE:suscept:move twrds:255:64
33 * suscept:TRUE:chem 0:TRUE:STW
35 * * canny:
36 * state:PLUS:state:PLUS:state
37 * type 0:TRUE:type 0:PLUS:type 1
41 unsigned char processSVRule(oldNeuron *cell, oldDendrite *dend, uint8 *svrule, unsigned int len) {
42 unsigned char state;
44 for (unsigned int i = 0; i < len; i++) {
45 switch (svrule[i]) {
46 case 0: // <end>
47 return state;
49 case 1: // 0
50 state = 0;
51 break;
53 case 2: // 1
54 state = 1;
55 break;
57 case 3: // 64
58 state = 64;
59 break;
61 case 4: // 255
62 state = 255;
63 break;
65 case 5: // chem0
66 break;
68 case 6: // chem1
69 break;
71 case 7: // chem2
72 break;
74 case 8: // chem3
75 break;
77 case 9: // state
78 state = cell->state;
79 break;
81 case 10: // output
82 break;
84 case 11: // thres
85 break;
87 case 12: // type0
88 break;
90 case 13: // type1
91 break;
93 case 14: // anded0
94 break;
96 case 15: // anded1
97 break;
99 case 16: // input
100 break;
102 case 17: // conduct
103 break;
105 case 18: // suscept
106 break;
108 case 19: // STW
109 break;
111 case 20: // LTW
112 break;
114 case 21: // strength
115 break;
117 case 22: // TRUE
118 if (!state) return 0;
119 break;
121 case 23: // PLUS
122 break;
124 case 24: // MINUS
125 break;
127 case 25: // TIMES
128 break;
130 case 26: // INCR
131 state++;
132 break;
134 case 27: // DECR
135 state--;
136 break;
138 case 28: // <unused>
139 case 29: // <unused>
140 case 30: // <error>
141 break;
143 /* creatures 2 is different, we should probably remap at load time:
144 case 22: // 32
145 case 23: // 128
146 case 24: // rnd const
147 case 25: // chem4
148 case 26: // chem5
149 case 27: // leak in
150 case 28: // leak out
151 case 29: // curr src leak in
152 case 30: // TRUE
153 case 31: // PLUS
154 case 32: // MINUS
155 case 33: // TIMES
156 case 34: // INCR
157 case 35: // DECR
158 case 36: // FALSE
159 case 37: // multiply
160 case 38: // average
161 case 39: // move twrds
162 case 40: // random
163 case 41: // <error>*/
167 return state;
170 oldLobe::oldLobe(oldBrain *b, oldBrainLobeGene *g) {
171 assert(b);
172 parent = b;
173 assert(g);
174 ourGene = g;
176 inited = false;
178 unsigned int width = g->width, height = g->height;
179 // TODO: good?
180 if (width < 1) width = 1;
181 if (height < 1) height = 1;
183 neurons.reserve(width * height);
185 oldNeuron n;
186 for (unsigned int i = 0; i < width * height; i++) {
187 neurons.push_back(n);
190 // TODO
193 void oldLobe::init() {
194 inited = true;
195 wipe();
197 // TODO
200 void oldLobe::wipe() {
201 // TODO
204 void oldLobe::tick() {
205 // TODO
208 oldBrain::oldBrain(oldCreature *p) {
209 assert(p);
210 parent = p;
213 void oldBrain::processGenes() {
214 shared_ptr<genomeFile> genome = parent->getGenome();
216 for (vector<gene *>::iterator i = genome->genes.begin(); i != genome->genes.end(); i++) {
217 if (!parent->shouldProcessGene(*i)) continue;
219 if (typeid(**i) == typeid(oldBrainLobeGene)) {
220 oldBrainLobeGene *g = (oldBrainLobeGene *)*i;
221 oldLobe *l = new oldLobe(this, g);
222 lobes[lobes.size()] = l; // TODO: muh
227 void oldBrain::init() {
228 for (std::map<unsigned int, oldLobe *>::iterator i = lobes.begin(); i != lobes.end(); i++) {
229 if (!(*i).second->wasInited()) (*i).second->init();
233 void oldBrain::tick() {
234 for (std::map<unsigned int, oldLobe *>::iterator i = lobes.begin(); i != lobes.end(); i++) {
235 (*i).second->tick();
239 oldLobe *oldBrain::getLobeByTissue(unsigned int id) {
240 if (lobes.find(id) == lobes.end())
241 return 0;
243 return lobes[id];
246 /* vim: set noet: */