-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathagents_factory.py
52 lines (43 loc) · 2.02 KB
/
agents_factory.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
#=======================================================
# agents_factory.py
# Created by: Adi Ben Binyamin
# Eran Amar
#========================================================
from agents_pool import *
from heuristics import *
from global_consts import *
def player_for_agent_attacher(agent_type, heuristic):
return lambda player_obj: agent_type(heuristic, player_obj)
# The names format is <agent_type>_<heu>_<random/deterministic>
AGENTS = {
# Basic agents:
'human': lambda player_obj: HumanAgent(),
'random': lambda player_obj: RandomAgent(),
'reflex': lambda player_obj: ReflexAgent(),
# --------------------------------------------------------
# Minimax agents no randomness:
'MM_Winning': player_for_agent_attacher(AlphaBetha,WinningPossibilitiesHeu),
'MM_Cells': player_for_agent_attacher(AlphaBetha,CellsWeightHeu),
'MM_Recursive': player_for_agent_attacher(AlphaBetha,RecursiveWeightHeu),
# --------------------------------------------------------
# Minimax agents WITH randomness:
'MM_Winning#R': None,
'MM_Cells#R': None,
'MM_Recursive#R': None,
# --------------------------------------------------------
# Greedy agents no randomness:
'G_Winning': player_for_agent_attacher(GreedyAgent,WinningPossibilitiesHeu),
'G_Cells': player_for_agent_attacher(GreedyAgent,CellsWeightHeu),
'G_Recursive': player_for_agent_attacher(GreedyAgent,RecursiveWeightHeu),
}
def AgentFactory(type_name, player_obj):
if not type_name in AGENTS.keys():
print 'Error! there is no such agent "%s".' % type_name
print USAGE
from sys import exit
exit(1)
base_type = type_name.replace(RANDOMNESS_SUFFIX, '')
base_agent = (AGENTS[base_type])(player_obj)
if RANDOMNESS_SUFFIX in type_name:
return GenericRandomJumpAgent(base_agent, RANDOM_FORMULA)
return base_agent