-
Notifications
You must be signed in to change notification settings - Fork 1
/
agent_test.py
executable file
·70 lines (64 loc) · 1.89 KB
/
agent_test.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import sys
import uuid
from agent.base import BaseAgent
from base.protocol import OfferRequest, OfferResponse, RoundResult, DealRequest, DealResponse
def init_ai_agent(class_path) -> BaseAgent:
print(f"Create agent from {class_path}")
split_result = class_path.rsplit('.', 1)
class_name = split_result[1]
module_path = split_result[0]
mod = __import__(module_path, fromlist=[class_name])
klass = getattr(mod, class_name)
instance = klass()
return instance
if __name__ == '__main__':
agent_path = "agent.my_agent.MyAgent"
if len(sys.argv) < 2:
print(f"Agent module not specified. Use default: {agent_path}")
else:
agent_path = sys.argv[1]
agent = init_ai_agent(agent_path)
agent.agent_id = str(uuid.uuid4())
# test offer_action
target_agent_uid = str(uuid.uuid4())
offer = agent.offer_action(OfferRequest(
round_id=1,
target_agent_uid=target_agent_uid,
total_amount=100
))
error = OfferResponse(offer).find_error()
if error:
print(error)
sys.exit(0)
# test round_result_action success
agent.round_result_action(RoundResult(
round_id=1,
win=True,
agent_gain={
agent.agent_id: 100 - offer,
target_agent_uid: offer
}
))
# test deal_action
accepted = agent.deal_action(DealRequest(
round_id=2,
from_agent_uid=target_agent_uid,
total_amount=100,
offer=1
))
DealResponse(accepted).find_error()
if error:
print(error)
sys.exit(0)
# test round_result_action disconnection_failure
agent.round_result_action(RoundResult(
round_id=2,
win=False,
agent_gain={
agent.agent_id: 0,
target_agent_uid: 0
},
disconnection_failure=True
))
print("Base test successfully completed!")