@@ -14,7 +14,7 @@ def __init__(self, size):
14
14
15
15
16
16
class Game (object ):
17
- def __init__ (self , map_upd_func , action_upd_func ):
17
+ def __init__ (self , bot_color , map_upd_func , action_upd_func ):
18
18
self .driver = None
19
19
self .mp = Map ()
20
20
self .players = []
@@ -29,17 +29,19 @@ def __init__(self, map_upd_func, action_upd_func):
29
29
self .useless = []
30
30
self .land_before = []
31
31
self .defending = False
32
- self .color = None
32
+ self .bot_color = bot_color
33
33
self .get_tensor_map = map_upd_func
34
34
self .send_action = action_upd_func
35
+ self .is_half = False
35
36
36
37
def get_map_from_env (self ):
37
38
"""
38
39
get map from environment
39
40
:return:
40
41
"""
41
- game_map = self .get_tensor_map (self .color )
42
+ game_map = self .get_tensor_map (self .bot_color )
42
43
map_size = game_map .shape [1 ]
44
+ game_map = game_map .long ().tolist ()
43
45
for i in range (map_size ):
44
46
for j in range (map_size ):
45
47
if game_map [1 ][i ][j ] == BlockType .city :
@@ -51,15 +53,16 @@ def get_map_from_env(self):
51
53
self .mp .mp [i ][j ].type = 'general'
52
54
elif game_map [1 ][i ][j ] == BlockType .mountain or game_map [1 ][i ][j ] == BlockType .obstacle :
53
55
self .mp .mp [i ][j ].type = 'mountain'
54
- elif game_map [1 ][i ][j ] == BlockType .road and game_map [2 ][i ][j ] == PlayerColor .grey :
56
+ elif game_map [1 ][i ][j ] == BlockType .road and game_map [2 ][i ][j ] == PlayerColor .grey \
57
+ and game_map [3 ][i ][j ] != 0 :
55
58
if game_map [2 ][i ][j ] == PlayerColor .grey :
56
59
self .mp .mp [i ][j ].type = 'empty'
57
60
else :
58
61
self .mp .mp [i ][j ].type = 'land'
59
62
else :
60
63
self .mp .mp [i ][j ].type = 'unknown'
61
64
62
- if game_map [2 ][i ][j ] == self .color :
65
+ if game_map [2 ][i ][j ] == self .bot_color :
63
66
self .mp .mp [i ][j ].belong = 1
64
67
else :
65
68
self .mp .mp [i ][j ].belong = 0
@@ -71,12 +74,10 @@ def get_map_from_env(self):
71
74
else :
72
75
self .mp .mp [i ][j ].cost = 1
73
76
74
- def set_color (self , color ):
75
- self .color = color
76
-
77
77
def pre (self ): # 预处理地图
78
78
tmp = self .mp .find_match (lambda a : a .type == 'general' and a .belong == 1 )
79
79
if len (tmp ) != 1 :
80
+ print ("" )
80
81
return 1
81
82
self .home_x = tmp [0 ][0 ]
82
83
self .home_y = tmp [0 ][1 ]
@@ -340,7 +341,7 @@ def flush_movements(self): # 更新移动
340
341
cur_movement = self .movements [0 ]
341
342
act = [self .cur_x , self .cur_y , self .cur_x + directions [cur_movement ][0 ],
342
343
self .cur_y + directions [cur_movement ][1 ], is_half ]
343
- self .send_action (self .color , act )
344
+ self .send_action (self .bot_color , act )
344
345
if self .movements [0 ] == 'W' :
345
346
self .cur_x -= 1
346
347
elif self .movements [0 ] == 'S' :
@@ -350,17 +351,18 @@ def flush_movements(self): # 更新移动
350
351
elif self .movements [0 ] == 'D' :
351
352
self .cur_y += 1
352
353
self .movements .pop (0 )
353
- self .get_tensor_map ()
354
+ self .get_map_from_env ()
354
355
self .update_map ()
355
- self .get_tensor_map ()
356
+ self .get_map_from_env ()
356
357
return
357
358
358
359
def bot_move (self ): # 主循环,每回合执行一次
359
- self .get_tensor_map ()
360
+ self .get_map_from_env ()
360
361
if not self .is_pre :
361
362
if self .pre () == 1 :
362
363
return
363
- if self .movements :
364
+ if len (self .movements ):
365
+ print ("flushed" )
364
366
self .flush_movements ()
365
367
return
366
368
if [self .cur_x , self .cur_y ] not in self .vis :
0 commit comments