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
|
#include <stdio.h>
#include "map.h"
#include "cell.h"
#include "position.h"
#include "worm.h"
#include "renderascii.h"
#include "renderpng.h"
#include <stdlib.h>
#include <time.h>
#include "image.h"
#include "palette.h"
#include "font.h"
int main( int argc, char *argv[] )
{
/*
Image im( 400, 400 );
Font f("ter-u12n.bdf");
Palette pl;
pl.addColor( 0, 0, 0 );
pl.addColor( 255, 0, 0 );
pl.addColor( 0, 0, 255 );
im.drawLine( 0, 12, 399, 12, 2 );
im.drawText( f, 12, 12, 1, "Hello World!yqjm (01234,56789)");
im.save("test.png", pl);
return 0;
*/
srand( time( NULL ) );
if( argc <= 2 )
{
printf(
"Specify dimensions as paramters, and at least two e.g.:\n"
" %s 10 10\n"
" %s 5 5 5\n"
" %s 10 5 8 3\n"
"\n",
argv[0], argv[0], argv[0]
);
return 0;
}
Position p( argc-1 );
bool bOk = false;
for( int j = 0; j < argc-1; j++ )
{
int tmp = strtol( argv[j+1], NULL, 10 );
if( tmp > 1 )
{
bOk = true;
}
p[j] = tmp;
}
if( !bOk )
{
printf("At least one dimension must be greater than 1.\n");
return 0;
}
// Position p( 4, 4, 4, 4, 4 );
// Position p( 3, 5, 5, 5 );
Map m( p );
for( int j = 0; j < p.getDims(); j++ )
p[j]--;
int iCount = 2;
Worm **pWorm = new Worm*[iCount];
pWorm[0] = new Worm( 1, Position( p.getDims() ), m );
pWorm[1] = new Worm( 2, p, m );
/*
Position t( p.getDims() );
pWorm[0] = new Worm( 1, t, m );
t[0] = p[0];
pWorm[1] = new Worm( 2, t, m );
*/
while( iCount > 0 )
{
for( int j = 0; j < iCount; j++ )
{
if( pWorm[j]->timestep() == false )
{
delete pWorm[j];
if( j < iCount-1 )
{
pWorm[j] = pWorm[iCount-1];
pWorm[iCount-1] = 0;
j--;
}
else
{
pWorm[j] = 0;
}
iCount--;
}
}
}
m.connect( 1, 2 );
// RenderAscii r( m );
RenderPng r( m );
r.render();
return 0;
}
|