srdice.py

Created by lastfuture

Created on October 19, 2018

1.01 KB

Shadowrun dice roller with exploding sixes (edge) and glitch/critical detection


from random import randint

_s = chr(144)

def _re(dice, edge=False):
  ro = _r(dice)
  _dp(ro["d"])
  if edge:
    rs = ro["s"]
    while rs:
      rr = _r(rs)
      for k in ro:
        ro[k] += rr[k]
      rs = rr["s"]
      _dp(rr["d"])
  if ro["o"] >= len(ro["d"])/2:
    if ro["h"]:
      print(_s+" glitch!")
    else:
      print(_s+" CRITICAL GLITCH!")
  if ro["h"]:
    print(_s+_s+" "+str(ro["h"])+" ")
  print()

def _dp(d):
  print((chr(149) if len(d) <= 15 else "").join(map(str,sorted(d)[::-1])))

def _r(di):
  out = dict(d=[], h=0, s=0, o=0)
  for i in range(di):
    r = randint(1,6)
    out["d"].append(r)
    if r == 6:
      out["s"] += 1
    if r >= 5:
      out["h"] += 1
    if r == 1:
      out["o"] += 1
  return out

def roll():
  _di = True
  for i in range(12):
    print()
  while _di:
    ed = False
    _di = input("Roll (d,e) "+_s+" ")
    if _di == "" or _di == "0":
      break
    _di = _di.split(",",2)
    if len(_di) > 1:
      ed = int(_di[1])
    _di = int(_di[0])
    _re(_di, ed)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.