Skip to content

Commit a6fd559

Browse files
committed
Created setxy function which sets the agents position to the specified parameters. set_pos function, sets the current position to the specified pos parameter. distancexy function, gives you the distance of the agent and the given coordinate. distance function, gives you the distance between the agent and another agent.
1 parent 5105dde commit a6fd559

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

mesa/agent.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ def turn_left(self, degree):
6363
"""Turns the agent left by the given degree"""
6464
self.heading = (self.heading + degree) % 360
6565

66+
def setxy(self, x, y):
67+
"""Sets the current position to the specified x,y parameters"""
68+
self.pos = (x, y)
69+
70+
def set_pos(self, apos):
71+
"""Sets the current position to the specified pos parameter"""
72+
self.pos = apos
73+
74+
def distancexy(self, x, y):
75+
"""Gives you the distance of the agent and the given coordinate"""
76+
return math.dist(self.pos, (x, y))
77+
78+
def distance(self, another_agent):
79+
"""Gives you the distance between the agent and another agent"""
80+
return self.distancexy(another_agent.pos[0], another_agent.pos[1])
81+
6682

6783
@property
6884
def random(self) -> Random:

0 commit comments

Comments
 (0)