-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMafiaBotTest.py
177 lines (149 loc) · 5.61 KB
/
MafiaBotTest.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
__author__ = 'LLCoolDave'
# ToDo: Replace by proper unit tests, currently broken as it stands
import logging
from MafiaBot.MafiaBot import *
from sopel.tools import Identifier
log = logging.getLogger('MafiaBot')
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(message)s')
ch.setFormatter(formatter)
# add the handlers to the logger
log.addHandler(ch)
mb = MafiaBot()
mainchannel = mb.mainchannel
deadchat = mb.deadchat
mafiachannel = mb.mafiachannels[0]
playerlist = [Identifier('PLAYERA'), Identifier('PLAYERB'), Identifier('PLAYERC'), Identifier('PLAYERD'), Identifier('PLAYERE'), Identifier('PLAYERF'), Identifier('PLAYERG')]
class botstub:
def msg(self, target, msg, max_messages=0):
log.info('BOT MSG @'+str(target)+': '+msg)
def join(self, param):
log.info('BOT JOIN: '+param)
def part(self, param):
log.info('BOT PART: '+param)
def write(self, param):
log.info('BOT WRITE: '+param[0]+param[1])
def say(self, msg, max_messages=0):
log.info('BOT SAY: '+msg)
def SendCommand(command, source, nick, param):
reply = mb.HandleCommand(command, source, nick, param, botstub())
log.info('COMMAND '+command+' by '+str(nick)+' in '+str(source)+' with parameter \''+str(param)+'\'')
if reply is not None:
log.info('RESPONSE ' + reply)
def SendPlayerCommand(command, source, nick, param):
reply = mb.HandlePlayerCommand(command, source, nick, param, botstub())
log.info('COMMAND '+command+' by '+str(nick)+' in '+str(source)+' with parameter \''+str(param)+'\'')
if reply is not None:
log.info('RESPONSE ' + reply)
def GameLoop():
mb.GameLoop(botstub())
def LogOff():
log.setLevel(50)
def LogOn():
log.setLevel(10)
def JoinAndStart():
for player in playerlist:
SendCommand('join', mainchannel, player, '')
SendCommand('setup', mainchannel, playerlist[0], 'load test')
SendCommand('setup', mainchannel, playerlist[0], 'daystart')
SendCommand('players', mainchannel, playerlist[0], '')
#test votes command
SendCommand('votes', mainchannel, playerlist[2], '')
SendCommand('start', mainchannel, playerlist[0], '')
SendCommand('votes', playerlist[3], playerlist[3], '')
def Vote(player, target='NoLynch'):
strtar = str(target)
SendCommand('vote', mainchannel, player, strtar)
def PassDay(target='NoLynch'):
for player in playerlist:
Vote(player, target)
def BreakPoint():
pass
def Main():
# all players join
LogOff()
JoinAndStart()
# get mafia
scums = [player for player in playerlist if mb.players[player].faction == MafiaPlayer.FACTION_MAFIA]
# get prostitute
prostitutes = [player for player in playerlist if isinstance(mb.players[player].role, Roles['prostitute'])]
if prostitutes:
pros = prostitutes[0]
else:
pros = None
# get prostitute
medics = [player for player in playerlist if isinstance(mb.players[player].role, Roles['medic'])]
if medics:
medic = medics[0]
else:
medic = None
cops = [player for player in playerlist if isinstance(mb.players[player].role, Roles['cop'])]
if cops:
cop = cops[0]
else:
cop = None
paritycops = [player for player in playerlist if isinstance(mb.players[player].role, Roles['paritycop'])]
if paritycops:
paritycop = paritycops[0]
else:
paritycop = None
trackers = [player for player in playerlist if isinstance(mb.players[player].role, Roles['tracker'])]
if trackers:
tracker = trackers[0]
else:
tracker = None
watchers = [player for player in playerlist if isinstance(mb.players[player].role, Roles['watcher'])]
if watchers:
watcher = watchers[0]
else:
watcher = None
bulletproofs = [player for player in playerlist if isinstance(mb.players[player].role, Roles['bulletproof'])]
if bulletproofs:
bulletproof = bulletproofs[0]
else:
bulletproof = None
gunsmiths = [player for player in playerlist if isinstance(mb.players[player].role, Roles['gunsmith'])]
if gunsmiths:
gunsmith = gunsmiths[0]
else:
gunsmith = None
vigilantes = [player for player in playerlist if isinstance(mb.players[player].role, Roles['vigilante'])]
if vigilantes:
vigilante = vigilantes[0]
else:
vigilante = None
aliens = [player for player in playerlist if isinstance(mb.players[player].role, Roles['alien'])]
if aliens:
alien = aliens[0]
else:
alien = None
if scums[0] in prostitutes:
scum = scums[1]
else:
scum = scums[0]
# get setup
setup = [(str(player), mb.players[player].GetFaction(), mb.players[player].role.GetRoleName()) for player in playerlist]
LogOn()
log.debug('This game\'s setup is: '+str(setup))
i = 0
while mb.active:
# lynch player i
PassDay(playerlist[i])
LogOff()
SendPlayerCommand('pass', gunsmith, gunsmith, bulletproof)
SendPlayerCommand('pass', pros, pros, cop)
SendPlayerCommand('pass', medic, medic, playerlist[0])
SendPlayerCommand('pass', cop, cop, playerlist[0])
SendPlayerCommand('pass', tracker, tracker, cop)
SendPlayerCommand('pass', watcher, watcher, cop)
SendPlayerCommand('pass', vigilante, vigilante, cop)
SendPlayerCommand('check', paritycop, paritycop, playerlist[6-i])
SendCommand('nokill', mafiachannel, scum, playerlist[0])
SendCommand('nokill', mafiachannel, pros, playerlist[0])
LogOn()
GameLoop()
i += 1
if __name__ == "__main__":
Main()