You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defrate_bomb_escape_directions(self, tile_coordinates):
# up right down left axis_directions= ((0,-1), (1,0), (0,1), (-1,0))
perpendicular_directions= ((1,0), (0,1), (1,0), (0,1))
result= [0,0,0,0]
fordirectionin (0,1,2,3):#TODO: This could be a range iteratorforiinrange(1,self.player.get_flame_length() +2):
axis_tile= (tile_coordinates[0] +i*axis_directions[direction][0],tile_coordinates[1] +i*axis_directions[direction][1])
ifnotself.tile_is_escapable(axis_tile):
breakperpendicular_tile1= (axis_tile[0] +perpendicular_directions[direction][0],axis_tile[1] +perpendicular_directions[direction][1])
perpendicular_tile2= (axis_tile[0] -perpendicular_directions[direction][0],axis_tile[1] -perpendicular_directions[direction][1])
ifi>self.player.get_flame_length() andself.game_map.get_danger_value(axis_tile) >=GameMap.SAFE_DANGER_VALUE:
result[direction] +=1ifself.tile_is_escapable(perpendicular_tile1) andself.game_map.get_danger_value(perpendicular_tile1) >=GameMap.SAFE_DANGER_VALUE:
result[direction] +=1ifself.tile_is_escapable(perpendicular_tile2) andself.game_map.get_danger_value(perpendicular_tile2) >=GameMap.SAFE_DANGER_VALUE:
result[direction] +=1returntuple(result)
The code below is a good example of how this code is well documented but not well commented. There is no explanation as to how the danger score is being used. While I appreciate the headers in cases like this they don't help the reviewer understand why things are the way they are.
## Returns an integer score in range 0 - 100 for given file (100 = good, 0 = bad).defrate_tile(self, tile_coordinates):
danger=self.game_map.get_danger_value(tile_coordinates)
ifdanger==0:
return0score=0ifdanger<1000:
score=20elifdanger<2500:
score=40else:
score=60tile_item=self.game_map.get_tile_at(tile_coordinates).itemiftile_item!=None:
iftile_item!=GameMap.ITEM_DISEASE:
score+=20else:
score-=10top= (tile_coordinates[0],tile_coordinates[1] -1)
right= (tile_coordinates[0] +1,tile_coordinates[1])
down= (tile_coordinates[0],tile_coordinates[1] +1)
left= (tile_coordinates[0] -1,tile_coordinates[1])
ifself.game_map.tile_has_lava(top) orself.game_map.tile_has_lava(right) orself.game_map.tile_has_lava(down) orself.game_map.tile_has_lava(left):
score-=5# don't go near lavaifself.game_map.tile_has_bomb(tile_coordinates):
ifnotself.player.can_box():
score-=5returnscore
In the below code a static mapping of cardinal directions appears again. Considering it's a static type and used in a number of locations it should be defined as other elements of the code are.
At this point, I should mention in the play function each action choice has a section of code associated with it. Each one of these sections could be split off into another function. This isn't necessary but rather a stylistic choice.
In the below code range should be xrange() as to not generate and store a set but to rather use an iterator. line 4919
AI class | lines 4547-4933
start
In the for loop they use a hardcoded set form 0-3 this set could be an iterator to improve memory usage.
line 4613
The code below is a good example of how this code is well documented but not well commented. There is no explanation as to how the danger score is being used. While I appreciate the headers in cases like this they don't help the reviewer understand why things are the way they are.
line 4613
In the below code a static mapping of cardinal directions appears again. Considering it's a static type and used in a number of locations it should be defined as other elements of the code are.
line 4698
This is an odd choice rather than deleting the AI player object it continues to live and waste CPU cycles.
line 4738
Again in the below an iterator could be used instead of a static array.
line 4797
At this point, I should mention in the play function each action choice has a section of code associated with it. Each one of these sections could be split off into another function. This isn't necessary but rather a stylistic choice.
In the below code range should be xrange() as to not generate and store a set but to rather use an iterator.
line 4919
Reviewed with minor issues
AI
classRecommendations:
AI
module to reduce size of main fileThe text was updated successfully, but these errors were encountered: