Created
November 21, 2009 21:01
-
-
Save ptarjan/240270 to your computer and use it in GitHub Desktop.
Algorithm for swtiching instruments in rockband. http://blog.paulisageek.com/2009/10/rock-band-group-algorithm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import sys | |
instruments = ["Drums", "Vocals", "Guitar", "Bass"] | |
people = sys.argv[1:] | |
if len(people) == 0: | |
print "python rockband.py Name1 Name2 ..." | |
sys.exit() | |
if len(people) < len(instruments): | |
print "If there is less than %d people, just pick some instruments, rotate, and then shuffle. You don't need me for that" % len(instruments) | |
sys.exit() | |
random.shuffle(people) | |
num = len(people) | |
places = [' Gap']*num | |
instruments_ids = [0, int(num*0.25), int(num*0.5), int(num*0.75)] | |
for i, ins in zip(instruments_ids, instruments): | |
places[i] = ins | |
while True : | |
for l,n in zip(places, people): | |
print "%s:\t%s" % (l, n) | |
if raw_input("Press <Enter> once you finished a round: ") == "q" : | |
break | |
print "" | |
playing = [people[x] for x in instruments_ids] | |
not_playing = list(set(people) - set(playing)) | |
if len(not_playing) < len(instruments) : | |
new_playing = not_playing + random.sample(playing, len(instruments) - len(not_playing)) | |
else : | |
new_playing = random.sample(not_playing, len(instruments)) | |
new_not_playing = list(set(people) - set(new_playing)) | |
random.shuffle(new_playing) | |
random.shuffle(new_not_playing) | |
people = [None]*num | |
for i, p in zip(instruments_ids, new_playing) : | |
people[i] = p | |
count = 0 | |
for i in xrange(len(people)) : | |
if not people[i] : | |
people[i] = new_not_playing[count] | |
count += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment