-
Notifications
You must be signed in to change notification settings - Fork 0
/
Raw Code
3438 lines (3438 loc) · 126 KB
/
Raw Code
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
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"cells": [
{
"cell_type": "markdown",
"id": "fd9debd6",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"source": [
"# Lux AI Season 2 Tutorial - Python Kit\n",
"\n",
"Welcome to Lux AI Season 2!\n",
"\n",
"This notebook is the basic setup to use Jupyter Notebooks and the kaggle-environments package to develop your bot. If you plan to not use Jupyter Notebooks or any other programming language, please see our Github. The following are some important links!\n",
"\n",
"Competition Page: https://www.kaggle.com/c/lux-ai-season-2/\n",
"\n",
"Online Visualizer: https://s2vis.lux-ai.org/\n",
"\n",
"Specifications: https://www.lux-ai.org/specs-s2\n",
"\n",
"Github: https://github.com/Lux-AI-Challenge/Lux-Design-S2\n",
"\n",
"Bot API: https://github.com/Lux-AI-Challenge/Lux-Design-S2/tree/main/kits\n",
"\n",
"And if you haven't done so already, we highly recommend you join our Discord server at https://discord.gg/aWJt3UAcgn or at the minimum follow the kaggle forums at https://www.kaggle.com/c/lux-ai-season-2/discussion. We post important announcements there such as changes to rules, events, and opportunities from our sponsors!\n",
"\n",
"Now let's get started!"
]
},
{
"cell_type": "markdown",
"id": "75339acc",
"metadata": {
"execution": {
"iopub.status.busy": "2023-01-24T18:02:29.549628Z",
"iopub.status.idle": "2023-01-24T18:02:29.550292Z",
"shell.execute_reply": "2023-01-24T18:02:29.550099Z",
"shell.execute_reply.started": "2023-01-24T18:02:29.550071Z"
},
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"source": [
"## Basic Setup\n",
"First thing to verify is that you have python 3.7 or above and have the [luxai_s2](https://pypi.org/project/luxai_s2/) package installed. Run the command below to do so. If you are using Kaggle Notebooks, **make sure to also click run-> restart and clear cell outputs** on the top right next to view and add-ons. (This fixes a bug where Kaggle Notebooks loads an incompatible package)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "26688963",
"metadata": {
"_kg_hide-input": true,
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"# verify version\n",
"!python --version\n",
"!pip install --upgrade luxai_s2\n",
"!pip install gym==0.19\n",
"!cp -r ../input/lux-ai-season-2/* ."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d7cb6ee3",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"%%writefile /opt/conda/lib/python3.7/site-packages/luxai_s2/version.py\n",
"__version__ = \"\"\n",
"# this code above is used for Kaggle Notebooks\n",
"# You might not need to run this but if you get an attribute error about the gym package, run it"
]
},
{
"cell_type": "markdown",
"id": "ebcf4362",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"source": [
"Once the above is installed, make sure to restart and clear cell outputs otherwise the code below won't run. Once that is done we can get started!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b1c61eb",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"from luxai_s2.env import LuxAI_S2\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "983d3530",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"from lux.kit import obs_to_game_state, GameState, EnvConfig\n",
"from luxai_s2.utils import animate\n",
"from lux.utils import direction_to, my_turn_to_place_factory\n",
"import gym"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ac007bdb",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e971be96",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"def animate(imgs, _return=True):\n",
" # using cv2 to generate videos as moviepy doesn't work on kaggle notebooks\n",
" import cv2\n",
" import os\n",
" import string\n",
" import random\n",
" video_name = ''.join(random.choice(string.ascii_letters) for i in range(18))+'.webm'\n",
" height, width, layers = imgs[0].shape\n",
" fourcc = cv2.VideoWriter_fourcc(*'VP90')\n",
" video = cv2.VideoWriter(video_name, fourcc, 10, (width,height))\n",
"\n",
" for img in imgs:\n",
" img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n",
" video.write(img)\n",
" video.release()\n",
" if _return:\n",
" from IPython.display import Video\n",
" return Video(video_name)\n",
"def interact(env, agents, steps):\n",
" # reset our env\n",
" obs = env.reset()\n",
" np.random.seed(0)\n",
" imgs = []\n",
" step = 0\n",
" # Note that as the environment has two phases, we also keep track a value called \n",
" # `real_env_steps` in the environment state. The first phase ends once `real_env_steps` is 0 and used below\n",
"\n",
" # iterate until phase 1 ends\n",
" while env.state.real_env_steps < 0:\n",
" if step >= steps: break\n",
" actions = {}\n",
" for player in env.agents:\n",
" o = obs[player]\n",
" a = agents[player].early_setup(step, o)\n",
" actions[player] = a\n",
" step += 1\n",
" obs, rewards, dones, infos = env.step(actions)\n",
" imgs += [env.render(\"rgb_array\", width=640, height=640)]\n",
" done = False\n",
" while not done:\n",
" if step >= steps: break\n",
" actions = {}\n",
" for player in env.agents:\n",
" o = obs[player]\n",
" a = agents[player].act(step, o)\n",
" actions[player] = a\n",
" step += 1\n",
" obs, rewards, dones, infos = env.step(actions)\n",
" imgs += [env.render(\"rgb_array\", width=640, height=640)]\n",
" done = dones[\"player_0\"] and dones[\"player_1\"]\n",
" return animate(imgs)"
]
},
{
"cell_type": "markdown",
"id": "d3a7d775",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"source": [
"We can now create an environment and start interacting with it, as well as look at what the observation is like"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d3cc42d8",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"env = LuxAI_S2() # create the environment object\n",
"obs = env.reset(seed=41) # resets an environment with a seed"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c201a5b6",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"#przyklad slownika\n",
"# stolice = {'Polska':'Warszawa', 'Singapur': 'Singapur_miasto'}\n",
"\n",
"# slownik = dict()\n",
"# slownik['Niemcy'] = 'Berlin'\n",
"# slownik['Polska'] = 'Warszawa'\n",
"\n",
"# slownik"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dfa84779",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"# the observation is always composed of observations for both players.\n",
"obs.keys(), obs[\"player_0\"].keys()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e470404a",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"env.agents"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80b8549f",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"env.state.env_cfg"
]
},
{
"cell_type": "markdown",
"id": "c47d8f28",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"source": [
"### Lokalizacja startowa"
]
},
{
"cell_type": "markdown",
"id": "66eebc2b",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"source": [
"To visualize the environment, on jupyter notebooks you have two options\n",
"\n",
"With the `rgb_array` mode you can visualize every step as an environment episode progresses. \n",
"\n",
"With the CLI tool, you can run an episode and save a replay.json to upload to https://s2vis.lux-ai.org/ or a replay.html file to directly open and watch"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2f6472a1",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"# visualize the environment so far with rgb_array to get a quick look at the map\n",
"# dark orange - high rubble, light orange - low rubble\n",
"# blue = ice, yellow = ore\n",
"map_rendered = env.render(\"rgb_array\", width=1000, height=1000)\n",
"plt.imshow(map_rendered)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20da5cd3",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"ice = obs[\"player_0\"][\"board\"][\"ice\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "235dad51",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"type(ice)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c26aa907",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"ice.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2463937b",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"plt.imshow(ice)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fb88b12f",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"from scipy.ndimage import distance_transform_cdt\n",
"\n",
"def manhattan_distance(binary_mask):\n",
" # Get the distance map from every pixel to the nearest positive pixel\n",
" distance_map = distance_transform_cdt(binary_mask, metric='taxicab')\n",
" return distance_map"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "59c95b83",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"dist_ice = manhattan_distance(1-ice)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "090f7c4e",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"dist_ice"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8aa79a4",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(18, 5))\n",
"im1 = ax1.imshow(map_rendered )\n",
"ax1.set_title('map')\n",
"im2 = ax2.imshow(ice)\n",
"ax2.set_title(\"ice\")\n",
"im3 = ax3.imshow(dist_ice)\n",
"ax3.set_title(\"distance to the closest ice\")\n",
"fig.colorbar(im3, ax=ax3)\n",
"plt.figure(dpi=150)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e2cdb44",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"valid_spawn_locations = obs[\"player_0\"][\"board\"][\"valid_spawns_mask\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9fd20426",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"valid_spawn_locations.shape, dist_ice.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e6a49e39",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"valid_spawn_locations"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b6b81d55",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"dist_ice"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7cbc2e81",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"valid_spawn_locations*dist_ice"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f72e834b",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"dist_ice"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e682f3fe",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"dist_ice.max()-dist_ice"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e529cbb",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(18, 5))\n",
"im1 = ax1.imshow(valid_spawn_locations)\n",
"ax1.set_title('valid spawn locations')\n",
"im2 = ax2.imshow(dist_ice)\n",
"ax2.set_title(\"distance to ice\")\n",
"start_map = valid_spawn_locations*(dist_ice.max()-dist_ice)\n",
"im3 = ax3.imshow(start_map)\n",
"ax3.set_title(\"valid spawn locations x distance to ice\")\n",
"fig.colorbar(im3, ax=ax3)\n",
"plt.figure(dpi=150)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "180dacda",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"start_map"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f1169dc5",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"start_map.max()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "711b7f2f",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"start_map==start_map.max()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "beb3e9f8",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"np.argwhere(start_map==start_map.max())[:2]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e7298452",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"start_loc_candidates = np.argwhere(start_map==start_map.max())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "643805a4",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"start_loc_candidates[:5]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7dbd5971",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"fig, (ax1, ax2, ax3, ax4) = plt.subplots(1, 4, figsize=(18, 5))\n",
"im1 = ax1.imshow(valid_spawn_locations)\n",
"ax1.set_title('valid spawn locations')\n",
"im2 = ax2.imshow(dist_ice)\n",
"ax2.set_title(\"distance to ice\")\n",
"start_map = valid_spawn_locations*(dist_ice.max()-dist_ice)\n",
"im3 = ax3.imshow(start_map)\n",
"spawn_map = np.zeros((48,48))\n",
"for i in start_loc_candidates:\n",
" x= i[0]\n",
" y= i[1]\n",
" spawn_map[x,y]=100\n",
"im4 = ax4.imshow(spawn_map)\n",
"\n",
"ax4.set_title(\"spawn map\")\n",
"fig.colorbar(im4, ax=ax4)\n",
"plt.figure(dpi=150)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e2e1c4c2",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"potential_spawns = np.array(list(zip(*np.where(obs['player_0'][\"board\"][\"valid_spawns_mask\"] == 1))))\n",
"spawn_loc = start_loc_candidates[np.random.randint(0, len(start_loc_candidates))]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b70b227e",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"rubble = obs[\"player_0\"][\"board\"][\"rubble\"].copy()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "847ee0cf",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"start_loc_candidates[7]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab8b6235",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"sp_x, sp_y = start_loc_candidates[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ebb06f1e",
"metadata": {
"papermill": {
"duration": null,