From: Mark Tearle Date: Thu, 30 Sep 2004 16:04:24 +0000 (+0000) Subject: Attempt at a fairer idler chooser X-Git-Tag: IMPORT-FROM-UCCCVS~57 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=80bad34b7547af4a4bb0b3d26c3c8e3357c55728;p=uccvend-vendserver.git Attempt at a fairer idler chooser --- diff --git a/sql-edition/servers/Idler.py b/sql-edition/servers/Idler.py index fc7573a..eedfe73 100755 --- a/sql-edition/servers/Idler.py +++ b/sql-edition/servers/Idler.py @@ -230,6 +230,9 @@ class ClockIdler(Idler): self.v.display(" %8.8s " % (output)) self.last = output + def affinity(self): + return 3 + class FortuneIdler(StringIdler): def __init__(self, v): fortune = "/usr/games/fortune" @@ -242,4 +245,4 @@ class FortuneIdler(StringIdler): StringIdler.__init__(self, v, text,repeat=False) def affinity(self): - return 15 + return 20 diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index 3f2c72f..b623be6 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -193,9 +193,9 @@ def setup_idlers(v): StringIdler(v, text=CREDITS), StringIdler(v, text=str(math.pi) + " "), StringIdler(v, text=str(math.e) + " "), - StringIdler(v), FortuneIdler(v), ClockIdler(v), + StringIdler(v), GrayIdler(v), TrainIdler(v), GrayIdler(v,one="*",zero="-"), @@ -205,11 +205,25 @@ def setup_idlers(v): GrayIdler(v,one="/",zero="\\",reorder=1), GrayIdler(v,one="X",zero="O",reorder=1), ] + disabled = [ + ] idler = choose_idler() def choose_idler(): global idler - idler = idlers[int(random()*len(idlers))] + iiindex = 0 + + if idler: + iiindex = idlers.index(idler) + + iilen = len(idlers) + + move = int(random()*len(idlers)) + 1 + + while move >= 0: + idler = idlers[( (iiindex + 1) % iilen)] + move = move - idler.affinity() + idler.reset() def idle_step():