Skip to content

Commit

Permalink
smart move selection (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
HokageM authored Feb 24, 2024
1 parent a26794f commit dc203f7
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/ninjabees/Bee.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,25 @@ def move(self):
x = self.get_x()
y = self.get_y()

move_x = random.randint(-1, 1)
move_y = random.randint(-1, 1)
hive_x = self.hive.get_x()
hive_y = self.hive.get_y()

dist_x_r = abs(hive_x - (x + 1)) + 1
dist_x_l = abs(hive_x - (x - 1)) + 1
dist_x_n = abs(hive_x - x) + 1
dist_y_u = abs(hive_y - (y - 1)) + 1
dist_y_d = abs(hive_y - (y + 1)) + 1
dist_y_n = abs(hive_y - y) + 1

move_xy = random.choices([(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0),
(1, 1)],
weights=[max(dist_x_l, dist_y_u), max(dist_x_l, 0), max(dist_x_l, dist_y_d),
max(dist_y_u, 0), max(dist_x_n, dist_y_n), max(dist_y_d, 0),
max(dist_x_r, dist_y_u), max(dist_x_r, 0), max(dist_x_r, dist_y_d)],
k=1)[0]

move_x = move_xy[0]
move_y = move_xy[1]

x += move_x
y += move_y
Expand Down

0 comments on commit dc203f7

Please sign in to comment.