-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent.pro
47 lines (44 loc) · 2.08 KB
/
agent.pro
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
get_agent_action(UniverseId, AgentId, Action, 'Arthur') :-
random_policy(UniverseId, AgentId, Action).
% get_current_agent_and_state(UniverseId, AgentId, StateId),
% basic_action_policy(StateId, AgentId, Action).
get_agent_action(UniverseId, AgentId, Action, 'Merlin') :-
random_policy(UniverseId, AgentId, Action).
% get_current_agent_and_state(UniverseId, AgentId, StateId),
% basic_action_policy(StateId, AgentId, Action).
get_agent_action(UniverseId, AgentId, Action, 'Mordred') :-
random_policy(UniverseId, AgentId, Action).
% get_current_agent_and_state(UniverseId, AgentId, StateId),
% basic_action_policy(StateId, AgentId, Action).
random_policy(UniverseId, AgentId, Action) :-
get_current_agent_and_state(UniverseId, AgentId, StateId),
state(StateId, Agents, _, _),
Agent = Agents.get(AgentId),
findall(A, can_perform(Agent.class, A), ActionList),
repeat,
random_member(ActionProposal, ActionList),
% pick a random time and universe if action is portal
% pick a random agent id for attack if action is one of
% attack .
(
(ActionProposal = portal,
global_universe_id(MaxUniverseId),
findall(Uid, between(0, MaxUniverseId, Uid), UniverseIds),
random_member(UniverseId, UniverseIds),
current_time(UniverseId, MaxTime, _),
findall(T, between(0, MaxTime, T), Times),
random_member(Time, Times),
Action = [portal, UniverseId, Time]);
(ActionProposal = portal_to_now,
global_universe_id(MaxUniverseId),
findall(Uid, between(0, MaxUniverseId, Uid), UniverseIds),
random_member(UniverseId, UniverseIds),
Action = [portal_to_now, UniverseId]);
(member(ActionProposal, [melee_attack, magic_missile, ranged_attack]),
dict_keys(Agents, AgentIds),
random_member(TargetAgentId, AgentIds),
\+ (TargetAgentId = AgentId),
Action = [ActionProposal, TargetAgentId]);
(Action = [ActionProposal])
).
get_agent_action(UniverseId, AgentId, Action, _) :- random_policy(UniverseId, AgentId, Action).