-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheuristic_bot.py
More file actions
50 lines (40 loc) · 1.78 KB
/
Copy pathheuristic_bot.py
File metadata and controls
50 lines (40 loc) · 1.78 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
# heuristic_bot.py
"""
Bot AI for GPD (client snapshot interface).
Delegates to bot_playstyles for the actual decision logic.
Interface:
decide(game_state, player_name) -> ("PEACE"/"GATHER"/"EXPAND"/"NOTHING", params)
where params for EXPAND is (src_id, tgt_id, send_amount)
"""
import logging
import bot_playstyles
logger = logging.getLogger(__name__)
def decide(game_state, player_name):
"""Main decision function -- routes to bot_playstyles."""
return bot_playstyles.decide(game_state, player_name)
# Test harness
if __name__ == "__main__":
sample = {
"players": [
{"name": "bot1", "money": 900, "is_bot": True, "vulnerable": False, "was_attacked": False},
{"name": "bot2", "money": 500, "is_bot": True, "vulnerable": True, "was_attacked": False},
{"name": "player", "money": 500, "is_bot": False, "vulnerable": False, "was_attacked": False},
],
"pins": [
{"id": 1, "name": "A", "owner": "bot1", "troops": 8,
"adj": [{"to": 2, "cost": 0}, {"to": 3, "cost": 0}], "continent": "Europe"},
{"id": 2, "name": "B", "owner": "bot2", "troops": 3,
"adj": [{"to": 1, "cost": 0}], "continent": "Europe"},
{"id": 3, "name": "C", "owner": None, "troops": 0,
"adj": [{"to": 1, "cost": 0}, {"to": 4, "cost": 100}], "continent": "Europe"},
{"id": 4, "name": "D", "owner": "player", "troops": 5,
"adj": [{"to": 3, "cost": 100}], "continent": "Asia"},
]
}
result = decide(sample, "bot1")
print(f"bot1 decision: {result}")
print(f"bot1 playstyle: {bot_playstyles.get_playstyle('bot1')}")
for i in range(5):
r = decide(sample, "bot1")
ps = bot_playstyles.get_playstyle("bot1")
print(f" [{ps}] -> {r}")