Ejemplo n.º 1
0
 def test_read_board_1 (self):
     v = StringIO("3\n3\n...\n***\n...")
     game = Life(v)
     game.read_board()
     self.assertEqual(len(game.board[0]),5) # added 2 to account for the wall
     game.run_conway(1,1)
     self.assertEqual(game.board[1][2].symbol,"*")
Ejemplo n.º 2
0
    def reset_lives_sprites(self):
        self.life1 = Life(715, 3, self)
        self.life2 = Life(742, 3, self)
        self.life3 = Life(769, 3, self)

        if self.lives == 3:
            self.livesGroup = sprite.Group(self.life1, self.life2, self.life3)
        elif self.lives == 2:
            self.livesGroup = sprite.Group(self.life1, self.life2)
        elif self.lives == 1:
            self.livesGroup = sprite.Group(self.life1)
Ejemplo n.º 3
0
def gen_rand_area():

    print("DupoDebug: gen_rand_area()")

    global area

    if len(area) == 0:

        empty = Life.create_empty_area(Life.scr_res)
        box = Life.draw_box(Life.scr_res, empty)
        area.append(Life.gen_rand_area(Life.scr_res, box, "o", 2))
        print("DupoDebug: Line 48")
Ejemplo n.º 4
0
	def __init__(self, dataSet):
		self.dataSet = dataSet
		
		self.cardType = CardType.createType(self.generateList('type'), self.model)
		self.cardTypes = CardTypes.createTypes(self.generateList('types'), self.model)
		self.cmc = Cmc.createCmc(self.generateList('cmc'), self.model)
		self.colorIdentity = ColorIdentity.createColorIdentity(self.generateList('colorIdentity'), self.model)
		self.colors = Colors.createColors(self.generateList('colors'), self.model)
		self.hand = Hand.createHand(self.generateList('hand'), self.model)
		self.imageName = ImageName.createImageName(self.generateList('imageName'), self.model)
		self.layouts = Layouts.createLayouts(self.generateList('layout'), self.model)
		self.legalities = Legalities.createLegalities(self.generateList('legalities'), self.model)
		self.life = Life.createLife(self.generateList('life'), self.model)
		self.loyalty = Loyalty.createLoyalty(self.generateList('loyalty'), self.model)
		self.manaCost = ManaCost.createManaCost(self.generateList('manaCost'), self.model)
		self.name = Name.createName(self.generateList('name'), self.model)
		self.names = Names.createNames(self.generateList('names'), self.model)
		self.power = Power.createPower(self.generateList('power'), self.model)
		self.printings = Printings.createPrintings(self.generateList('printings'), self.model)
		self.rulings = Rulings.createRulings(self.generateList('rulings'), self.model)
		self.source = Source.createSource(self.generateList('source'), self.model)
		self.starter = Starter.createStarter(self.generateList('starter'), self.model)
		self.cardSubTypes = CardSubTypes.createSubTypes(self.generateList('subtypes'), self.model)
		self.cardSuperTypes = CardSuperTypes.createSuperTypes(self.generateList('supertypes'), self.model)
		self.text = Text.createText(self.generateList('text'), self.model)
		self.toughness = Toughness.createToughness(self.generateList('toughness'), self.model)
Ejemplo n.º 5
0
 def test_run2(self):
     x = Life(5,5, "Conway")
     x.place(0,1,ConwayCell(0, "Conway"))
     x.place(1,1,ConwayCell(1, "Conway"))
     x.place(2,1,ConwayCell(1, "Conway"))
     x.place(2,2,ConwayCell(0, "Conway"))
     x.place(3,1,ConwayCell(1, "Conway"))
     x.place(4,2,ConwayCell(1, "Conway"))
     self.assertEqual(x.run(3, []),None)
Ejemplo n.º 6
0
 def test_run1 (self): 
     x = Life(2,2, "Conway")
     x.place(0,0,ConwayCell(1, "Conway"))
     x.place(0,1,ConwayCell(1, "Conway"))
     x.place(1,0,ConwayCell(1, "Conway"))
     x.run(3,[])
     self.assertEqual(x.population_count, 4)
Ejemplo n.º 7
0
 def init_group(self):
     self.lives = []
     chromosome = [x for x in range(self.city_count)]
     for i in range(self.scale_N):
         random.shuffle(chromosome)  #随机打乱染色体顺序
         chromosome_cpy = chromosome[:]
         life = Life(chromosome_cpy, self.data)
         self.lives.append(life)
     self.sum_score = sum([life.adaptive_score for life in self.lives])
Ejemplo n.º 8
0
def mod_area():

    global area

    # Currnet years in the area
    curr_year = len(area) - 1
    # print("Debug: mod_area(): curr_year={}".format(curr_year))

    area.append(Life.thisIsLife(Life.scr_res, area[curr_year]))
Ejemplo n.º 9
0
 def test_run2 (self):
     x = Life(2,4, "Conway")
     x.place(0,0,ConwayCell(1, "Conway"))
     x.place(0,1,ConwayCell(1, "Conway"))
     x.place(0,3,ConwayCell(1, "Conway"))
     y = x.run(3,[3])
     self.assertEqual(x.population_count, 0)
Ejemplo n.º 10
0
    def newChild(self):
        #以交配概率mating_rate交配产生新的后代
        father = self.pick_one()
        rate = random.random()

        # 按概率交配
        if rate < self.mating_rate:
            mother = self.pick_one()
            chromosome = self.mating(father, mother)
        else:
            #没有交配权的加入新群体,等待基因突变
            chromosome = father.chromosome

        # 按概率突变
        rate = random.random()
        if rate < self.variation_rate:
            chromosome = self.variation(chromosome)

        return Life(chromosome, self.data)
Ejemplo n.º 11
0
 def test_life_live_neighbors2(self): 
     x = Life (2,2,"Conway")
     x.place (0,0, ConwayCell(0, "Conway"))
     x.place(0,1, ConwayCell(1, "Conway"))
     self.assertEqual (x.get_num_live_neighbors(1,1), 1)
Ejemplo n.º 12
0
 def test_life_6(self):
     initial = [['f',1,1],['dim',3,3]]
     j = Life(initial,".")
     k = j.__repr__()
     self.assertEqual(k,"")
Ejemplo n.º 13
0
 def test_life_place2(self):
     x = Life(2,2, "Conway")
     x.place(1,1,ConwayCell(0, "Conway"))
     self.assertEqual(x.matrix[0][0].status,0)
     self.assertEqual(x.matrix[1][1].str_type,"Conway")
Ejemplo n.º 14
0
def load_file_area():

    global area
    if len(area) == 0:
        area.append(Life.load_area(Life.scr_res, "area.txt"))
Ejemplo n.º 15
0
 def test_play_conway_4(self):
     v = StringIO("5\n4\n....\n....\n***.\n....\n.*.*")
     game = Life(v)
     game.read_board()
     game.play_round_Conway_Cell()
     self.assertEqual(game.board[2][3].status,0)
Ejemplo n.º 16
0
 def test_run_conway_4(self):
     v = StringIO("5\n4\n....\n....\n***.\n....\n.*.*")
     game = Life(v)
     game.read_board()
     game.run_conway(1,1)
     self.assertEqual(game.board[2][3].status,0)
Ejemplo n.º 17
0
from Life import *

# ---------------------
# Life Conway_Cell 21x13
# ---------------------

print("*** Life Conway_Cell 21x13 ***")
print()
"""
Simulate 12 evolutions.
Print every grid (i.e. 0, 1, 2, 3, ... 12)
"""

infile = open("RunLife.in", "r")

game = Life(infile)
game.read_board()

game.run_conway(12,1)

# ---------------------
# Life Conway_Cell 20x29
# ---------------------

print("*** Life Conway_Cell 20x29 ***")
print()
"""
Simulate 28 evolutions.
Print every 4th grid (i.e. 0, 4, 8, ... 28)
"""
Ejemplo n.º 18
0
 def test_print_matrix1(self):
     x = Life(2,2, "Conway")
     x.place(1,1,ConwayCell(0, "Conway"))
     y = x.print_matrix()
     self.assertEqual(y,None)
Ejemplo n.º 19
0
 def test_run3 (self): 
     x = Life(4,5, "Conway")
     x.place(0,2,FredkinCell(1, "Fredkin"))
     x.place(0,1,FredkinCell(1, "Fredkin"))
     x.place(0,3,FredkinCell(1, "Fredkin"))
     x.place(0,0,FredkinCell(1, "Fredkin"))
     x.place(1,1,FredkinCell(1, "Fredkin"))
     x.print_matrix()
     x.run(20, [])
     self.assertEqual(x.population_count, 0)
Ejemplo n.º 20
0
 def test_life_live_neighbors3(self): 
     x = Life (4,4,"Conway")
     x.place (0,0, ConwayCell(1, "Conway"))
     x.place(0,2, ConwayCell(1, "Conway"))
     x.place(1,0, ConwayCell(1, "Conway"))
     self.assertEqual (x.get_num_live_neighbors(1,1), 3)
Ejemplo n.º 21
0
 def test_read_board_3(self):
     v = StringIO("4\n4\n----\n-00-\n-00-\n----")
     game = Life(v)
     game.read_board()
     self.assertEqual(len(game.board[0]),6)
Ejemplo n.º 22
0
 def test_read_board_2(self):
     v = StringIO("4\n4\n....\n....\n....\n....")
     game = Life(v)
     game.read_board()
     self.assertEqual(len(game.board[0]),6) # added 2 to account for the wall
Ejemplo n.º 23
0
 def test_life_place3(self): 
     x = Life(2,2, "Conway")
     x.place(1,0,ConwayCell(1, "Conway"))
     self.assertEqual(x.matrix[1][0].status,1)
     self.assertEqual(x.matrix[1][0].str_type,"Conway")
Ejemplo n.º 24
0
def playLife():
    l = Life()
    l.run()
Ejemplo n.º 25
0
    def test_life_live_neightbors4(self):

        x = Life (8,8,"Conway")
        x.place(0,0, ConwayCell(1, "Conway"))
        x.place(0,1, ConwayCell(1, "Conway"))
        x.place(0,2, ConwayCell(1, "Conway"))
        x.place (0,3, ConwayCell(1, "Conway"))
        x.place(1,0, ConwayCell(1, "Conway"))
        x.place(1,1, ConwayCell(1, "Conway"))
        x.place (1,2, ConwayCell(1, "Conway"))
        x.place(1,3, ConwayCell(1, "Conway"))
        x.place(2,0, ConwayCell(1, "Conway"))
        x.place(2,1, ConwayCell(1, "Conway"))
        x.place (2,2, ConwayCell(1, "Conway"))
        x.place(2,3, ConwayCell(1, "Conway"))
        self.assertEqual (x.get_num_live_neighbors(1,1), 8)
Ejemplo n.º 26
0
#!/usr/bin/env python

# $LastChangedBy$
# $LastChangedRevision$
# $LastChangedDate$
# $HeadURL$

from Life import *
from Day import *
import datetime
import matplotlib.pyplot as plt

joe_blow = Life( "Joe Blow", datetime.date(1990, 1, 1), 1 )
print joe_blow.getProfile()

jane_blow = Life( "Jane Blow", datetime.date(1990, 1, 1), 0 )

# Test to see if they are distinct objects and are not static
print jane_blow
print joe_blow
print jane_blow.getProfile()
print joe_blow.getProfile()

monday = Day( datetime.date(2012, 12, 24), 170.0, 70.0 )
tuesday = Day( datetime.date(2012, 12, 25), 170.0, 71.0 )
wednesday = Day( datetime.date(2012, 12, 26), 170.0, 73.0 )
thursday = Day( datetime.date(2012, 12, 27), 170.0, 69.0 )
joe_blow.addDay(monday)
joe_blow.addDay(tuesday)
joe_blow.addDay(wednesday)
joe_blow.addDay(thursday)
Ejemplo n.º 27
0
 def test_read_board_5(self):
     v = StringIO("5\n4\n....\n....\n***.\n....\n.*.*")
     game = Life(v)
     game.read_board()
     self.assertEqual(len(game.board[0]),6)
     self.assertEqual(len(game.board),7)
Ejemplo n.º 28
0
 def test_play_fredkin_4(self):
     v = StringIO("4\n4\n----\n-00-\n-00-\n----")
     game = Life(v)
     game.read_board()
     game.play_round_Fredkin_Cell()
     self.assertEqual(game.board[2][3].status,1)
Ejemplo n.º 29
0
 def test_run_fredkin_4(self):
     v = StringIO("4\n4\n----\n-00-\n-00-\n----")
     game = Life(v)
     game.read_board()
     game.run_fredkin(1,1)
     self.assertEqual(game.board[2][3].status,0)
Ejemplo n.º 30
0
 def test_read_board_4(self):
     v = StringIO("2\n4\n....\n....")
     game = Life(v)
     game.read_board()
     self.assertEqual(len(game.board),4)
Ejemplo n.º 31
0
 def test_int_matrix1(self): 
     x = Life(3,3,"Fredkin")
     x.place(0,0, FredkinCell(1, "Fredkin"))
     self.assertEqual(x.int_matrix, [[0,0,0],[0,0,0],[0,0,0]])