diff options
author | Mike Buland <mike@xagasoft.com> | 2015-04-02 15:28:31 -0600 |
---|---|---|
committer | Mike Buland <mike@xagasoft.com> | 2015-04-02 15:28:31 -0600 |
commit | 518619603ab3c49b7fdfcf19c439c1a30668164f (patch) | |
tree | dda7774f51bde150db91dac14718cc78f7571039 /src/main.cpp | |
download | lost-518619603ab3c49b7fdfcf19c439c1a30668164f.tar.gz lost-518619603ab3c49b7fdfcf19c439c1a30668164f.tar.bz2 lost-518619603ab3c49b7fdfcf19c439c1a30668164f.tar.xz lost-518619603ab3c49b7fdfcf19c439c1a30668164f.zip |
Everything works, it could use more stuff.
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..ef3f3de --- /dev/null +++ b/src/main.cpp | |||
@@ -0,0 +1,95 @@ | |||
1 | #include <stdio.h> | ||
2 | |||
3 | #include "map.h" | ||
4 | #include "cell.h" | ||
5 | #include "position.h" | ||
6 | #include "worm.h" | ||
7 | #include "renderascii.h" | ||
8 | #include "renderpng.h" | ||
9 | |||
10 | #include <stdlib.h> | ||
11 | #include <time.h> | ||
12 | |||
13 | int main( int argc, char *argv[] ) | ||
14 | { | ||
15 | srand( time( NULL ) ); | ||
16 | |||
17 | if( argc <= 2 ) | ||
18 | { | ||
19 | printf( | ||
20 | "Specify dimensions as paramters, and at least two e.g.:\n" | ||
21 | " %s 10 10\n" | ||
22 | " %s 5 5 5\n" | ||
23 | " %s 10 5 8 3\n" | ||
24 | "\n", | ||
25 | argv[0], argv[0], argv[0] | ||
26 | ); | ||
27 | return 0; | ||
28 | } | ||
29 | |||
30 | Position p( argc-1 ); | ||
31 | bool bOk = false; | ||
32 | for( int j = 0; j < argc-1; j++ ) | ||
33 | { | ||
34 | int tmp = strtol( argv[j+1], NULL, 10 ); | ||
35 | if( tmp > 1 ) | ||
36 | { | ||
37 | bOk = true; | ||
38 | } | ||
39 | p[j] = tmp; | ||
40 | } | ||
41 | if( !bOk ) | ||
42 | { | ||
43 | printf("At least one dimension must be greater than 1.\n"); | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | // Position p( 4, 4, 4, 4, 4 ); | ||
48 | // Position p( 3, 5, 5, 5 ); | ||
49 | Map m( p ); | ||
50 | for( int j = 0; j < p.getDims(); j++ ) | ||
51 | p[j]--; | ||
52 | |||
53 | int iCount = 2; | ||
54 | Worm **pWorm = new Worm*[iCount]; | ||
55 | pWorm[0] = new Worm( 1, Position( p.getDims() ), m ); | ||
56 | pWorm[1] = new Worm( 2, p, m ); | ||
57 | /* | ||
58 | Position t( p.getDims() ); | ||
59 | pWorm[0] = new Worm( 1, t, m ); | ||
60 | t[0] = p[0]; | ||
61 | pWorm[1] = new Worm( 2, t, m ); | ||
62 | */ | ||
63 | |||
64 | while( iCount > 0 ) | ||
65 | { | ||
66 | for( int j = 0; j < iCount; j++ ) | ||
67 | { | ||
68 | if( pWorm[j]->timestep() == false ) | ||
69 | { | ||
70 | delete pWorm[j]; | ||
71 | if( j < iCount-1 ) | ||
72 | { | ||
73 | pWorm[j] = pWorm[iCount-1]; | ||
74 | pWorm[iCount-1] = 0; | ||
75 | j--; | ||
76 | } | ||
77 | else | ||
78 | { | ||
79 | pWorm[j] = 0; | ||
80 | } | ||
81 | iCount--; | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | |||
86 | m.connect( 1, 2 ); | ||
87 | |||
88 | // RenderAscii r( m ); | ||
89 | RenderPng r( m ); | ||
90 | r.render(); | ||
91 | |||
92 | |||
93 | return 0; | ||
94 | } | ||
95 | |||