Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Generation
diff options
context:
space:
mode:
authorOli <olivier.belanger@umontreal.ca>2007-06-06 00:02:21 (GMT)
committer Oli <olivier.belanger@umontreal.ca>2007-06-06 00:02:21 (GMT)
commita4db417a4daf807aa3cd395b457935d11345f9ac (patch)
tree44cbc7eb6ece6ec653d5578f8f2e6199e507e1e7 /Generation
parent280280298524aa63e144e87d6c32554a996c23d8 (diff)
Algo generators on properties
Diffstat (limited to 'Generation')
-rwxr-xr-xGeneration/Drunk.py67
-rw-r--r--Generation/GenerationPitch.py4
2 files changed, 54 insertions, 17 deletions
diff --git a/Generation/Drunk.py b/Generation/Drunk.py
index 4649aff..3d0823a 100755
--- a/Generation/Drunk.py
+++ b/Generation/Drunk.py
@@ -6,12 +6,15 @@
import random
class Drunk:
- def __init__( self, minValue, maxValue ):
- self.lastValue = random.randint( minValue, maxValue )
+ def __init__( self, minValue, maxValue, trackLength=None ):
+ self.minValue = min(minValue, maxValue)
+ self.maxValue = max(minValue, maxValue)
+ self.lastValue = random.randint( self.minValue, self.maxValue )
+
def getNextValue( self, maxStepSize, maxValue ):
if self.lastValue < 0 or self.lastValue > maxValue:
- return random.randint( 0, maxValue )
+ return random.randint( self.minValue, maxValue )
direction = self.getDirection( maxValue )
stepSize = self.getStepSize( direction, abs(maxStepSize), maxValue )
@@ -23,10 +26,10 @@ class Drunk:
self.lastValue += direction * random.randint( minStepSize, stepSize )
- if self.lastValue < 0:
- self.lastValue = 0
- elif self.lastValue > 14:
- self.lastValue = 14
+ if self.lastValue < self.minValue:
+ self.lastValue = self.minValue
+ elif self.lastValue > maxValue: #instead of 14...
+ self.lastValue = maxValue
else:
self.lastValue = self.lastValue
@@ -47,9 +50,11 @@ class Drunk:
return min( maxStepSize, maxValue - self.lastValue )
class DroneAndJump( Drunk ):
- def __init__( self, minValue, maxValue ):
- Drunk.__init__( self, minValue, maxValue )
- self.beforeLastValue = random.randint( minValue, maxValue )
+ def __init__( self, minValue, maxValue, trackLength=None ):
+ Drunk.__init__( self, minValue, maxValue, trackLength=None )
+ self.minValue = min(minValue, maxValue)
+ self.maxValue = max(minValue, maxValue)
+ self.beforeLastValue = self.minValue #random.randint( self.minValue, self.maxValue )
self.lastValue = self.beforeLastValue + 1
def getNextValue( self, maxStepSize, maxValue ):
@@ -68,9 +73,11 @@ class DroneAndJump( Drunk ):
return Drunk.getStepSize( self, direction, 0, maxValue )
class Repeter( Drunk ):
- def __init__( self, minValue, maxValue ):
- Drunk.__init__( self, minValue, maxValue)
- self.lastValue = random.randint( minValue, maxValue)
+ def __init__( self, minValue, maxValue, trackLength=None ):
+ Drunk.__init__( self, minValue, maxValue, trackLength=None)
+ self.minValue = min(minValue, maxValue)
+ self.maxValue = max(minValue, maxValue)
+ self.lastValue = random.randint( self.minValue, self.maxValue)
def getNextValue( self, maxStepSize, maxValue ):
self.lastValue = Drunk.getNextValue( self, abs(maxStepSize), maxValue )
@@ -83,8 +90,8 @@ class Repeter( Drunk ):
return Drunk.getStepSize( self, direction, 0, maxValue )
class Loopseg( Drunk ):
- def __init__( self, minValue, maxValue ):
- Drunk.__init__( self, minValue, maxValue )
+ def __init__( self, minValue, maxValue, trackLength=None ):
+ Drunk.__init__( self, minValue, maxValue, trackLength=None )
self.recordedValues = []
self.recordState = 2
self.recordPlayback = 0
@@ -123,3 +130,33 @@ class Loopseg( Drunk ):
def loopAround( self ):
self.lastValue = self.recordedValues[self.recordPlayback]
self.recordPlayback += 1
+
+class Line:
+ def __init__(self, minValue, maxValue, trackLength=20):
+ maxVal = max(minValue, maxValue)
+ if maxVal == minValue:
+ self.reverse = True
+ minVal = maxValue
+ self.lastValue = maxVal
+ else:
+ self.reverse = False
+ minVal = minValue
+ self.lastValue = minVal
+
+ scale = float(maxVal - minVal)
+ if self.reverse:
+ self.inc = -scale/trackLength
+ else:
+ self.inc = scale/trackLength
+
+ def getNextValue(self, rand, maxValue):
+ self.val = self.lastValue + int(random.randint(0, rand)*random.choice([-0.5,0.5]))
+ if self.val < 0:
+ self.val = 0
+ elif self.val > maxValue:
+ self.val = maxValue
+ else:
+ self.val = self.val
+ self.lastValue = self.val+self.inc
+ return self.val
+
diff --git a/Generation/GenerationPitch.py b/Generation/GenerationPitch.py
index 99fceaa..b4391d5 100644
--- a/Generation/GenerationPitch.py
+++ b/Generation/GenerationPitch.py
@@ -6,8 +6,8 @@ from Generation.GenerationConstants import GenerationConstants
class GenerationPitch:
def __init__( self, pattern ):
- MIN = 5
- MAX = 10
+ MIN = 0
+ MAX = 14
if pattern == 0:
self.pitchMethod = Drunk.Drunk( MIN, MAX )
elif pattern == 1: