Changeset 15:5cc5069458a9
- Timestamp:
- 12/15/10 03:04:54 (5 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Bacteria.py
r7 r15 ˆà 1 ˆà from random import*ˆà ˆà 1 from random import *ˆà ˆà 2 from math import *ˆà 2 3 ˆà 3 4 class Bacteria (object):ˆà òÀæ òÀæ ˆà 8 9 self.mutated=mutatedˆà 9 10 ˆà 10 ˆà def check_collision (self, bacteria ):ˆàˆà 11 def check_collision (self, bacteria, delta, bact_r):ˆà 11 12 for bact in bacteria:ˆà 12 ˆà if 0<abs(self.position-bact.position)< 3:ˆàˆà 13 if 0<abs(self.position-bact.position)<delta+2*bact_r:ˆà 13 14 return bactˆà 14 15 return falseˆà 15 16 ˆà 16 ˆà def move (self, delta_t, radius):ˆà 17 ˆà passˆà ˆà 17 def move (self, delta_t, radius, delta, bact_r):ˆà ˆà 18 if abs(self.position)<radius-(bact_r+delta):ˆà ˆà 19 self.velocity=self.velocity.angleToCoord(-(pi/2-self.velocity.angle()))ˆà ˆà 20 self.position=self.position*delta_tˆà 18 21 ˆà 19 ˆà def collision (self, other, delta_t):ˆà 20 ˆà passˆà ˆà 22 def collision (self, other, delta_t, radius, delta, bact_r):ˆà ˆà 23 self.velocity, other.velocity = other.velocity, self.velocity ˆà ˆà 24 self.move (delta_t, radius, delta, bact_r)ˆà 21 25 ˆà 22 26 def reprod (type, env, p_max):ˆà òÀæ òÀæ ˆà 27 31 return randrange(0, int(1/p))==0 ˆà 28 32 ˆà 29 ˆà def asexual (self, bacteria, delta_t, radius):ˆà ˆà 33 def asexual (self, bacteria, delta_t, radius, delta, bact_r, full_lifetime):ˆà ˆà 34 if self.find_place_a(bacteria, delta, bact_r):ˆà ˆà 35 bacteria.append(Bacteria(self.position+Vector(-(bact_r+0.75*delta),0),ˆà ˆà 36 self.rnd_velocity(), full_lifetime, self.if_mutated()))ˆà ˆà 37 ˆà ˆà 38 def sexual (self, other, bacteria, delta_t, radius, delta, bact_r, full_lifetime):ˆà 30 39 passˆà 31 40 ˆà 32 ˆà def sexual (self, other, bacteria, delta_t, radius):ˆà ˆà 41 def find_place_a (self, bacteria, delta, bact_r): #searches for place for childrenˆà ˆà 42 for bact in bacteria:ˆà ˆà 43 if 0<abs(bact.position-self.position)<(bact_r*3+delta*2):ˆà ˆà 44 return falseˆà ˆà 45 return trueˆà ˆà 46 ˆà ˆà 47 ˆà ˆà 48 def find_place_s (self, other, bacteria, delta, bact_r):ˆà ˆà 49 for bact in bacteria:ˆà ˆà 50 if bact_r<abs(bact.position-(self.position+other.position)*(1/2))<((sqrt(2)+1)*bact_r*2+delta*2):ˆà ˆà 51 return falseˆà ˆà 52 return trueˆà ˆà 53 ˆà ˆà 54 ˆà ˆà 55 def rnd_velocity(self):ˆà 33 56 passˆà 34 57 ˆà 35 ˆà def find_place_a (self, bacteria): #searches for place for childrenˆà ˆà 58 def if_mutated_a(self):ˆà ˆà 59 passˆà ˆà 60 ˆà ˆà 61 def if_mutated__s(self,other):ˆà 36 62 passˆà 37 63 ˆà 38 ˆà def find_place_s (self, other, bacteria):ˆà 39 ˆà passˆà ˆà 64 ˆà ˆà 65 ˆà ˆà 66 ˆà ˆà 67 ˆà ˆà 68 ˆà
Note: See TracChangeset
for help on using the changeset viewer.