Exemplo n.º 1
0
  def mutateAt(self, index):
    result = False
    blob = self.blobs[index]
    newBlob = blob.clone()

    newBlob.radius += 1

    if not self.validate(newBlob):
      for i in range(5):
        offset = Vector.randomUnitCircle() * random()*i
        newBlob.pos += offset

        if self.validate(newBlob):
          result = True
          break
    else:
      result = True

    if not result and random() > 0.5:
      newBlob.radius -= 1
      for i in range(5):
        offset = Vector.randomUnitCircle() * random()*i

        if self.validate(newBlob):
          result = True


    if result:
      self.blobs[index] = newBlob

    return result
Exemplo n.º 2
0
  def spawn(self):
    if len(self.blobs) > 0:
      randomBlob = choice(self.blobs)

      pos = randomBlob.pos + (Vector.randomUnitCircle() * randomBlob.radius * 2) * random()
    else:
      pos = Vector(random() * self.screenDim[0], random() * self.screenDim[1])

    self.spawnAt(pos)
Exemplo n.º 3
0
 def spawn(self):
   x = choice(range(self.screenDim[0]))
   y = choice(range(self.screenDim[1]))
   pos = Vector(x,y)
   if not self.isSet(pos):
     self.motives.append(Motive(pos, Vector.randomUnitCircle(), choice([MotiveType.Car, MotiveType.Pedestrian])))