Update app.py
Browse files
app.py
CHANGED
@@ -48,7 +48,7 @@ class Ant:
|
|
48 |
# Perceive nearby ants
|
49 |
self.nearby_ants = [ant for ant in ants if distance.euclidean(self.position, ant.position) <= self.communication_range]
|
50 |
|
51 |
-
|
52 |
possible_actions = self.get_possible_actions()
|
53 |
|
54 |
if random.random() < self.genome['exploration_rate']:
|
@@ -74,6 +74,16 @@ class Ant:
|
|
74 |
|
75 |
self.q_table[(self.position, action)] = new_q
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
def get_possible_actions(self):
|
78 |
x, y = self.position
|
79 |
possible_actions = []
|
|
|
48 |
# Perceive nearby ants
|
49 |
self.nearby_ants = [ant for ant in ants if distance.euclidean(self.position, ant.position) <= self.communication_range]
|
50 |
|
51 |
+
def act(self, pheromone_grid):
|
52 |
possible_actions = self.get_possible_actions()
|
53 |
|
54 |
if random.random() < self.genome['exploration_rate']:
|
|
|
74 |
|
75 |
self.q_table[(self.position, action)] = new_q
|
76 |
|
77 |
+
def calculate_reward(self):
|
78 |
+
if self.carrying_food:
|
79 |
+
return 10
|
80 |
+
elif self.position in FOOD_SOURCES:
|
81 |
+
return 20
|
82 |
+
elif self.position in OBSTACLES:
|
83 |
+
return -10
|
84 |
+
else:
|
85 |
+
return -1 + self.food_pheromone - self.danger_pheromone + 0.5 * self.exploration_pheromone
|
86 |
+
|
87 |
def get_possible_actions(self):
|
88 |
x, y = self.position
|
89 |
possible_actions = []
|