-
Notifications
You must be signed in to change notification settings - Fork 14
/
python_simple_sample.py
executable file
·103 lines (76 loc) · 2.7 KB
/
python_simple_sample.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
# This sample script connects to the AIWolf server, but
# does not do anything else. It will choose itself as the
# target for any actions requested by the server, (voting,
# attacking ,etc) forcing the server to choose a random target.
import logging
from logging import getLogger, StreamHandler, Formatter, FileHandler
import aiwolfpy
import argparse
# name
myname = 'sample_python'
# content factory
cf = aiwolfpy.ContentFactory()
# logger
logger = getLogger("aiwolfpy")
logger.setLevel(logging.NOTSET)
# handler
stream_handler = StreamHandler()
stream_handler.setLevel(logging.NOTSET)
handler_format = Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
stream_handler.setFormatter(handler_format)
logger.addHandler(stream_handler)
# file_handler = FileHandler('aiwolf_game.log')
# file_handler.setLevel(logging.WARNING)
# file_handler.setFormatter(handler_format)
# logger.addHandler(file_handler)
class SampleAgent(object):
def __init__(self):
# my name
self.base_info = dict()
self.game_setting = dict()
def getName(self):
return self.my_name
# new game (no return)
def initialize(self, base_info, diff_data, game_setting):
self.base_info = base_info
self.game_setting = game_setting
# new information (no return)
def update(self, base_info, diff_data, request):
self.base_info = base_info
# Start of the day (no return)
def dayStart(self):
return None
# conversation actions: require a properly formatted
# protocol string as the return.
def talk(self):
return cf.over()
def whisper(self):
return cf.over()
# targetted actions: Require the id of the target
# agent as the return
def vote(self):
return self.base_info['agentIdx']
def attack(self):
return self.base_info['agentIdx']
def divine(self):
return self.base_info['agentIdx']
def guard(self):
return self.base_info['agentIdx']
# Finish (no return)
def finish(self):
return None
agent = SampleAgent()
# read args
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-p', type=int, action='store', dest='port')
parser.add_argument('-h', type=str, action='store', dest='hostname')
parser.add_argument('-r', type=str, action='store', dest='role', default='none')
parser.add_argument('-n', type=str, action='store', dest='name', default=myname)
input_args = parser.parse_args()
client_agent = aiwolfpy.AgentProxy(
agent, input_args.name, input_args.hostname, input_args.port, input_args.role, logger, "pandas"
)
# run
if __name__ == '__main__':
client_agent.connect_server()