forked from rkasper/shouty-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShouty.py
30 lines (22 loc) · 982 Bytes
/
Shouty.py
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
27
28
29
30
from Coordinate import Coordinate
MESSAGE_RANGE = 1000
class Shouty:
__locations: {str: Coordinate} # person-name -> person's-location
__shouts: {str: [str]} # shouter's-name -> list-of-their-messages
def __init__(self):
self.__locations = {}
self.__shouts = {}
def set_location(self, person: str, location: Coordinate):
self.__locations[person] = location
def shout(self, shouter: str, shout: str):
if shouter not in self.__shouts:
self.__shouts[shouter] = []
self.__shouts[shouter].append(shout)
def get_shouts_heard_by(self, listener: str):
shouts_heard = {}
for shouter in iter(self.__shouts):
persons_shouts: [str] = self.__shouts[shouter]
distance = self.__locations[listener].distance_from(self.__locations[shouter])
if distance < MESSAGE_RANGE:
shouts_heard[shouter] = persons_shouts
return shouts_heard