forked from bymayanksingh/connect4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_factory.py
More file actions
50 lines (40 loc) · 1.3 KB
/
agent_factory.py
File metadata and controls
50 lines (40 loc) · 1.3 KB
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
"""
agent_factory.py
----------------
Centralised helper to configure and create DPAgent instances.
Edit the defaults here (γ, dp_only, verbosity) instead of hunting through
game_data.py or other files. Any module can simply:
from agent_factory import make_agent
agent = make_agent() # DP‑only, γ=0.95, quiet
strong = make_agent(dp_only=False, gamma=0.99, verbose=True)
"""
from typing import Any
from dp_agent import DPAgent
def make_agent(
*,
dp_only: bool = True,
gamma: float = 0.95,
verbose: bool = False,
**kwargs: Any
) -> DPAgent:
"""
Build and return a configured DPAgent.
Args
----
dp_only : If True → search & heuristics **disabled** (pure DP mode).
If False → search & heuristics **enabled** (strong-play mode).
gamma : Discount factor (0 < γ ≤ 1).
verbose : Master verbosity flag controlling most console prints.
**kwargs : Forward‑compatibility – any extra keyword args are passed
straight to the DPAgent constructor.
Returns
-------
DPAgent instance with the requested configuration.
"""
return DPAgent(
discount_factor=gamma,
use_heuristics=not dp_only,
use_search=not dp_only,
verbose=verbose,
**kwargs,
)