zmiana karmienia
This commit is contained in:
parent
1e5ba0765c
commit
539a08af0d
12
agent.py
12
agent.py
@ -31,9 +31,9 @@ class Agent:
|
|||||||
elif event.key == pygame.K_RIGHT:
|
elif event.key == pygame.K_RIGHT:
|
||||||
self.move('Turn Right', max_x, max_y, obstacles, animals)
|
self.move('Turn Right', max_x, max_y, obstacles, animals)
|
||||||
|
|
||||||
feed_animal(self, animals)
|
# feed_animal(self, animals)
|
||||||
|
|
||||||
def move(self, action, max_x, max_y, obstacles, animals):
|
def move(self, action, max_x, max_y, obstacles, animals, goal):
|
||||||
if action == 'Go Forward':
|
if action == 'Go Forward':
|
||||||
new_x, new_y = self.x, self.y
|
new_x, new_y = self.x, self.y
|
||||||
if self.direction == 'N':
|
if self.direction == 'N':
|
||||||
@ -56,11 +56,13 @@ class Agent:
|
|||||||
self.direction = {'N': 'E', 'E': 'S', 'S': 'W', 'W': 'N'}[self.direction]
|
self.direction = {'N': 'E', 'E': 'S', 'S': 'W', 'W': 'N'}[self.direction]
|
||||||
|
|
||||||
self.istate = (self.x, self.y, self.direction)
|
self.istate = (self.x, self.y, self.direction)
|
||||||
feed_animal(self, animals)
|
feed_animal(self, animals, goal)
|
||||||
|
|
||||||
def feed_animal(self, animals):
|
def feed_animal(self, animals, goal):
|
||||||
|
goal_x, goal_y = goal
|
||||||
|
if self.x == goal_x and self.y == goal_y:
|
||||||
for animal in animals:
|
for animal in animals:
|
||||||
if self.x == animal.x and self.y == animal.y:
|
if animal.x == goal_x and animal.y == goal_y:
|
||||||
if animal.feed() == 'True':
|
if animal.feed() == 'True':
|
||||||
animal._feed = 0
|
animal._feed = 0
|
||||||
print(animal.name, "fed with", animal.food)
|
print(animal.name, "fed with", animal.food)
|
2
main.py
2
main.py
@ -260,7 +260,7 @@ def main():
|
|||||||
|
|
||||||
if actions:
|
if actions:
|
||||||
action = actions.pop(0)
|
action = actions.pop(0)
|
||||||
agent.move(action, GRID_WIDTH, GRID_HEIGHT, obstacles, Animals)
|
agent.move(action, GRID_WIDTH, GRID_HEIGHT, obstacles, Animals, goal)
|
||||||
pygame.time.wait(200)
|
pygame.time.wait(200)
|
||||||
else:
|
else:
|
||||||
animal = random.choice(Animals)
|
animal = random.choice(Animals)
|
||||||
|
Loading…
Reference in New Issue
Block a user