Example #1
0
 def breed(self, mate):
     if not mate.breedable():
         return
     for partner in self.crew:
         # no sterile or pregnant partners
         if not partner.breedable():
             continue
         if partner.sex == mate.sex:
             continue
         # no fathers or mothers
         if partner.crew_id == mate.mom.crew_id or partner.crew_id == mate.dad.crew_id:
             continue
         if mate.crew_id == partner.mom.crew_id or mate.crew_id == partner.dad.crew_id:
             continue
         prob = .006
         # half siblings and full siblings
         if mate.dad.crew_id == partner.dad.crew_id:
             prob *= .01
         if mate.mom.crew_id == partner.mom.crew_id:
             prob *= .01
         if random.random() < prob:
             baby = Crewmate()
             mate.breeding = True
             partner.breeding = True
             if mate.sex == Sex.Male:
                 baby.be_born(mate, partner)
             else:
                 baby.be_born(partner, mate)
             self.crew.append(baby)
             print UI.inline_print(baby)+" has been born."
             print "Their parents are "+mate.name+" and "+partner.name
             return
Example #2
0
def test_generate_child():
    crew = initial.test_crew_infant()
    # child = Crewmate()
    baby = Crewmate()
    baby.be_born(crew[0], crew[1])
    # ui.full_info(baby)
    if any_uninitialized(baby):
        print "test_generate_child failed"
Example #3
0
def test_get_set_attributes():
    crew1 = Crewmate()
    crew1.empathy = 5
    crew1.intelligence = 5
    crew1.creativity = 5
    if crew1.empathy != 5:
        print "Error, something is wrong with getting or setting empathy"
    if crew1.intelligence != 5:
        print "Error, something is wrong with getting or setting intelligence"
    if crew1.creativity != 5:
        print "Error, something is wrong with getting or setting creativity"
Example #4
0
def test_growing_up():
    crew1 = Crewmate()
    crew2 = Crewmate()

    crew1.age = 1
    crew1.grow_one_year()
    if crew1.age != 2:
        print "Error, problem growing one year to 2"
    if crew1.adult is not False:
        print "Error, infant is being reported as adult"

    crew2.age = 14
    crew2.grow_one_year()
    if crew2.age != 15:
        print "Error, problem growing one year to 15"
    if crew2.adult is not True:
        print "Error, adult is not being reported as such"
Example #5
0
def test_sex():
    crew1 = Crewmate()
    crew2 = Crewmate()

    crew1.set_sex(Sex.Female)
    if crew1.sex != Sex.Female:
        print "Sex isn't able to be assigned manually"

    crew2.set_sex()
    if crew2.sex != Sex.Male and crew2.sex != Sex.Female:
        print "Sex isn't correctly assigned randomly"
        print crew2.sex
Example #6
0
def test_crew_id_increment():
    crew1 = Crewmate()
    crew2 = Crewmate()

    # print "crew1 "+str(crew1.get_id())+". crew2 "+str(crew2.get_id())
    if crew2.get_id() - crew1.get_id() != 1:
        print "Error, crew_id_increment broken"
Example #7
0
 def breed(self, mate):
     if not mate.breedable():
         return
     for partner in self.crew:
         # no sterile or pregnant partners
         if not partner.breedable():
             continue
         if partner.sex == mate.sex:
             continue
         # no fathers or mothers
         if partner.crew_id == mate.mom.crew_id or partner.crew_id == mate.dad.crew_id:
             continue
         if mate.crew_id == partner.mom.crew_id or mate.crew_id == partner.dad.crew_id:
             continue
         prob = .006
         # half siblings and full siblings
         if mate.dad.crew_id == partner.dad.crew_id:
             prob *= .01
         if mate.mom.crew_id == partner.mom.crew_id:
             prob *= .01
         if random.random() < prob:
             baby = Crewmate()
             mate.breeding = True
             partner.breeding = True
             if mate.sex == Sex.Male:
                 baby.be_born(mate, partner)
             else:
                 baby.be_born(partner, mate)
             self.crew.append(baby)
             print UI.inline_print(baby) + " has been born."
             print "Their parents are " + mate.name + " and " + partner.name
             return
Example #8
0
def import_crew():
    temp = Ship()
    genetics = import_genetics()
    seed = []
    for _ in range(100):
        mate = Crewmate()
        mate.set_sex()
        mate.set_name()
        mate.adult = True
        create_genome(mate, genetics)
        seed.append(mate)
    temp.crew = seed
    # while len(temp.crew) < 101:
    #     temp.breed_all()
    #     print "breeding"
    temp.breed_all()
    del temp.crew[0:100]
    for mate in temp.crew:
        mate.age = int(20 * random.random()) + 15
        mate.become_adult()

    return temp.crew
Example #9
0
def test_set_parents():
    crew1 = Crewmate()
    crew2 = Crewmate()
    crew3 = Crewmate()
    crew3.set_parents(crew1, crew2)
    if crew3.dad != crew1:
        print "Error, not the right dad"
    if crew3.mom != crew2:
        print "Error, not the right mom"
Example #10
0
def test_inheriting_genome():
    crew = initial.test_crew_adult()
    child = Crewmate()
    child.set_parents(crew[0], crew[1])
    var0 = False
    var1 = False
    for _ in range(10):
        child.inherit()
        for gene in child.genome[0]:
            if gene.condition == "00":
                var0 = True
            if gene.condition == "01":
                var1 = True
    if not (var0 and var1):
        print "test_inheriting_genome failed"
Example #11
0
def test_naming():
    crew1 = Crewmate()
    crew2 = Crewmate()
    crew3 = Crewmate()

    crew1.set_name("foo",
                   "bar")  #remember, first name is last, last name is first
    if crew1.name != "bar foo":
        print "Error, name isn't being correctly set manually"
        print crew1.name + " should be bar foo"

    crew2.set_sex()
    crew2.set_name("bar")
    if "bar" not in crew2.name:
        print "Error, name isn't being set correctly when given just last name"
        print crew2.name + " should have last name bar"

    crew3.set_sex()
    crew3.set_name()
    if crew3.name == "Unnamed":
        print "Error, name isn't being set correctly when given no names"
        print crew3.name
Example #12
0
def test_assign_job():
    crew = Crewmate()
    crew.job = "Tester"
    # crew.training = True
    crew.grow_one_year()
Example #13
0
def test_crew_adult():

    gene00 = Gene()
    gene00.locus = 0
    gene00.condition = "00"
    gene00.condition_prob = 1
    gene00.congential = 1  # Congential = 0, Adult = 1
    gene00.dominant = True  # Genes are either recessive or dominant. We Mendel for now
    gene00.emp = 1
    gene00.int = 1
    gene00.cre = 1

    gene01 = Gene()
    gene01.locus = 0
    gene01.condition = "01"
    gene01.condition_prob = 1
    gene01.congential = 1  #Congential = 0, Adult = 1
    gene01.dominant = False  #Genes are either recessive or dominant. We Mendel for now
    gene01.emp = -1
    gene01.int = -1
    gene01.cre = -1

    crew1 = Crewmate()
    crew1.set_sex()
    crew1.set_name("01", "crew")
    crew1.genome.append([gene00, gene01])

    crew2 = Crewmate()
    crew2.set_sex()
    crew2.set_name("02", "crew")
    crew2.genome.append([gene01, gene01])

    crew1.mom = Crewmate()
    crew1.mom.name = "mom"
    crew1.dad = Crewmate()
    crew1.dad.name = "dad"

    crew2.mom = Crewmate()
    crew2.mom.name = "mom"
    crew2.dad = Crewmate()
    crew2.dad.name = "dad"

    return [crew1, crew2]