-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathagent.py
More file actions
26 lines (22 loc) · 1.21 KB
/
Copy pathagent.py
File metadata and controls
26 lines (22 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import logging
from world import *
class Agent:
def __init__(self, name, body, world):
self.name = name
self.world = world # My representation of the world
self.body = body # List of body positions. body[0] is the head
self.nutrients = {} # Dict representing nutrient stock
self.age = 0 # number of cycles this agent has lived so far
self.timespent = 0.0 # seconds spent by previous call to chooseAction
def chooseAction(self, vision, msg):
"""Analyse input vision and msg, and choose an action to do and msg to post."""
# This is the brain of the agent. It should be reimplemented on any subclass.
# It may use the fields (.name, .world, .body, .nutrients, .age, .timespent)
# and the parameters (vision and msg) to decide what to do.
# It must return an action (one of the ACTIONS),
# and a message (a possibly empty bytes object) to send to the other agent.
# (You may want to use pickle.dumps / pickle.loads to convert
# objects to bytes and back.)
action = Stay
msg = b"" # an empty message costs nothing
return action, msg