Skip to content

Commit

Permalink
Merge pull request #23 from Agent-LucIA/fix/improve_moving_units
Browse files Browse the repository at this point in the history
fix(#12): improve units movement
  • Loading branch information
chucheria authored Sep 4, 2021
2 parents 5d77f5b + 49cc8af commit 3282b50
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lucia.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _init_my_turn(self, game_state, observation):
self._width = game_state.map_width
self._height = game_state.map.height
self._player = game_state.players[observation.player]
self._opponent = game_state.players[observation.player]
self._opponent = game_state.players[(observation.player+1)%2]
self._n_units = len(game_state.players[observation.player].units)


Expand Down Expand Up @@ -125,5 +125,6 @@ def _write_notes(self):
height = self._height,
player = self._player,
n_units = self._n_units,
units_map = self._units_map
units_map = self._units_map,
tiles_assigned = []
)
6 changes: 6 additions & 0 deletions worker/tasks/find_nearest_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def find_all_resources(self, map, height, width):
def find_closest_resources(self, object, player):
"""
"""

tiles_assigned = self._blackboard.get_value('tiles_assigned')

closest_dist = math.inf
closest_resource_tile = None
for resource_tile in self._resource_tiles:
Expand All @@ -57,6 +60,9 @@ def find_closest_resources(self, object, player):
and not player.researched_uranium()):
continue

if resource_tile.pos in tiles_assigned:
continue

dist = resource_tile.pos.distance_to(object.pos)
if dist < closest_dist:
closest_dist = dist
Expand Down
6 changes: 4 additions & 2 deletions worker/tasks/move_to_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def run(self):
object)

updated = self.update_blackboard(direction,
object)
object,
target_position)

return True if updated else False

Expand Down Expand Up @@ -90,7 +91,7 @@ def get_final_position(self,posible_pos,object):
return direction


def update_blackboard(self, direction, object):
def update_blackboard(self, direction, object, target_position):

if direction:
old_pos = object.pos
Expand All @@ -103,6 +104,7 @@ def update_blackboard(self, direction, object):

self._blackboard.set_values(units_map=units_map)
self._blackboard.append_values(actions=movement)
self._blackboard.append_values(tiles_assigned=target_position)
self._blackboard.set_values(position=None)
return True
else:
Expand Down

0 comments on commit 3282b50

Please sign in to comment.