-
Notifications
You must be signed in to change notification settings - Fork 3
/
TUTORIAL.html
968 lines (803 loc) · 34.4 KB
/
TUTORIAL.html
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
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
lang="en" xml:lang="en">
<head>
<title>Tank Wars - 10-Minute Complete Step-by-Step Tutorial</title>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/>
<meta name="generator" content="Org-mode"/>
<meta name="generated" content="2011-03-13 Sun"/>
<meta name="author" content="Tank Wars Team"/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
html { font-family: Verdana; font-size: 12pt; }
.title { text-align: center; }
.todo { color: red; }
.done { color: green; }
.tag { background-color: #add8e6; font-weight:normal }
.target { }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
p.verse { margin-left: 3% }
pre {
border: 1pt solid #AEBDCC;
background-color: #F3F5F7;
padding: 5pt;
font-family: monospace;
font-size: 90%;
overflow:auto;
}
table { border-collapse: collapse; }
td, th { vertical-align: top; }
dt { font-weight: bold; }
div.figure { padding: 0.5em; }
div.figure p { text-align: center; }
.linenr { font-size:smaller }
.code-highlighted {background-color:#ffff00;}
.org-info-js_info-navigation { border-style:none; }
#org-info-js_console-label { font-size:10px; font-weight:bold;
white-space:nowrap; }
.org-info-js_search-highlight {background-color:#ffff00; color:#000000;
font-weight:bold; }
/*]]>*/-->
</style>
<script type="text/javascript">
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
</head>
<body>
<div id="content">
<h1 class="title">Tank Wars - 10-Minute Complete Step-by-Step Tutorial</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">Prerequisites : </a></li>
<li><a href="#sec-2">Introduction : </a></li>
<li><a href="#sec-3">Aim of the Game: </a></li>
<li><a href="#sec-4">Instructions for running the game </a></li>
<li><a href="#sec-5">Your Score and Number of Moves left </a></li>
<li><a href="#sec-6">Step 0 - The co-ordinate axes </a></li>
<li><a href="#sec-7">Step 1 - A simple proof-of-concept Tank: </a></li>
<li><a href="#sec-8">Step 2 - Each of the 8 moves possible </a></li>
<li><a href="#sec-9">Code Example - Attack enemy falcon </a></li>
<li><a href="#sec-10">Step 3 - Carries out each of the four actions </a></li>
<li><a href="#sec-11">Code Example - Attack enemy bunkers </a></li>
<li><a href="#sec-12">Step 4 - Introduce calculate_best_action_plan </a></li>
<li><a href="#sec-13">Code Example - Dodge bullets </a></li>
<li><a href="#sec-14">Step 5 - Creating some local functions for calculations of your own </a></li>
<li><a href="#sec-15">Step 6 - Changing Decision Table weightage </a></li>
<li><a href="#sec-16">Introducing Info </a></li>
<li><a href="#sec-17">Introducing the Map </a></li>
<li><a href="#sec-18">Direction </a></li>
<li><a href="#sec-19">Move </a></li>
<li><a href="#sec-20">Position </a></li>
<li><a href="#sec-21">Object Info </a></li>
<li><a href="#sec-22">Bullet Info </a></li>
<li><a href="#sec-23">Scoring Key </a></li>
<li><a href="#sec-24">Testing </a></li>
<li><a href="#sec-25">Creating maps </a></li>
<li><a href="#sec-26">Hints and Cautions about various advanced strategies </a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Prerequisites : </h2>
<div class="outline-text-2" id="text-1">
<ul>
<li id="sec-1.1">The TankWars.zip file - Unzip it in any folder of your choice <br/>
</li>
<li id="sec-1.2">10 minutes <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Introduction : </h2>
<div class="outline-text-2" id="text-2">
<ul>
<li id="sec-2.1">All you need to do to control your Tank is fill in the get_player_move () function in DecisionMaker1.cpp. <br/>
</li>
<li id="sec-2.2">This tutorial will take you through a series of increasingly complex definitions for that function. <br/>
</li>
<li id="sec-2.3">That will also familiarize you with the general information and structure of the code available to you to make your ultimate, indestructible Tank <br/>
</li>
<li id="sec-2.4">If you're really, REALLY impatient, you can simply check out the code bits under each step and copy-paste them into your DecisionMaker file and run them. You'd probably figure the rest out as you go along. <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Aim of the Game: </h2>
<div class="outline-text-2" id="text-3">
<ul>
<li id="sec-3.1">To end the game with maximum points <br/>
</li>
<li id="sec-3.2">The game ends when either your Falcon (military base) is killed or if your Tank dies or if the same happens to the opponent or if the Maximum number of moves are exceeded <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-4" class="outline-2">
<h2 id="sec-4">Instructions for running the game </h2>
<div class="outline-text-2" id="text-4">
<ul>
<li id="sec-4.1">Simply open a terminal and type <br/>
<p><br/>
<pre class="src src-bash">make play
</pre>
</p></li>
<li id="sec-4.2">To display the game in your browser, just type <br/>
<p><br/>
<pre class="src src-bash">make display
</pre>
</p></li>
</ul>
</div>
</div>
<div id="outline-container-5" class="outline-2">
<h2 id="sec-5">Your Score and Number of Moves left </h2>
<div class="outline-text-2" id="text-5">
<ul>
<li id="sec-5.1">The get_player_move () function receives <br/>
<ul>
<li id="sec-5.1.1">Your score [my_score] and <br/>
</li>
<li id="sec-5.1.2">Your enemy's score [enemy_score]. <br/>
</li>
</ul>
</li>
<li id="sec-5.2">It also receives the [total_moves_done] so far <br/>
</li>
<li id="sec-5.3">MAX_NUMBER_OF_MOVES tells you how many moves you can make <br/>
</li>
<li id="sec-5.4"><a href="#sec-23">Scoring Key</a> <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-6" class="outline-2">
<h2 id="sec-6">Step 0 - The co-ordinate axes </h2>
<div class="outline-text-2" id="text-6">
<p><br/>
(0, 0)<br/>
+————————> (y-axis)<br/>
v<br/>
(x-axis)<br/>
</p>
<p><br/>
^ UP <br/>
LEFT | RIGHT<br/>
<–——|–——><br/>
v DOWN<br/>
</p>
<p><br/>
</p></div>
</div>
<div id="outline-container-7" class="outline-2">
<h2 id="sec-7">Step 1 - A simple proof-of-concept Tank: </h2>
<div class="outline-text-2" id="text-7">
<ul>
<li id="sec-7.1">Just type : <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #a020f0;">return</span> Move (GO_RIGHT);
</pre>
</p></li>
<li id="sec-7.2">Not surprisingly, this makes your Tank move right each time <br/>
</li>
<li id="sec-7.3">However, that would have either led to it being shot by one of the Machine Guns out there or inevitably dashing into a wall and dying. <br/>
</li>
<li id="sec-7.4">Note : If your Tank dies, the opponent gains 400 points, so that is another incentive to stay alive <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-8" class="outline-2">
<h2 id="sec-8">Step 2 - Each of the 8 moves possible </h2>
<div class="outline-text-2" id="text-8">
<ul>
<li id="sec-8.1">Choose any one of the following 8 moves <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Go in one of the four directions
</span><span style="color: #a020f0;">return</span> Move (GO_UP);
<span style="color: #a020f0;">return</span> Move (GO_DOWN);
<span style="color: #a020f0;">return</span> Move (GO_LEFT);
<span style="color: #a020f0;">return</span> Move (GO_RIGHT);
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Shoot in one of the four directions
</span><span style="color: #a020f0;">return</span> Move (SHOOT_UP);
<span style="color: #a020f0;">return</span> Move (SHOOT_DOWN);
<span style="color: #a020f0;">return</span> Move (SHOOT_LEFT);
<span style="color: #a020f0;">return</span> Move (SHOOT_RIGHT);
</pre>
</p></li>
<li id="sec-8.2">Documentation - <a href="#sec-19">Move</a> <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-9" class="outline-2">
<h2 id="sec-9">Code Example - Attack enemy falcon </h2>
<div class="outline-text-2" id="text-9">
<ul>
<li id="sec-9.1">Let's dive into the actual coding process by skipping all the boring documentation bit <br/>
</li>
<li id="sec-9.2">How would you attack the Enemy Falcon? <br/>
</li>
<li id="sec-9.3">For that you need 3 things <br/>
<ul>
<li id="sec-9.3.1">The position of the falcon <br/>
</li>
<li id="sec-9.3.2">The next move you have to make in order to get closer to it <br/>
</li>
<li id="sec-9.3.3">And the direction to shoot in so that you hit the Falcon <br/>
</li>
</ul>
</li>
<li id="sec-9.4">The answers are in the variable my_info in the DecisionMaker class <br/>
</li>
<li id="sec-9.5">It contains <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #228b22;">object_info</span> <span style="color: #b8860b;">opp_falcon</span>;
</pre>
</p></li>
<li id="sec-9.6">Also, my_info contains a boolean - can_shoot_at_enemy_falcon - which is true whenever the Falcon is in your sights <br/>
</li>
<li id="sec-9.7">The resulting code is simple enough <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">If you can shoot at the Enemy Falcon from the current position, do so
</span><span style="color: #228b22;">Move</span> <span style="color: #b8860b;">my_next_move</span>;
<span style="color: #a020f0;">if</span> (my_info.can_shoot_at_enemy_falcon){
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">This is the move to go closer
</span> my_next_move = my_info.my_falcon.initial_move;
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">However, we don't want to go closer
</span> <span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">We want to shoot in that direction!
</span> my_next_move.shoot = <span style="color: #5f9ea0;">true</span>;
<span style="color: #a020f0;">return</span> my_next_move;
}
<span style="color: #a020f0;">else</span>{
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Just go closer
</span> my_next_move = my_info.my_falcon.initial_move;
<span style="color: #a020f0;">return</span> my_next_move;
}
</pre>
</p></li>
<li id="sec-9.8">Documentation - <a href="#sec-20">Position</a> <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-10" class="outline-2">
<h2 id="sec-10">Step 3 - Carries out each of the four actions </h2>
<div class="outline-text-2" id="text-10">
<ul>
<li id="sec-10.1">Let's try making some more complex moves <br/>
</li>
<li id="sec-10.2">Say you want to pick up the gold piece nearest to you <br/>
</li>
<li id="sec-10.3">It's simple. All you need to do is <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #228b22;">int</span> <span style="color: #b8860b;">my_action_plan</span> = GO_TO_NEAREST_GOLD
get_best_move_for (my_action_plan)
</pre>
</p></li>
<li id="sec-10.4">You can pass any of the following default Action Plans as parameters <br/>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col align="left" /><col align="left" />
</colgroup>
<tbody>
<tr><td>GO_TO_NEAREST_GOLD</td><td>Each time, your Tank will move in the direction of the nearest gold piece. Neat, huh?</td></tr>
<tr><td>ATTACK_ENEMY_FALCON</td><td>That will take your Tank closer to the Enemy Falcon and shoot if it is in your sights.</td></tr>
<tr><td>ATTACK_ENEMY_TANK</td><td>This will take your Tank closer to the Enemy Tank and shoot if it is in your sights</td></tr>
<tr><td>DEFEND_MY_FALCON</td><td>Just go back towards your Falcon so that you can defend it from any attack</td></tr>
</tbody>
</table>
</li>
<li id="sec-10.5">get_best_move_for, as the name suggests, gets you the best move you could make for a particular Action Plan. <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-11" class="outline-2">
<h2 id="sec-11">Code Example - Attack enemy bunkers </h2>
<div class="outline-text-2" id="text-11">
<ul>
<li id="sec-11.1">Again, my_info comes to the rescue. You have a vector of object_infos which tell you about each bunker's position, distance from you, initial_move, etc. <br/>
</li>
<li id="sec-11.2">Code is pretty much the same as for attack enemy falcon <br/>
</li>
<li id="sec-11.3">And, you can do the same to attack the Enemy Tank itself! <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-12" class="outline-2">
<h2 id="sec-12">Step 4 - Introduce calculate_best_action_plan </h2>
<div class="outline-text-2" id="text-12">
<ul>
<li id="sec-12.1">However, it can get pretty monotonous doing the same action again and again. <br/>
</li>
<li id="sec-12.2">To aid in making your Tank dynamic and more adaptive, we have come up with a rudimentary Decision Making model <br/>
You can use it to calculate the best moves for your Tank based on the situation and your preferences.<br/>
</li>
<li id="sec-12.3">We provide four different strategies that you can choose by default. <br/>
</li>
<li id="sec-12.4">They are <br/>
<ul>
<li id="sec-12.4.1">AGGRESSIVE <br/>
</li>
<li id="sec-12.4.2">DEFENSIVE <br/>
</li>
<li id="sec-12.4.3">GREEDY <br/>
</li>
<li id="sec-12.4.4">CUSTOMIZED <br/>
</li>
</ul>
</li>
<li id="sec-12.5">To put it in action, just say <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #228b22;">int</span> <span style="color: #b8860b;">my_strategy</span> = AGGRESSIVE;
<span style="color: #228b22;">int</span> <span style="color: #b8860b;">my_action_plan</span> = calculate_best_action_plan_for (my_strategy);
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Now, my_action_plan will contain one of the four basic action plans mentioned above
</span><span style="color: #a020f0;">return</span> get_best_move_for (my_action_plan);
</pre>
</p></li>
<li id="sec-12.6">Explanation <br/>
<ul>
<li id="sec-12.6.1">What calculate_best_action_plan_for does is it looks for the utility or expected benefits of each of the four default Action Plans. <br/>
</li>
<li id="sec-12.6.2">This is done based on the weightage given for each plan and the difficulty of carrying each plan out as defined in your DecisionMaker object. <br/>
</li>
<li id="sec-12.6.3">It then returns the Action Plan which has maximum expected benefit <br/>
</li>
<li id="sec-12.6.4">To see what the default weightages are, go to DECISION_MAKER::DMinitializer function in DecisionMaker1.cpp <br/>
</li>
<li id="sec-12.6.5">To see how the default difficulty values are determined, go to DECISION_MAKER::fill_difficulty_table function in DecisionMaker1.cpp <br/>
</li>
<li id="sec-12.6.6">By default, the difficulty of carrying out an action plan is the shortest distance to the goal object. ie. for GO_TO_NEAREST_GOLD, the difficulty is the distance to the nearest gold <br/>
</li>
<li id="sec-12.6.7">In short, if a particular Action Plan, say ATTACK_ENEMY_TANK, is given higher weightage than the others then it will be recommended as the best plan when the distance from the enemy tank is not too high <br/>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-13" class="outline-2">
<h2 id="sec-13">Code Example - Dodge bullets </h2>
<div class="outline-text-2" id="text-13">
<ul>
<li id="sec-13.1">If you play the game for long enough, you'll find that most of the time, your Tank dies because it was hit by some bullet <br/>
</li>
<li id="sec-13.2">Let's try to dodge those pesky bullets <br/>
</li>
<li id="sec-13.3">A naive method <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #228b22;">bullet_info</span> <span style="color: #b8860b;">curr_bullet</span>;
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Tank's current position
</span>posn = my_info.curr_posn;
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Go this many steps to the RIGHT and see if any bullet there is
</span><span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">coming towards you
</span><span style="color: #a020f0;">for</span> (i = 1; i <= BULLET_SPEED; i++){
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Make posn become the position to its right
</span> posn.go_in_direction (Direction (RIGHT));
safe_dirn = UP; <span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Direction in which to dodge
</span> opposite_dirn = LEFT; <span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Direction in which bullets will come
</span>
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">For each bullet out there
</span> <span style="color: #a020f0;">for</span> (j = 0; j < my_info.machine_gun_bullets.size (); j++){
curr_bullet = my_info.machine_gun_bullets[j];
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">If you are within its range and if it is coming towards you
</span> <span style="color: #a020f0;">if</span> (curr_bullet.posn == posn && curr_bullet.dirn == Direction (opposite_dirn)){
<span style="color: #a020f0;">return</span> Move (safe_dirn); <span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Dodge
</span> }
}
}
</pre>
</p></li>
<li id="sec-13.4">This example introduces <br/>
<ul>
<li id="sec-13.4.1">Position curr_posn <br/>
</li>
<li id="sec-13.4.2">BULLET_SPEED <br/>
Each bullet travels BULLET_SPEED steps in one move<br/>
</li>
<li id="sec-13.4.3">Direction <br/>
Documentation - <a href="#sec-18">Direction</a><br/>
</li>
<li id="sec-13.4.4">Bullet Lists in my_info <br/>
Documentation - <a href="#sec-22">Bullet Info</a><br/>
<ul>
<li id="sec-13.4.4.1">The info object contains 3 Bullet Lists <br/>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col align="left" /><col align="left" />
</colgroup>
<tbody>
<tr><td>my_bullets</td><td>List of info about all my bullets</td></tr>
<tr><td>enemy_bullets</td><td>List of info about all enemy bullets</td></tr>
<tr><td>machine_gun_bullets</td><td>List of info about all MG bullets</td></tr>
</tbody>
</table>
</li>
</ul>
</li>
</ul>
</li>
<li id="sec-13.5">Of course, it is just a toy example. :-) <br/>
</li>
<li id="sec-13.6">Your actual function should take care of a lot of factors and check for various corner cases. Good Luck! :-) <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-14" class="outline-2">
<h2 id="sec-14">Step 5 - Creating some local functions for calculations of your own </h2>
<div class="outline-text-2" id="text-14">
<ul>
<li id="sec-14.1">Simple. You can just create new functions in the DecisionMaker1.cpp file and call them. <br/>
</li>
<li id="sec-14.2">Just remember not to change anything anywhere else. <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-15" class="outline-2">
<h2 id="sec-15">Step 6 - Changing Decision Table weightage </h2>
<div class="outline-text-2" id="text-15">
<ul>
<li id="sec-15.1">Of course, you don't have to put up with the default weightages or the default ways of calculating difficulties. Try experimenting. <br/>
</li>
<li id="sec-15.2">Go to [ DMinitializer function ] <br/>
</li>
<li id="sec-15.3">For example, if you feel DEFENSIVE plan should never even consider ATTACK_ENEMY_TANK or ATTACK_ENEMY_FALCON, then put weightages for them as 0. <br/>
</li>
<li id="sec-15.4">Maybe set GREEDY's weightage for GO_TO_NEAREST_GOLD as 100 and everything else as 0. That's really greedy! :-). Be careful, though, chances of getting shot by Machine Guns and the Enemy tank are very high. <br/>
</li>
<li id="sec-15.5">You can set the values for each Strategy in the Weightage Table on the fly by calling <br/>
<p><br/>
<pre class="src src-c++">set_weightage_table (AGGRESSIVE, 20, 80, 80, 0);
</pre>
</p></li>
<li id="sec-15.6"><a name="Info" id="Info"></a>This can be useful when you want to tweaks based on the current situation <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-16" class="outline-2">
<h2 id="sec-16">Introducing Info </h2>
<div class="outline-text-2" id="text-16">
<ul>
<li id="sec-16.1">Info object contains pretty much all the basic game information you're going to need <br/>
</li>
<li id="sec-16.2">This way you don't even have to know what Breadth-First Search means or deal with things like 'What is the next move to make in order to shoot the Enemy Falcon?'. Phew! <br/>
</li>
<li id="sec-16.3">DecisionMaker contains two objects <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #228b22;">Info</span> <span style="color: #b8860b;">my_info</span>;
<span style="color: #228b22;">Info</span> <span style="color: #b8860b;">opp_info</span>;
</pre>
</p></li>
<li id="sec-16.4">my_info pertains to information about your Tank <br/>
</li>
<li id="sec-16.5">opp_info pertains to information about the Enemy Tank <br/>
</li>
<li id="sec-16.6">Contents <br/>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col align="left" /><col align="left" /><col align="left" />
</colgroup>
<thead>
<tr><th scope="col">Type</th><th scope="col">Variable</th><th scope="col">Value</th></tr>
</thead>
<tbody>
<tr><td>Position</td><td>curr_posn</td><td>Your current Position</td></tr>
<tr><td>ID</td><td>my_ID</td><td>Your ID</td></tr>
<tr><td>ID</td><td>enemy_ID</td><td>Enemy ID</td></tr>
<tr><td>bool</td><td>can_shoot_at_enemy_tank</td><td>Whether the enemy tank is in your sights</td></tr>
<tr><td>bool</td><td>can_shoot_at_enemy_falcon</td><td>Whether the enemy Falcon is in your sights</td></tr>
<tr><td>Direction</td><td>shoot_falcon_dirn</td><td>Direction in which Enemy Falcon lies</td></tr>
<tr><td>Direction</td><td>shoot_enemy_tank_dirn</td><td>Direction in which Enemy Tank lies</td></tr>
<tr><td>Vector of Bullet Info</td><td>my_bullets</td><td>Information about all bullets you shot</td></tr>
<tr><td>Vector of Bullet Info</td><td>enemy_bullets</td><td>Information about all bullets the Enemy shot</td></tr>
<tr><td>Vector of Bullet Info</td><td>machine_gun_bullets</td><td>Information about all bullets the MGs shot</td></tr>
<tr><td>Vector of object_infos</td><td>gold</td><td>Information about all gold pieces</td></tr>
<tr><td>Object_info</td><td>my_falcon</td><td>Information about your falcon</td></tr>
<tr><td>Object_info</td><td>opp_falcon</td><td>Information about Enemy falcon</td></tr>
<tr><td>Object_info</td><td>opp_tank</td><td>Information about Enemy Tank</td></tr>
<tr><td>Object_info</td><td>nearest_gold</td><td>Information about the nearest gold piece</td></tr>
<tr><td>bool</td><td>gold_available</td><td>Do any more gold pieces exist on Map?</td></tr>
</tbody>
</table>
<ul>
<li id="sec-16.6.1"><a name="Map" id="Map"></a>That's all <br/>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-17" class="outline-2">
<h2 id="sec-17">Introducing the Map </h2>
<div class="outline-text-2" id="text-17">
<ul>
<li id="sec-17.1">OK! So, now you have an all-new, shiny, mean and destructive Tank at your command. <br/>
</li>
<li id="sec-17.2">But, how exactly do you analyze the game? <br/>
</li>
<li id="sec-17.3">How do you know what to do? Should you be GREEDY? Should you switch to an AGGRESSIVE strategy? Should you do something else altogether? <br/>
</li>
<li id="sec-17.4">For that you need to look at the "Map" <br/>
</li>
<li id="sec-17.5">It is nothing but the 2-D array of cells in which all the Tanks, Bunkers, Falcons, Walls, etc. are stored. <br/>
</li>
<li id="sec-17.6">Each object occupies one cell. <br/>
</li>
<li id="sec-17.7">Your DecisionMaker class will have an object called <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #228b22;">MapClass</span> <span style="color: #b8860b;">my_map</span>;
</pre>
</p></li>
<li id="sec-17.8">This contains a 2-D array - <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #228b22;">char</span> <span style="color: #b8860b;">map</span>[MAP_SIZE][MAP_SIZE];
</pre>
</p></li>
<li id="sec-17.9">This is what will get updated each time as your Tank and your Enemy's tank move around and shoot bullets <br/>
</li>
<li id="sec-17.10"><a name="Symbols" id="Symbols"></a>This is what is shown in your browser when you call 'make display' <br/>
</li>
<li id="sec-17.11">The character symbols represent various objects <br/>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col align="left" /><col align="left" /><col align="left" />
</colgroup>
<thead>
<tr><th scope="col">Object</th><th scope="col">Constant defined</th><th scope="col">Actual character</th></tr>
</thead>
<tbody>
<tr><td>Gold piece</td><td>GOLD</td><td>G</td></tr>
<tr><td>Wall</td><td>WALL</td><td>#</td></tr>
<tr><td>Empty cell</td><td>EMPTY</td><td>.</td></tr>
<tr><td>Dead Tank / MG</td><td>DEAD</td><td>D</td></tr>
<tr><td>Tank 1</td><td>TANK1</td><td>1</td></tr>
<tr><td>Bunker of Tank 1</td><td>BUNKER1</td><td>X</td></tr>
<tr><td>Falcon of Tank 1</td><td>FALCON1</td><td>F</td></tr>
<tr><td>Bullet of Tank 1</td><td>BULLET1</td><td>A</td></tr>
<tr><td>Tank 2</td><td>TANK2</td><td>2</td></tr>
<tr><td>Bunker of Tank 2</td><td>BUNKER2</td><td>Y</td></tr>
<tr><td>Falcon of Tank 2</td><td>FALCON2</td><td>E</td></tr>
<tr><td>Bullet of Tank 2</td><td>BULLET2</td><td>B</td></tr>
<tr><td>Machine Gun</td><td>MACHINE_GUN</td><td>M</td></tr>
<tr><td>Bullet of MG</td><td>MACHINE_GUN_BULLET</td><td>K</td></tr>
</tbody>
</table>
</li>
<li id="sec-17.12">You can access the elements of the map[][] array directly. Like so <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #a020f0;">if</span> (my_map.map[i][j] == WALL){
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Then do something
</span>}
<span style="color: #a020f0;">else</span> <span style="color: #a020f0;">if</span> (my_map.map[i][j] == GOLD){
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Go for it!
</span>}
</pre>
</p></li>
<li id="sec-17.13">Or, more simply, you can simply use Positions <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #228b22;">Direction</span> <span style="color: #b8860b;">d</span> = Direction (RIGHT); <span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">or (LEFT) or (0), (1), etc.
</span>my_neighbour = curr_posn.get_neighbour (d);
<span style="color: #a020f0;">if</span> (my_map.get_element (my_neighbour) == WALL){
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Then do something
</span>}
<span style="color: #a020f0;">else</span> <span style="color: #a020f0;">if</span> (my_map.get_element (my_neighbour) == GOLD){
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Go for it!
</span>}
</pre>
</p></li>
</ul>
</div>
</div>
<div id="outline-container-18" class="outline-2">
<h2 id="sec-18"><a name="Direction" id="Direction"></a>Direction </h2>
<div class="outline-text-2" id="text-18">
<ul>
<li id="sec-18.1">Basically just a pair - xdir and ydir <br/>
</li>
<li id="sec-18.2">You can use it in different ways <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #228b22;">Direction</span> <span style="color: #b8860b;">dirn</span> = Direction (LEFT); <span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">RIGHT, etc
</span><span style="color: #228b22;">Direction</span> <span style="color: #b8860b;">dirn2</span> = dirn;
<span style="color: #a020f0;">if</span> (dirn == Direction (1)){ <span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">1 : DOWN
</span> <span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Something or the other
</span>}
</pre>
</p></li>
</ul>
</div>
</div>
<div id="outline-container-19" class="outline-2">
<h2 id="sec-19"><a name="Move" id="Move"></a>Move </h2>
<div class="outline-text-2" id="text-19">
<ul>
<li id="sec-19.1">It has two variables <br/>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col align="left" /><col align="left" />
</colgroup>
<tbody>
<tr><td>bool</td><td>shoot</td></tr>
<tr><td>Direction</td><td>dirn</td></tr>
</tbody>
</table>
</li>
<li id="sec-19.2">Usage <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #228b22;">Move</span> <span style="color: #b8860b;">my_move</span> = Move (SHOOT_LEFT);
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">or
</span><span style="color: #228b22;">Move</span> <span style="color: #b8860b;">move1</span>;
move1.shoot = <span style="color: #5f9ea0;">true</span>;
move1.dirn = Direction (LEFT);
<span style="color: #228b22;">Move</span> <span style="color: #b8860b;">move2</span> = move1;
</pre>
</p></li>
</ul>
</div>
</div>
<div id="outline-container-20" class="outline-2">
<h2 id="sec-20"><a name="Position" id="Position"></a>Position </h2>
<div class="outline-text-2" id="text-20">
<ul>
<li id="sec-20.1">Again just a pair - x, y <br/>
</li>
<li id="sec-20.2">Main usage <br/>
<p><br/>
<pre class="src src-c++"><span style="color: #228b22;">Position</span> <span style="color: #b8860b;">posn</span> = my_info.curr_posn;
my_left_neighbour = posn.get_neighbour (Direction (LEFT));
posn.go_in_direction (Direction (RIGHT));
<span style="color: #99968b; font-style: italic;">// </span><span style="color: #b22222;">Now, posn is the cell to the right
</span></pre>
</p></li>
</ul>
</div>
</div>
<div id="outline-container-21" class="outline-2">
<h2 id="sec-21"><a name="Object==Info" id="Object==Info"></a>Object Info </h2>
<div class="outline-text-2" id="text-21">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col align="left" /><col align="left" />
</colgroup>
<thead>
<tr><th scope="col">Variable</th><th scope="col">Value</th></tr>
</thead>
<tbody>
<tr><td>shortest_distance</td><td>Shortest Distance to the Object</td></tr>
<tr><td>posn</td><td>The Position of the Object</td></tr>
<tr><td>initial_move</td><td>The Move you need to make now to get closer to the Object</td></tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-22" class="outline-2">
<h2 id="sec-22"><a name="Bullet==Info" id="Bullet==Info"></a>Bullet Info </h2>
<div class="outline-text-2" id="text-22">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col align="left" /><col align="left" />
</colgroup>
<tbody>
<tr><td>posn</td><td>Current position of the Bullet</td></tr>
<tr><td>dirn</td><td>Direction in which it is travelling</td></tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-23" class="outline-2">
<h2 id="sec-23"><a name="Scoring==Key" id="Scoring==Key"></a>Scoring Key </h2>
<div class="outline-text-2" id="text-23">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col align="left" /><col align="right" />
</colgroup>
<thead>
<tr><th scope="col">Event</th><th scope="col">Points</th></tr>
</thead>
<tbody>
<tr><td>ENEMY_FALCON_KILLED</td><td>1000</td></tr>
<tr><td>ENEMY_KILLED</td><td>500</td></tr>
<tr><td>ALIVE_AT_THE_END</td><td>400</td></tr>
<tr><td>DESTROYED_ENEMY_BUNKER</td><td>65</td></tr>
<tr><td>PICKED_UP_GOLD</td><td>40</td></tr>
<tr><td>TIME_LIMIT_EXCEEDED</td><td>-300</td></tr>
<tr><td>INVALID_MOVE</td><td>-100</td></tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-24" class="outline-2">
<h2 id="sec-24">Testing </h2>
<div class="outline-text-2" id="text-24">
<ul>
<li id="sec-24.1">You can test your bots on your own computer by changing the code for DecisionMaker2 as well. <br/>
</li>
<li id="sec-24.2">You can even run your bot against another bot just like itself and seet what the result is! :-) <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-25" class="outline-2">
<h2 id="sec-25">Creating maps </h2>
<div class="outline-text-2" id="text-25">
<ul>
<li id="sec-25.1">To test your bot's functionality, you can try creating your own maps <br/>
</li>
<li id="sec-25.2">Simply edit 'map.txt' in your Tank-Wars folder <br/>
</li>
<li id="sec-25.3">The symbols representing each object are described in <a href="#sec-17.10">Symbols</a> <br/>
</li>
<li id="sec-25.4">The only conditions on the Map are that it should have <br/>
<ul>
<li id="sec-25.4.1">TANK1 <br/>
</li>
<li id="sec-25.4.2">TANK2 <br/>
</li>
<li id="sec-25.4.3">FALCON1 <br/>
</li>
<li id="sec-25.4.4">FALCON2 <br/>
</li>
</ul>
</li>
<li id="sec-25.5">That's all <br/>
</li>
<li id="sec-25.6">Some sample maps are present in maps/ directory. <br/>
</li>
</ul>
</div>
</div>
<div id="outline-container-26" class="outline-2">
<h2 id="sec-26">Hints and Cautions about various advanced strategies </h2>
<div class="outline-text-2" id="text-26">
<ul>
<li id="sec-26.1">Make sure you can handle Bunkers (both yours and the enemy's). Maps in the tournament will be more and more complex <br/>
</li>
<li id="sec-26.2">Make sure that your bot doesn't get stuck shooting continuously in the same direction <br/>
That can happen when both you and the enemy tank are facing each other and want to kill each other. The game might go on and on with you both shooting at each other<br/>
</li>
<li id="sec-26.3">Make sure you prioritize according to the situations and the point allocation. <br/>
</li>
</ul>
</div>
</div>
<div id="postamble">
<p class="author"> Author: Tank Wars Team
<a href="mailto:[email protected]"><[email protected]></a>
</p>
<p class="date"> Date: 2011-03-13 Sun</p>
<p class="creator">HTML generated by org-mode 6.33x in emacs 23</p>
</div>
</div>
</body>
</html>