Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.fbb.msu.ru/trac/petri_dish/changeset/15
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 06:37:54 2016
Êîäèðîâêà: IBM-866
Changeset 15:5cc5069458a9 òÀÓ Petri Dish

Changeset 15:5cc5069458a9


Ignore:
Timestamp:
12/15/10 03:04:54 (5 years ago)
Author:
Smirnova Victoria
Branch:
default
Message:

Bacteria.py module 0.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Bacteria.py

    r7 r15 ˆà
    1ˆàfrom random import*ˆà
    ˆà1from random import *ˆà
    ˆà2from math import *ˆà
    23ˆà
    34class Bacteria (object):ˆà
    òÀæ òÀæ ˆà
    89        self.mutated=mutatedˆà
    910ˆà
    10ˆà    def check_collision (self, bacteria):ˆà
    ˆà11    def check_collision (self, bacteria, delta, bact_r):ˆà
    1112        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:ˆà
    1314                return bactˆà
    1415            return falseˆà
    1516ˆà
    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ˆà
    1821ˆà
    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)ˆà
    2125    ˆà
    2226    def reprod (type, env, p_max):ˆà
    òÀæ òÀæ ˆà
    2731        return randrange(0, int(1/p))==0    ˆà
    2832ˆà
    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):ˆà
    3039        passˆà
    3140ˆà
    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):ˆà
    3356        passˆà
    3457ˆà
    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):ˆà
    3662        passˆà
    3763    ˆà
    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.