From 92192e8cce7e4aa9de005ef7e32b13eca1776a79 Mon Sep 17 00:00:00 2001 From: Mark Tearle Date: Thu, 30 Sep 2004 16:04:24 +0000 Subject: [PATCH] Attempt at a fairer idler chooser --- sql-edition/servers/Idler.py | 5 ++++- sql-edition/servers/VendServer.py | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) 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(): -- 2.20.1