-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvw4_example.py
executable file
·32 lines (22 loc) · 1.29 KB
/
vw4_example.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
31
32
#!/usr/bin/env python3
from typing import Iterable
from vacuumworld import run
from vacuumworld.model.actions.vwactions import VWAction
from vacuumworld.model.actions.vwidle_action import VWIdleAction
from vacuumworld.model.actions.vwbroadcast_action import VWBroadcastAction
from vacuumworld.model.actions.vweffort import VWActionEffort
from vacuumworld.model.actor.mind.surrogate.vwactor_mind_surrogate import VWActorMindSurrogate
class MyMind(VWActorMindSurrogate):
def __init__(self) -> None:
super(MyMind, self).__init__()
# Add here all the attributes you need/want.
def revise(self) -> None:
# Do something with the observation, the messages, and the effort instead of simply storing/printing them.
print(f"Observation:\n{self.get_latest_observation().pretty_format()}")
print(f"Messages: {[str(m) for m in self.get_latest_received_messages()]}")
print(f"Current effort since the beginning of the simulation: {self.get_effort()}.")
def decide(self) -> Iterable[VWAction]:
# Replace this trivial decision process with something meaningful.
return [VWIdleAction(), VWBroadcastAction(message="Hello!", sender_id=self.get_own_id())]
if __name__ == "__main__":
run(default_mind=MyMind(), efforts=VWActionEffort.REASONABLE_EFFORTS)