Browse Source

fixed some bugs and improved the role selection system

master
jcao219 14 years ago
parent
commit
ab9f541707
  1. 21
      vars.py
  2. 107
      wolfgame.py

21
vars.py

@ -7,13 +7,21 @@ NIGHT_TIME_LIMIT = 90
DAY_TIME_LIMIT = 137 DAY_TIME_LIMIT = 137
####################################################################################### #######################################################################################
# PLAYERS SEER WOLF CURSED DRUNK HARLOT TRAITOR GUNNER # # ROLE INDEX: PLAYERS SEER WOLF CURSED DRUNK HARLOT TRAITOR GUNNER #
ROLES_GUIDE = { 4 : ( 1 , 1 , 0 , 0 , 0 , 0 , 0 ), # ROLES_GUIDE = { 4 : ( 1 , 1 , 0 , 0 , 0 , 0 , 0 ), #
6 : ( 0 , 0 , 1 , 1 , 0 , 0 , 0 ), # 6 : ( 1 , 1 , 1 , 1 , 0 , 0 , 0 ), #
8 : ( 0 , 1 , 0 , 0 , 1 , 0 , 0 ), # 8 : ( 1 , 2 , 1 , 1 , 1 , 0 , 0 ), #
10 : ( 0 , 0 , 0 , 0 , 0 , 1 , 1 )} # 10 : ( 1 , 2 , 1 , 1 , 1 , 1 , 1 )} #
####################################################################################### #######################################################################################
ROLE_INDICES = {0 : "seer",
1 : "wolf",
2 : "cursed",
3 : "village drunk",
4 : "harlot",
5 : "traitor",
6 : "gunner"}
NO_VICTIMS_MESSAGES = ("The body of a young penguin pet is found.", NO_VICTIMS_MESSAGES = ("The body of a young penguin pet is found.",
@ -25,11 +33,6 @@ LYNCH_MESSAGES = ("The villagers, after much debate, finally decide on lynching
"Resigned to his/her fate, \u0002{0}\u0002 is led to the gallows. After death, it is discovered (s)he was a \u0002{1}\u0002.") "Resigned to his/her fate, \u0002{0}\u0002 is led to the gallows. After death, it is discovered (s)he was a \u0002{1}\u0002.")
# These change ingame
ROLES = {"person" : []}
PHASE = "none" # "join", "day", or "night"
TIMERS = [None, None] # nightlimit, daylimit
is_role = lambda plyr, rol: rol in ROLES and plyr in ROLES[rol] is_role = lambda plyr, rol: rol in ROLES and plyr in ROLES[rol]
def plural(role): def plural(role):

107
wolfgame.py

@ -24,6 +24,8 @@ def connect_callback(cli):
vars.LAST_PING = 0 # time of last !ping vars.LAST_PING = 0 # time of last !ping
vars.ROLES = {"person" : []} vars.ROLES = {"person" : []}
vars.PHASE = "none" # "join", "day", or "night" vars.PHASE = "none" # "join", "day", or "night"
vars.TIMERS = [None, None]
vars.DEAD = []
@ -49,7 +51,8 @@ def reset(cli):
cli.mode(chan, "-v", "{0} {0}!*@*".format(plr)) cli.mode(chan, "-v", "{0} {0}!*@*".format(plr))
for deadguy in vars.DEAD: for deadguy in vars.DEAD:
cli.mode(chan, "-q", "{0} {0}!*@*".format(deadguy)) cli.mode(chan, "-q", "{0} {0}!*@*".format(deadguy))
vars.DEAD = []
vars.ROLES = {"person" : []} vars.ROLES = {"person" : []}
@ -177,14 +180,14 @@ def stats(cli, nick, chan, rest):
message.append("\u0002(0}\u0002 {1}".format(count, vars.plural(role))) message.append("\u0002(0}\u0002 {1}".format(count, vars.plural(role)))
else: else:
message.append("\u0002{0}\u0002 {1}".format(count, role)) message.append("\u0002{0}\u0002 {1}".format(count, role))
if len(vars.ROLES["wolf"]) > 1: if len(vars.ROLES["wolf"]) > 1 or not vars.ROLES["wolf"]):
vb = "are" vb = "are"
else: else:
vb = "is" vb = "is"
cli.msg(chan, "{0}: There {3} {1}, and {2}.".format(nick, cli.msg(chan, "{0}: There {3} {1}, and {2}.".format(nick,
", ".join(message[0:-1]), ", ".join(message[0:-1]),
message[-1]), message[-1],
vb) vb))
@ -263,10 +266,10 @@ def chk_win(cli):
if len(vars.ROLES["wolf"]) >= len(vars.list_players()) / 2: if len(vars.ROLES["wolf"]) >= len(vars.list_players()) / 2:
cli.msg(chan, ("Game over! There are the same number of wolves as "+ cli.msg(chan, ("Game over! There are the same number of wolves as "+
"villagers. The wolves eat everyone, and win.")) "villagers. The wolves eat everyone, and win."))
elif not len(vars.ROLES["wolf"]) and not vars.ROLES["traitor"]: elif not len(vars.ROLES["wolf"]) and not vars.ROLES.get("traitor", 0):
cli.msg(chan, ("Game over! All the wolves are dead! The villagers "+ cli.msg(chan, ("Game over! All the wolves are dead! The villagers "+
"chop them up, BBQ them, and have a hearty meal.")) "chop them up, BBQ them, and have a hearty meal."))
elif not len(vars.ROLES["wolf"]) and vars.ROLES["traitor"]: elif not len(vars.ROLES["wolf"]) and vars.ROLES.get("traitor", 0):
pass # WOLVES ARE NOT GONE :O pass # WOLVES ARE NOT GONE :O
# TODO: transform TRAITOR # TODO: transform TRAITOR
return False return False
@ -530,18 +533,19 @@ def transition_night(cli):
'Use "see <nick>" to see the role of a player.')) 'Use "see <nick>" to see the role of a player.'))
cli.msg(seer, "Players: "+", ".join(pl)) cli.msg(seer, "Players: "+", ".join(pl))
for d in vars.ROLES["village drunk"]:
cli.msg(d, 'You have been drinking too much! You are the village drunk.')
@cmd("!start") @cmd("!start")
def start(cli, nick, chan, rest): def start(cli, nick, chan, rest):
pl = vars.list_players() villagers = vars.list_players()
if vars.PHASE == "none": if vars.PHASE == "none":
cli.notice(nick, "No game is currently running.") cli.notice(nick, "No game is currently running.")
return return
if vars.PHASE != "join": if vars.PHASE != "join":
cli.notice(nick, "Werewolf is already in play.") cli.notice(nick, "Werewolf is already in play.")
return return
if nick not in pl: if nick not in villagers:
cli.notice(nick, "You're currently not playing.") cli.notice(nick, "You're currently not playing.")
return return
now = datetime.now() now = datetime.now()
@ -550,60 +554,49 @@ def start(cli, nick, chan, rest):
cli.msg(chan, "Please wait at least {0} more seconds.".format(dur)) cli.msg(chan, "Please wait at least {0} more seconds.".format(dur))
return return
if len(pl) < 4: if len(villagers) < 4:
cli.msg(chan, "{0}: Four or more players are required to play.".format(nick)) cli.msg(chan, "{0}: Four or more players are required to play.".format(nick))
return return
vars.ROLES = {} vars.ROLES = {}
nharlots = 0 vars.CURSED = ""
nseers = 0 vars.GUNNERS = []
nwolves = 0
ndrunk = 0 addroles = None
ncursed = 0 for pcount in range(len(villagers), 3, -1):
ntraitor = 0
for pcount in range(4, len(pl)+1):
addroles = vars.ROLES_GUIDE.get(pcount) addroles = vars.ROLES_GUIDE.get(pcount)
if addroles: if addroles:
nseers += addroles[0] break
nwolves += addroles[1] for i, count in enumerate(addroles):
ncursed += addroles[2] role = vars.ROLE_INDICES[i]
ndrunk += addroles[3] selected = random.sample(villagers, count)
nharlots += addroles[4] vars.ROLES[role] = selected
ntraitor += addroles[5] for x in selected:
villagers.remove(x)
seer = random.choice(pl) # Select cursed (just a villager)
vars.ROLES["seer"] = [seer] if vars.ROLES["cursed"]:
pl.remove(seer) vars.CURSED = random.choice((villagers + # harlot and drunk can be cursed
vars.ROLES["harlot"] +
harlots = random.sample(pl, nharlots) vars.ROLES["village drunk"] +
vars.ROLES["harlot"] = harlots vars.ROLES["cursed"]))
for h in harlots: for person in vars.ROLES["cursed"]:
pl.remove(h) villagers.append(person)
del vars.ROLES["cursed"]
wolves = random.sample(pl, nwolves) # Select gunner (also a villager)
vars.ROLES["wolf"] = wolves if vars.ROLES["gunner"]:
for w in wolves: possible = (villagers +
pl.remove(w) vars.ROLES["harlot"] +
vars.ROLES["village drunk"] +
drunk = random.choice(pl) vars.ROLES["seer"] +
vars.ROLES["village drunk"] = [drunk] vars.ROLES["gunner"])
pl.remove(drunk) if vars.CURSED in possible:
possible.remove(vars.CURSED)
vars.ROLES["villager"] = pl vars.GUNNERS = random.sample(possible, len(vars.ROLES["gunner"]))
for person in vars.ROLES["gunner"]:
if ncursed: villagers.append(person)
vars.CURSED = random.choice(vars.ROLES["villager"] + \ del vars.ROLES["gunner"]
vars.ROLES.get("harlot", []) +\
vars.ROLES.get("village drunk", []))
else:
vars.CURSED = ""
if ntraitor: vars.ROLES["villager"] = villagers
possible = vars.ROLES["villager"]
if vars.CURSED:
possible.remove(vars.CURSED) # Cursed traitors are not allowed
vars.ROLES["traitor"] = random.sample(possible, ntraitor)
cli.msg(chan, ("{0}: Welcome to Werewolf, the popular detective/social party "+ cli.msg(chan, ("{0}: Welcome to Werewolf, the popular detective/social party "+
"game (a theme of Mafia).").format(", ".join(vars.list_players()))) "game (a theme of Mafia).").format(", ".join(vars.list_players())))

Loading…
Cancel
Save