-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
218 lines (185 loc) · 5.11 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif
#ifdef __APPLE__
#include <SDL/SDL.h>
#else
#include <SDL/SDL.h>
#endif
#include <iostream>
#include <fstream>
/*
#include "include/cBrain.h"
#include "include/cSensor.h"
#include "include/cMover.h"
#include "include/cNeuron.h"
#include "include/cRandomPool.h"
*/
#include "include/cMainControler.h"
#include "include/cMenuState.h"
#include "include/cRenderState.h"
#include "include/cCreature.h"
int main ( int argc, char** argv )
{
/*
std::map<unsigned,CANN::cNeuron*> map;
std::map<unsigned,CANN::cNeuron*> map2;
CANN::cNeuron * one, * two, *three;
one = new CANN::cNeuron(1);
two = new CANN::cNeuron(2);
three = new CANN::cNeuron(3);
one->init(0.5, 10);
two->init(0.5, 10);
three->init(0.5, 10);
one->register_to(map);
two->register_to(map);
three->register_to(map2);
one->link(*one, 1);
one->link(*two, 1);
two->link(*one, 1);
two->link(*two, 1);
three->link(*three, 0.5);
one->pair(*three);
three->pair(*one);
CANN::cRandomPool R;
one->mutate_links(R);
std::cout << one->get_genome() << std::endl;
*/
/*
std::ofstream fout("file.txt");
CANN::cRandomPool R;
CANN::cBrain bob(R, 4, "bob");
bob.genome(std::cout);
bob.genome(fout);
fout.close();
std::ifstream fin("file.txt");
CANN::cBrain blue(fin);
blue.genome(std::cout);
fin.close();
fout.open("file.txt");
CANN::cSensor antenna(R, std::vector<unsigned>(3,3), "antenna");
antenna.genome(std::cout);
antenna.genome(fout);
fout.close();
fin.open("file.txt");
CANN::cSensor eye(fin);
eye.genome(std::cout);
*/
/*
CANN::cRandomPool R;
CANN::cBrain bob(R, 4, "bob");
std::vector<unsigned>layout(1,2);
CANN::cSensor nose(R, layout, "nose");
CANN::cMover legs(R, layout, "legs");
std::vector<CANN::cNeuron *> nose_plug;
nose_plug.push_back(bob.at(0));
nose_plug.push_back(bob.at(1));
nose.bind(nose_plug);
std::vector<CANN::cNeuron *> leg_plug;
leg_plug.push_back(bob.at(2));
leg_plug.push_back(bob.at(3));
legs.bind(leg_plug);
nose.genome(std::cout);
legs.genome(std::cout);
std::cout << legs;
std::vector<double> IO(2,2);
for (int i = 0; i < 10; i++)
{
std::cout << "exchange" << std::endl;
nose.exchange(IO);
std::cout << nose;
std::cout << bob;
std::cout << legs;
std::cout << "send/flip" << std::endl;
nose.send();
bob.send();
legs.send();
nose.flip();
bob.flip();
legs.flip();
legs.exchange(IO);
std::cout << nose;
std::cout << bob;
std::cout << legs;
std::cout << IO.at(0) << ' ' << IO.at(1) << std::endl;
}
*/
Interface::cMainControler * program = Interface::cMainControler::create();
program->init("hello", 640, 480, 32);
Interface::cMenuState * menu = new Interface::cMainMenu(program);
//Interface::cRenderState * render = Interface::cRenderState::create(program);
program->push(menu);
//program->push(render);
program->run();
program->clean_up();
/*
// initialize SDL video
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}
// make sure SDL cleans up before exit
atexit(SDL_Quit);
// create a new window
SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16,
SDL_HWSURFACE|SDL_DOUBLEBUF);
if ( !screen )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
return 1;
}
// load an image
SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
if (!bmp)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
// centre the bitmap on screen
SDL_Rect dstrect;
dstrect.x = (screen->w - bmp->w) / 2;
dstrect.y = (screen->h - bmp->h) / 2;
// program main loop
bool done = false;
while (!done)
{
// message processing loop
SDL_Event event;
while (SDL_PollEvent(&event))
{
// check for messages
switch (event.type)
{
// exit if the window is closed
case SDL_QUIT:
done = true;
break;
// check for keypresses
case SDL_KEYDOWN:
{
// exit if ESCAPE is pressed
if (event.key.keysym.sym == SDLK_ESCAPE)
done = true;
break;
}
} // end switch
} // end of message processing
// DRAWING STARTS HERE
// clear screen
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
// draw bitmap
SDL_BlitSurface(bmp, 0, screen, &dstrect);
// DRAWING ENDS HERE
// finally, update the screen :)
SDL_Flip(screen);
} // end main loop
// free loaded bitmap
SDL_FreeSurface(bmp);
// all is well ;)
printf("Exited cleanly\n");
*/
return 0;
}