-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalexk-RunDarwin.c++
774 lines (687 loc) · 24.5 KB
/
alexk-RunDarwin.c++
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
// -----------------------------
// projects/darwin/RunDarwin.c++
// Copyright (C) 2013
// Glenn P. Downing
// -----------------------------
/*
To run the program:
% g++ -pedantic -std=c++0x -Wall Darwin.c++ RunDarwin.c++ -o RunDarwin
% valgrind RunDarwin > RunDarwin.out
To configure Doxygen:
doxygen -g
That creates the file Doxyfile.
Make the following edits:
EXTRACT_ALL = YES
EXTRACT_PRIVATE = YES
EXTRACT_STATIC = YES
GENERATE_LATEX = NO
To document the program:
doxygen Doxyfile
*/
// --------
// includes
// --------
#include <cassert> // assert
#include <cstdlib> // rand, srand
#include <iostream> // cout, endl
#include <stdexcept> // invalid_argument, out_of_range
#include "Darwin.h" //for creatures n stuff
// ----
// main
// ----
int main () {
using namespace std;
// ----
// food
// ----
/*
0: left
1: go 0
*/
// ------
// hopper
// ------
/*
0: hop
1: go 0
*/
// -----
// rover
// -----
/*
0: if_enemy 9
1: if_empty 7
2: if_random 5
3: left
4: go 0
5: right
6: go 0
7: hop
8: go 0
9: infect
10: go 0
*/
// ----
// trap
// ----
/*
0: if_enemy 3
1: left
2: go 0
3: infect
4: go 0
*/
// ----------
// darwin 8x8
// ----------
try {
cout << "*** Darwin 8x8 ***" << endl;
int a[] = {Food, east, 0, 0,
Hopper, north, 3, 3,
Hopper, east, 3, 4,
Hopper, south, 4, 4,
Hopper, west, 4, 3,
Food, north, 7, 7};
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(8, 8, v);
b->printGrid();
for(int i = 0; i < 5; i++)
{
b->nextTurn();
b->printGrid();
}
/*
8x8 Darwin
Food, facing east, at (0, 0)
Hopper, facing north, at (3, 3)
Hopper, facing east, at (3, 4)
Hopper, facing south, at (4, 4)
Hopper, facing west, at (4, 3)
Food, facing north, at (7, 7)
Simulate 5 moves.
Print every grid.
*/
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
// ----------
// darwin 7x9
// ----------
try {
cout << "*** Darwin 7x9 ***" << endl;
srand(0);
int a[] = {Trap, south, 0, 0,
Hopper, east, 3, 2,
Rover, north, 5, 4,
Trap, west, 6, 8};
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(7, 9, v);
b->printGrid();
for(int i = 0; i < 5; i++)
{
b->nextTurn();
b->printGrid();
}
/*
7x9 Darwin
Trap, facing south, at (0, 0)
Hopper, facing east, at (3, 2)
Rover, facing north, at (5, 4)
Trap, facing west, at (6, 8)
Simulate 5 moves.
Print every grid.
*/
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
// ------------
// darwin 72x72
// without best
// ------------
try {
cout << "*** Darwin 72x72 without Best ***" << endl;
srand(0);
int x =0;
int a[] = {Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72};
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(72, 72, v);
b->printGrid();
for(int i = 0; i < 10; i++)
{
b->nextTurn();
b->printGrid();
}
for(int j = 10; j < 1000; j++)
{
b->nextTurn();
if(j%100 == 99)
b->printGrid();
}
/*
Randomly place the following creatures facing randomly.
Call rand(), mod it with 5184 (72x72), and use that for the position
in a row-major order grid.
Call rand() again, mod it with 4 and use that for it's direction with
the ordering: west, north, east, south.
Do that for each kind of creature.
10 Food
10 Hopper
10 Rover
10 Trap
Simulate 1000 moves.
Print the first 10 grids (i.e. 0, 1, 2...9).
Print every 100th grid after that (i.e. 100, 200, 300...1000).
*/
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
// ------------
// darwin 72x72
// with best
// ------------
try {
cout << "*** Darwin 72x72 with Best ***" << endl;
srand(0);
int x = 0;
int a[] = {Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Food, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Hopper, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Rover, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Trap, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Best, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Best, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Best, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Best, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Best, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Best, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Best, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Best, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Best, (rand() % 4), (x=(rand() % 5184))/72, x%72,
Best, (rand() % 4), (x=(rand() % 5184))/72, x%72,
};
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(72, 72, v);
b->printGrid();
for(int i = 0; i < 10; i++)
{
b->nextTurn();
b->printGrid();
}
for(int j = 10; j < 1000; j++)
{
b->nextTurn();
if(j%100 == 99)
b->printGrid();
}
/*
Randomly place the following creatures facing randomly.
Call rand(), mod it with 5184 (72x72), and use that for the position
in a row-major order grid.
Call rand() again, mod it with 4 and use that for it's direction with
the ordering: 0:west, 1:north, 2:east, 3:south.
Do that for each kind of creature.
10 Food
10 Hopper
10 Rover
10 Trap
10 Best
Simulate 1000 moves.
Best MUST outnumber ALL other species for the bonus pts.
Print the first 10 grids (i.e. 0, 1, 2...9).
Print every 100th grid after that (i.e. 100, 200, 300...1000).
*/
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
cout << "starting acceptance tests" << endl;
try {
cout << "*** Darwin 72x72 Acceptance test ***" << endl;
srand(0);
int x =0;
int a[] = {
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72,
rand()%5, (rand() % 4), (x=(rand() % 5184))/72, x%72};
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(72, 72, v);
b->printGrid();
for(int i = 0; i < 10; i++)
{
b->nextTurn();
b->printGrid();
}
for(int j = 10; j < 1000; j++)
{
b->nextTurn();
if(j%100 == 99)
b->printGrid();
}
/*
Randomly place the following creatures facing randomly.
Call rand(), mod it with 5184 (72x72), and use that for the position
in a row-major order grid.
Call rand() again, mod it with 4 and use that for it's direction with
the ordering: west, north, east, south.
Do that for each kind of creature, specified by a call to rand % 5.
Simulate 1000 moves.
Print the first 10 grids (i.e. 0, 1, 2...9).
Print every 100th grid after that (i.e. 100, 200, 300...1000).
*/
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
try {
cout << "*** Darwin 100x100 Acceptance Test***" << endl;
srand(0);
int x =0;
int a[] = {
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100,
rand()%5, (rand() % 4), (x=(rand() % 10000))/100, x%100};
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(100, 100, v);
b->printGrid();
for(int i = 0; i < 10; i++)
{
b->nextTurn();
b->printGrid();
}
for(int j = 10; j < 1000; j++)
{
b->nextTurn();
if(j%100 == 99)
b->printGrid();
}
/*
Randomly place the following creatures facing randomly.
Call rand(), mod it with 10000 (100x100), and use that for the position
in a row-major order grid.
Call rand() again, mod it with 4 and use that for it's direction with
the ordering: west, north, east, south.
Do that for each kind of creature, specified by a call to rand % 5.
Simulate 1000 moves.
Print the first 10 grids (i.e. 0, 1, 2...9).
Print every 100th grid after that (i.e. 100, 200, 300...1000).
*/
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
try {
cout << "*** Darwin 1x30 Big Trap ***" << endl;
srand(0);
int a[] = {Rover,east,0,0,
Hopper,west,0,29};
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(1,30, v);
for (int i = 0; i < 20; ++i)
{
b->printGrid();
b->nextTurn();
}
b->printGrid();
/*
in a darwin world of 1 by 30
create a rover at the left side
and a hopper on the right most side facing each other
simulate 20 moves
*/
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
try {
cout << "*** Darwin 4x10 without Best ***" << endl;
srand(0);
int a[] = {
Trap,east,0,0,
Trap,east,1,0,
Trap,east,2,0,
Trap,east,3,0,
Trap,east,0,1,
Trap,east,1,1,
Trap,east,2,1,
Trap,east,3,1,
Rover,east,0,9,
Rover,east,1,9,
Rover,east,2,9,
Rover,east,3,9
};
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(4,10, v);
for (int i = 0; i < 20; ++i)
{
b->printGrid();
b->nextTurn();
}
b->printGrid();
/*
in a darwin world of 4 by 10
8 traps all on the left hand side as much as possible all facing east
create 4 rovers all on the right side all facing east
simulate 20 moves
*/
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
/*1x1 world
1 food at 0,0 facing west
4 moves
print every
watch food look for friends
so cry:'(
*/
try{
cout << "*** Darwin 1x1 Lonely ***" << endl;
srand(0);
int a[] = {Food,west,0,0};
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(1,1, v);
int i;
b->printGrid();
for(i = 1; i <= 4; ++i)
{
b->nextTurn();
b->printGrid();
}
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
try {
cout << "*** BChean's 4x12 (#5) ***" << endl;
int a[] = {
Food, south,4, 0,
Food, south,5, 0,
Food, south,6, 0,
Food, south, 7, 0,
Rover, west,0, 0,
Rover, west,0, 1,
Rover, west,11, 0,
Rover, west, 11, 1,
Trap, north, 4, 2,
Trap, north, 5, 2,
Trap, north, 6, 2,
Trap, north, 7, 2,
Trap, north, 4, 3,
Trap, north,5, 3,
Trap, north, 6, 3,
Trap, north,7, 3
};
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(12, 4, v);
b->printGrid();
for (int i = 0; i < 28; ++i)
{
b->nextTurn();
b->printGrid();
}
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
// ------------
// rover_skinny_board 8x1
// ------------
try {
cout << "*** Rover Skinny Board 8x1 ***" << endl;
srand(0);
int a[] = {Rover, east, 3, 0};
const int NUM_MOVES = 100;
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(8, 1, v);
b->printGrid();
for (int i = 1; i <= NUM_MOVES; ++i) {
b->nextTurn();
if (i % 10 == 0) {
b->printGrid();
}
}
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
//START MY TESTS
try{
cout << "*** Darwin 10X10 Test I ***" << endl;
srand(0);
int a[] = {
Food, south, 5, 5,
Hopper, north, 3, 5,
Hopper, south, 2, 6,
Hopper, east, 1, 9,
Hopper, east, 8, 1,
Rover, south, 2, 5
};
vector<int> v(a, a + sizeof(a) / sizeof(a[0]));
board *b = new board(10, 10, v);
b->printGrid();
for(int i = 1; i < 6; i++){
b->nextTurn();
b->printGrid();
}
}
catch (const invalid_argument&) {
assert(false);}
catch (const out_of_range&) {
assert(false);}
return 0;}