5 * Created by Alyssa Milburn on Wed Apr 11 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.
24 #include <boost/shared_ptr.hpp>
28 using boost::shared_ptr
;
32 struct c2ebraincomponentorder
{
33 bool operator()(const class c2eBrainComponent
*b1
, const class c2eBrainComponent
*b2
) const;
36 class c2eBrainComponent
{
38 friend class c2ebraincomponentorder
;
41 class c2eBrain
*parent
;
45 virtual void init() = 0;
46 virtual void tick() = 0;
47 uint8
getUpdateTime() { return updatetime
; }
48 bool wasInited() { return inited
; }
50 c2eBrainComponent(class c2eBrain
*b
) : parent(b
) { assert(b
); inited
= false; }
51 virtual ~c2eBrainComponent() { }
63 std::vector
<c2erule
> rules
;
66 void init(uint8 ruledata
[48]);
67 bool runRule(float acc
, float srcneuron
[8], float neuron
[8], float spareneuron
[8], float dendrite
[8], class c2eCreature
*creature
);
77 c2eNeuron
*source
, *dest
;
80 class c2eLobe
: public c2eBrainComponent
{
82 c2eBrainLobeGene
*ourGene
;
83 c2eSVRule initrule
, updaterule
;
84 std::vector
<c2eNeuron
> neurons
;
88 c2eLobe(class c2eBrain
*b
, c2eBrainLobeGene
*g
);
92 c2eBrainLobeGene
*getGene() { return ourGene
; }
93 unsigned int getNoNeurons() { return neurons
.size(); }
94 c2eNeuron
*getNeuron(unsigned int i
) { return &neurons
[i
]; }
95 unsigned int getSpareNeuron() { return spare
; }
96 void setNeuronInput(unsigned int i
, float input
);
100 class c2eTract
: public c2eBrainComponent
{
102 c2eBrainTractGene
*ourGene
;
103 c2eSVRule initrule
, updaterule
;
104 std::vector
<c2eDendrite
> dendrites
;
105 std::vector
<c2eNeuron
*> src_neurons
, dest_neurons
;
108 c2eDendrite
*getDendriteFromTo(c2eNeuron
*, c2eNeuron
*);
112 c2eTract(class c2eBrain
*b
, c2eBrainTractGene
*g
);
116 c2eBrainTractGene
*getGene() { return ourGene
; }
117 unsigned int getNoDendrites() { return dendrites
.size(); }
118 c2eDendrite
*getDendrite(unsigned int i
) { return &dendrites
[i
]; }
125 class c2eCreature
*parent
;
127 std::multiset
<c2eBrainComponent
*, c2ebraincomponentorder
> components
;
130 std::map
<std::string
, c2eLobe
*> lobes
;
131 std::vector
<c2eTract
*> tracts
;
133 c2eBrain(c2eCreature
*p
);
137 c2eLobe
*getLobeById(std::string id
);
138 c2eLobe
*getLobeByTissue(unsigned int id
);
139 c2eCreature
*getParent() { return parent
; }