Attempt at a fairer idler chooser
authorMark Tearle <[email protected]>
Thu, 30 Sep 2004 16:04:24 +0000 (16:04 +0000)
committerMark Tearle <[email protected]>
Thu, 30 Sep 2004 16:04:24 +0000 (16:04 +0000)
sql-edition/servers/Idler.py
sql-edition/servers/VendServer.py

index fc7573a..eedfe73 100755 (executable)
@@ -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
index 3f2c72f..b623be6 100755 (executable)
@@ -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():

UCC git Repository :: git.ucc.asn.au