Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
UCC
UCC Snack Machine Server Code
Commits
37efb139
Commit
37efb139
authored
Dec 13, 2014
by
Mark Tearle
Browse files
Modify idler selection algorithm
parent
5a6a5b47
Changes
1
Hide whitespace changes
Inline
Side-by-side
VendServer/VendServer.py
View file @
37efb139
...
...
@@ -288,23 +288,33 @@ def reset_idler(v, vstatus, t = None):
def
choose_idler
():
global
idlers
,
idler
iiindex
=
0
average_affinity
=
10
# guessing here...
if
idler
and
idler
.
__class__
!=
GreetingIdler
:
iiindex
=
idlers
.
index
(
idler
)
iilen
=
len
(
idlers
)
move
=
int
(
random
()
*
len
(
idlers
)
*
average_affinity
)
+
1
# Implementation of the King Of the Hill algorithm from;
# http://eli.thegreenplace.net/2010/01/22/weighted-random-generation-in-python/
#def weighted_choice_king(weights):
# total = 0
# winner = 0
# for i, w in enumerate(weights):
# total += w
# if random.random() * total < w:
# winner = i
# return winner
#
total
=
0
winner
=
None
for
choice
in
idlers
:
weight
=
choice
.
affinity
()
total
+=
weight
if
random
()
*
total
<
weight
:
winner
=
choice
while
move
>=
0
:
iiindex
+=
1
iiindex
%=
iilen
idler
=
idlers
[
iiindex
]
move
-=
idler
.
affinity
()
idler
=
winner
idler
.
reset
()
if
idler
:
idler
.
reset
()
def
idle_step
(
vstatus
):
global
idler
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment