Skip to content

Commit

Permalink
Swap out random.choices in OcarinaSongs.py
Browse files Browse the repository at this point in the history
  • Loading branch information
phixtyseven committed Sep 27, 2018
1 parent 8c503f5 commit a2a260a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions OcarinaSongs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
}

import random
from Utils import random_choices

# checks if one list is a sublist of the other (in either direction)
# python is magic.....
Expand Down Expand Up @@ -64,7 +65,7 @@ def identity(x):
return x

def random_piece(count, allowed=range(0,5)):
return random.choices(allowed, k=count)
return random_choices(allowed, k=count)

def invert_piece(piece):
return [4 - note for note in piece]
Expand Down Expand Up @@ -197,7 +198,7 @@ def __init__(self, rand_song=True, piece_size=3, extra_position='none', starting

if rand_song:
self.length = random.randint(4, 8)
self.activation = random.choices(range(0,5), k=self.length)
self.activation = random_choices(range(0,5), k=self.length)
self.playback = random_playback(self.activation)
else:
if extra_position != 'none':
Expand All @@ -214,28 +215,28 @@ def __init__(self, rand_song=True, piece_size=3, extra_position='none', starting
# randomly choose song parameters
def get_random_song():

rand_song = random.choices([True, False], [1, 9])[0]
piece_size = random.choices([3, 4], [5, 2])[0]
extra_position = random.choices(['none', 'start', 'middle', 'end'], [12, 1, 1, 1])[0]
rand_song = random_choices([True, False], [1, 9])[0]
piece_size = random_choices([3, 4], [5, 2])[0]
extra_position = random_choices(['none', 'start', 'middle', 'end'], [12, 1, 1, 1])[0]
activation_transform = identity
playback_transform = identity
weight_damage = 0
should_transpose = random.choices([True, False], [1, 4])[0]
should_transpose = random_choices([True, False], [1, 4])[0]
starting_range=range(0,5)
if should_transpose:
weight_damage = 2
direction = random.choices(['up', 'down'], [1, 1])[0]
direction = random_choices(['up', 'down'], [1, 1])[0]
if direction == 'up':
starting_range=range(0,4)
activation_transform = transpose_piece(1)
elif direction == 'down':
starting_range=range(1,5)
activation_transform = transpose_piece(-1)
should_invert = random.choices([True, False], [3 - weight_damage, 6])[0]
should_invert = random_choices([True, False], [3 - weight_damage, 6])[0]
if should_invert:
weight_damage += 1
activation_transform = compose(invert_piece, activation_transform)
should_reflect = random.choices([True, False], [5 - weight_damage, 4])[0]
should_reflect = random_choices([True, False], [5 - weight_damage, 4])[0]
if should_reflect:
activation_transform = compose(reverse_piece, activation_transform)
playback_transform = reverse_piece
Expand Down Expand Up @@ -375,4 +376,4 @@ def str_to_song(song:str):
raise Exception('Invalid note %s. Valid notes are A, D, R, L, U' % c)

notes.append(note_map[c])
return Song(activation=notes)
return Song(activation=notes)

0 comments on commit a2a260a

Please sign in to comment.