-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource
74 lines (59 loc) · 1.16 KB
/
source
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct CELL
{
double health;
int neighbors;
struct CELL *right, *down;
} CELL;
CELL *connectilize(int size, double world[size][size], int i, int j)
{
if (i >=size || j >=size)
return NULL;
CELL *newCell, *tempCell;
newCell = (CELL*)malloc(sizeof(CELL));
tempCell = newCell;
tempCell->health = world[i][j];
tempCell->right = connectilize(size, world, i, j+1);
tempCell->down = connectilize(size, world, i+1, j);
return tempCell;
}
void seeWorld(CELL *head)
{
CELL *rp;
CELL *dp = head;
while(dp)
{
rp = dp;
while(rp)
{
printf("%.1f ", rp->health);
rp = rp->right;
}
printf("\n");
dp = dp->down;
}
}
int main(int argc, char *argv[])
{
srand(time(NULL));
int size = atoi(argv[1]);
int interations = atoi(argv[2]);
int i, j, k;
double world[size][size];
for (i = 0; i < size; i++)
{
for (j = 0; j < size; j++)
{
world[i][j]=rand() % 5;
printf("%.1f ", world[i][j]);
}
printf("\n");
}
printf("\n");
printf("\n");
CELL *head = connectilize(size, world, 0,0);
seeWorld(head);
return 0;
}