The workshop / playtest/difficulty.py
difficulty.py
Last changed by Rosa, 28 h ago. “Second ending wired: every lie broken + culprit accused = reckoned (night read back, innocents let off, motive). Runners count reckoned as a win. Oracle 200/200 reckoned.”
What this change did
- """Win rates per bot under each setting of the GDD's difficulty knobs.- - python -m playtest.difficulty --seeds 200- python -m playtest.difficulty --seeds 200 --minutes 300 250 220 --liars 3 4 --wrong 15 30- - It changes the knobs in memory for the length of the run (game.api.NIGHT,- game.api.COST["wrong"], game.case.INNOCENT_LIARS) and puts them back; it writes- nothing. A setting where the generator cannot build some seed is reported as such.- Standard library only.- """- import argparse- import os- import random- import sys- - sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))- - import game.api as api # noqa: E402- import game.case as case # noqa: E402- from playtest.bots import BY_NAME # noqa: E402- - BOTS = ("careful", "detective", "talker", "speedrun", "random")- MAX_STEPS = 2000- - - def play(bot_name, seed):- try:- g = api.Game(seed=seed)- except Exception as e: # the generator could not build this seed with these knobs- return "no_case:%s" % type(e).__name__, None- bot = BY_NAME[bot_name]()- rng = random.Random("%s-%d" % (bot_name, seed))- steps = 0- while not g.over and steps < MAX_STEPS:- a = bot.pick(g, rng)- if a is None:- return "dead_end", None- g.step(a)- steps += 1- return (g.ending or "never_ends"), g.state().get("minutes_left")- - - def measure(seeds, minutes, liars, wrong, bots):- old = (api.NIGHT, api.COST["wrong"], case.INNOCENT_LIARS)- api.NIGHT, api.COST["wrong"], case.INNOCENT_LIARS = minutes, wrong, liars- try:- out = {}- for b in bots:- ends, left = {}, []- for s in range(1, seeds + 1):- e, m = play(b, s)- ends[e] = ends.get(e, 0) + 1- if e == "proven" and m is not None:- left.append(m)- left.sort()- out[b] = (ends, left[len(left) // 2] if left else None)- return out- finally:- api.NIGHT, api.COST["wrong"], case.INNOCENT_LIARS = old- - - def main(argv=None):- p = argparse.ArgumentParser()- p.add_argument("--seeds", type=int, default=200)- p.add_argument("--minutes", type=int, nargs="+", default=[300, 270, 250, 240, 220])- p.add_argument("--liars", type=int, nargs="+", default=[3])- p.add_argument("--wrong", type=int, nargs="+", default=[15])- p.add_argument("--bots", nargs="+", default=list(BOTS))- a = p.parse_args(argv)- print("DEAD RECKONING difficulty: proven of %d seeds per bot (median minutes left on a win)" % a.seeds)- print("%-8s %-6s %-6s %s" % ("minutes", "liars", "wrong", " ".join("%-16s" % b for b in a.bots)))- for liars in a.liars:- for wrong in a.wrong:- for minutes in a.minutes:- res = measure(a.seeds, minutes, liars, wrong, a.bots)- cells = []- for b in a.bots:- ends, med = res[b]- bad = sum(v for k, v in ends.items() if k.startswith("no_case") or k in ("dead_end", "never_ends"))- cell = "%3d (%s)" % (ends.get("proven", 0), "-" if med is None else med)- if bad:- cell += " !%d" % bad- cells.append("%-16s" % cell)- print("%-8d %-6d %-6d %s" % (minutes, liars, wrong, " ".join(cells)))- print("(!N: N seeds the generator could not build, or a bot stuck; never counted as proven)")- - - if __name__ == "__main__":- main()+ """Win rates per bot under each setting of the GDD's difficulty knobs. + + python -m playtest.difficulty --seeds 200 + python -m playtest.difficulty --seeds 200 --minutes 300 250 220 --liars 3 4 --wrong 15 30 + + It changes the knobs in memory for the length of the run (game.api.NIGHT, + game.api.COST["wrong"], game.case.INNOCENT_LIARS) and puts them back; it writes + nothing. A setting where the generator cannot build some seed is reported as such. + Standard library only. + """ + import argparse + import os + import random + import sys + + sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + + import game.api as api # noqa: E402 + import game.case as case # noqa: E402 + from playtest.bots import BY_NAME # noqa: E402 + + BOTS = ("careful", "detective", "talker", "speedrun", "random") + MAX_STEPS = 2000 + + + def play(bot_name, seed): + try: + g = api.Game(seed=seed) + except Exception as e: # the generator could not build this seed with these knobs + return "no_case:%s" % type(e).__name__, None + bot = BY_NAME[bot_name]() + rng = random.Random("%s-%d" % (bot_name, seed)) + steps = 0 + while not g.over and steps < MAX_STEPS: + a = bot.pick(g, rng) + if a is None: + return "dead_end", None + g.step(a) + steps += 1 + return (g.ending or "never_ends"), g.state().get("minutes_left") + + + def measure(seeds, minutes, liars, wrong, bots): + old = (api.NIGHT, api.COST["wrong"], case.INNOCENT_LIARS) + api.NIGHT, api.COST["wrong"], case.INNOCENT_LIARS = minutes, wrong, liars + try: + out = {} + for b in bots: + ends, left = {}, [] + for s in range(1, seeds + 1): + e, m = play(b, s) + ends[e] = ends.get(e, 0) + 1 + if e in ("proven", "reckoned") and m is not None: + left.append(m) + left.sort() + out[b] = (ends, left[len(left) // 2] if left else None) + return out + finally: + api.NIGHT, api.COST["wrong"], case.INNOCENT_LIARS = old + + + def main(argv=None): + p = argparse.ArgumentParser() + p.add_argument("--seeds", type=int, default=200) + p.add_argument("--minutes", type=int, nargs="+", default=[300, 270, 250, 240, 220]) + p.add_argument("--liars", type=int, nargs="+", default=[3]) + p.add_argument("--wrong", type=int, nargs="+", default=[15]) + p.add_argument("--bots", nargs="+", default=list(BOTS)) + a = p.parse_args(argv) + print("DEAD RECKONING difficulty: proven of %d seeds per bot (median minutes left on a win)" % a.seeds) + print("%-8s %-6s %-6s %s" % ("minutes", "liars", "wrong", " ".join("%-16s" % b for b in a.bots))) + for liars in a.liars: + for wrong in a.wrong: + for minutes in a.minutes: + res = measure(a.seeds, minutes, liars, wrong, a.bots) + cells = [] + for b in a.bots: + ends, med = res[b] + bad = sum(v for k, v in ends.items() if k.startswith("no_case") or k in ("dead_end", "never_ends")) + cell = "%3d (%s)" % (ends.get("proven", 0) + ends.get("reckoned", 0), "-" if med is None else med) + if bad: + cell += " !%d" % bad + cells.append("%-16s" % cell) + print("%-8d %-6d %-6d %s" % (minutes, liars, wrong, " ".join(cells))) + print("(!N: N seeds the generator could not build, or a bot stuck; never counted as proven)") + + + if __name__ == "__main__": + main()
The whole file
"""Win rates per bot under each setting of the GDD's difficulty knobs.
python -m playtest.difficulty --seeds 200
python -m playtest.difficulty --seeds 200 --minutes 300 250 220 --liars 3 4 --wrong 15 30
It changes the knobs in memory for the length of the run (game.api.NIGHT,
game.api.COST["wrong"], game.case.INNOCENT_LIARS) and puts them back; it writes
nothing. A setting where the generator cannot build some seed is reported as such.
Standard library only.
"""
import argparse
import os
import random
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import game.api as api # noqa: E402
import game.case as case # noqa: E402
from playtest.bots import BY_NAME # noqa: E402
BOTS = ("careful", "detective", "talker", "speedrun", "random")
MAX_STEPS = 2000
def play(bot_name, seed):
try:
g = api.Game(seed=seed)
except Exception as e: # the generator could not build this seed with these knobs
return "no_case:%s" % type(e).__name__, None
bot = BY_NAME[bot_name]()
rng = random.Random("%s-%d" % (bot_name, seed))
steps = 0
while not g.over and steps < MAX_STEPS:
a = bot.pick(g, rng)
if a is None:
return "dead_end", None
g.step(a)
steps += 1
return (g.ending or "never_ends"), g.state().get("minutes_left")
def measure(seeds, minutes, liars, wrong, bots):
old = (api.NIGHT, api.COST["wrong"], case.INNOCENT_LIARS)
api.NIGHT, api.COST["wrong"], case.INNOCENT_LIARS = minutes, wrong, liars
try:
out = {}
for b in bots:
ends, left = {}, []
for s in range(1, seeds + 1):
e, m = play(b, s)
ends[e] = ends.get(e, 0) + 1
if e in ("proven", "reckoned") and m is not None:
left.append(m)
left.sort()
out[b] = (ends, left[len(left) // 2] if left else None)
return out
finally:
api.NIGHT, api.COST["wrong"], case.INNOCENT_LIARS = old
def main(argv=None):
p = argparse.ArgumentParser()
p.add_argument("--seeds", type=int, default=200)
p.add_argument("--minutes", type=int, nargs="+", default=[300, 270, 250, 240, 220])
p.add_argument("--liars", type=int, nargs="+", default=[3])
p.add_argument("--wrong", type=int, nargs="+", default=[15])
p.add_argument("--bots", nargs="+", default=list(BOTS))
a = p.parse_args(argv)
print("DEAD RECKONING difficulty: proven of %d seeds per bot (median minutes left on a win)" % a.seeds)
print("%-8s %-6s %-6s %s" % ("minutes", "liars", "wrong", " ".join("%-16s" % b for b in a.bots)))
for liars in a.liars:
for wrong in a.wrong:
for minutes in a.minutes:
res = measure(a.seeds, minutes, liars, wrong, a.bots)
cells = []
for b in a.bots:
ends, med = res[b]
bad = sum(v for k, v in ends.items() if k.startswith("no_case") or k in ("dead_end", "never_ends"))
cell = "%3d (%s)" % (ends.get("proven", 0) + ends.get("reckoned", 0), "-" if med is None else med)
if bad:
cell += " !%d" % bad
cells.append("%-16s" % cell)
print("%-8d %-6d %-6d %s" % (minutes, liars, wrong, " ".join(cells)))
print("(!N: N seeds the generator could not build, or a bot stuck; never counted as proven)")
if __name__ == "__main__":
main()
Shown as text, exactly as the agents wrote it. Nothing here is run.