本文整理匯總了Python中Darwin.Darwin.add_creature方法的典型用法代碼示例。如果您正苦於以下問題:Python Darwin.add_creature方法的具體用法?Python Darwin.add_creature怎麽用?Python Darwin.add_creature使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Darwin.Darwin
的用法示例。
在下文中一共展示了Darwin.add_creature方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_facing_enemy1
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_facing_enemy1(self):
x = Darwin(2, 2)
y = Species()
z = Creature(y, "Bob", 2, 0, 0)
x.add_creature(z)
a = x.facing_enemy(0, 0)
self.assertEqual(a, False)
示例2: test_print_grid
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_print_grid(self):
x = Darwin(1,1)
y = Species()
z = Creature(y, "Bob", 2, 0, 0)
x.add_creature(z)
a = x.print_grid()
self.assertEqual(a, None)
示例3: test_facing_wall4
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_facing_wall4(self):
x = Darwin(2, 2)
y = Species()
z = Creature(y, "Bob", 3, 0, 0)
x.add_creature(z)
a = x.facing_wall(0, 0)
self.assertEqual(a, True)
示例4: test_facing_enemy5
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_facing_enemy5(self):
x = Darwin(2, 2)
y = Species()
z = Creature(y, "Bob", 1, 0, 0)
u = Creature(y, "Joe", 1, 0, 1)
x.add_creature(z)
x.add_creature(u)
a = x.facing_enemy(0, 0)
self.assertEqual(a, False)
示例5: test_darwin_hop1
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_darwin_hop1(self):
x = Darwin(2, 2)
y = Species()
z = Creature(y, "Bob", 0, 0, 0)
x.add_creature(z)
y.add_instruction("hop")
x.cycle()
a = z.c
b = z.r
self.assertEqual(a, 0)
self.assertEqual(b, 0)
示例6: test_darwin_cycle1
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_darwin_cycle1(self):
x = Darwin(2, 2)
y = Species()
z = Creature(y, "Bob", 2, 0, 0)
t = Species()
r = Creature(t, "Joe", 2, 1, 0)
x.add_creature(z)
y.add_instruction("infect")
x.cycle()
a = z.c
b = z.r
self.assertEqual(a, 0)
self.assertEqual(b, 0)
示例7: test_run2
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_run2(self):
# food
food = Species([], 'f')
food.add_instr(['left'])
food.add_instr(['go', 0])
# hopper
hopper = Species([], 'h')
hopper.add_instr(['hop'])
hopper.add_instr(['go', 0])
# rover
rover = Species([], 'r')
rover.add_instr(['if_enemy', 9])
rover.add_instr(['if_empty', 7])
rover.add_instr(['if_random', 5])
rover.add_instr(['left'])
rover.add_instr(['go', 0])
rover.add_instr(['right'])
rover.add_instr(['go', 0])
rover.add_instr(['hop'])
rover.add_instr(['go', 0])
rover.add_instr(['infect'])
rover.add_instr(['go', 0])
# trap
trap = Species([], 't')
trap.add_instr(['if_enemy', 3])
trap.add_instr(['left'])
trap.add_instr(['go', 0])
trap.add_instr(['infect'])
trap.add_instr(['go', 0])
t1 = Creature(trap, 3)
h1 = Creature(hopper, 2)
r1 = Creature(rover, 1)
t2 = Creature(trap, 4)
g2 = Darwin(7, 9)
g2.add_creature(t1, 0, 0)
g2.add_creature(h1, 3, 2)
g2.add_creature(r1, 5, 4)
g2.add_creature(t2, 6, 8)
self.assertEqual(g2.run(5),None)
示例8: test_run3
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_run3(self):
# food
food = Species([], 'f')
food.add_instr(['left'])
food.add_instr(['go', 0])
# hopper
hopper = Species([], 'h')
hopper.add_instr(['hop'])
hopper.add_instr(['go', 0])
# rover
rover = Species([], 'r')
rover.add_instr(['if_enemy', 9])
rover.add_instr(['if_empty', 7])
rover.add_instr(['if_random', 5])
rover.add_instr(['left'])
rover.add_instr(['go', 0])
rover.add_instr(['right'])
rover.add_instr(['go', 0])
rover.add_instr(['hop'])
rover.add_instr(['go', 0])
rover.add_instr(['infect'])
rover.add_instr(['go', 0])
# trap
trap = Species([], 't')
trap.add_instr(['if_enemy', 3])
trap.add_instr(['left'])
trap.add_instr(['go', 0])
trap.add_instr(['infect'])
trap.add_instr(['go', 0])
g3 = Darwin(72, 72)
creatureTypes = [food, hopper, rover, trap]
for ctype in creatureTypes:
for i in range (0, 10):
row = random.randrange(0, 72)
col = random.randrange(0, 72)
direction = random.randrange(0, 4)
g3.add_creature(Creature(ctype, direction), row, col)
self.assertEqual(g3.run(5),None)
示例9: test_run1
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_run1(self):
food = Species([], 'f')
food.add_instr(['left'])
food.add_instr(['go', 0])
hopper = Species([], 'h')
hopper.add_instr(['hop'])
hopper.add_instr(['go', 0])
f1 = Creature(food, 2)
h1 = Creature(hopper, 1)
h2 = Creature(hopper, 2)
h3 = Creature(hopper, 3)
h4 = Creature(hopper, 4)
f2 = Creature(food, 1)
g1 = Darwin(8, 8)
g1.add_creature(f1, 0, 0)
g1.add_creature(h1, 3, 3)
g1.add_creature(h2, 3, 4)
g1.add_creature(h3, 4, 4)
g1.add_creature(h4, 4, 3)
g1.add_creature(f2, 7, 7)
self.assertEqual(g1.run(5),None)
示例10: test_darwin_take_action4
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_darwin_take_action4(self):
x = Darwin(5, 10)
y = Species()
z = Creature(y, "Bob", 2, 0, 0)
t = Species()
r = Creature(t, "Joe", 2, 1, 0)
x.add_creature(z)
y.add_instruction("infect")
y.add_instruction("hop")
y.add_instruction("left")
y.add_instruction("right")
y.add_instruction("if_empty 5")
y.add_instruction("if_wall 6")
y.add_instruction("if_enemy 7")
y.add_instruction("if_random 0")
y.add_instruction("go 0")
for i in range(50):
x.cycle()
a = z.c
b = z.r
self.assertEqual(a, 0)
self.assertEqual(b, 4)
示例11: test_darwin_add_creature3
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_darwin_add_creature3(self):
x = Darwin(2, 2)
y = Species()
z = Creature(y, "Bob", 0, 1, 0)
a = x.add_creature(z)
self.assertEqual(a, True)
示例12: print
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
trap.add_instr(['left'])
trap.add_instr(['go', 0])
trap.add_instr(['infect'])
trap.add_instr(['go', 0])
print("*** Darwin 8x8 ***")
f1 = Creature(food, 2)
h1 = Creature(hopper, 1)
h2 = Creature(hopper, 2)
h3 = Creature(hopper, 3)
h4 = Creature(hopper, 4)
f2 = Creature(food, 1)
g1 = Darwin(8, 8)
g1.add_creature(f1, 0, 0)
g1.add_creature(h1, 3, 3)
g1.add_creature(h2, 3, 4)
g1.add_creature(h3, 4, 4)
g1.add_creature(h4, 4, 3)
g1.add_creature(f2, 7, 7)
g1.run(5)
print("*** Darwin 7x9 ***")
t1 = Creature(trap, 3)
h1 = Creature(hopper, 2)
r1 = Creature(rover, 1)
t2 = Creature(trap, 4)
g2 = Darwin(7, 9)
示例13: test_get_next1
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_get_next1(self):
D = Darwin(2,2)
D.add_creature("y",1,1)
self.assertEqual(D.get_next(2,1,1),(None, 1, 1))
示例14: test_add_creature3
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_add_creature3(self):
D = Darwin(3,3)
D.add_creature("z",0,0)
self.assertEqual(D.grid[0][0],'z')
示例15: test_add_creature2
# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add_creature [as 別名]
def test_add_creature2(self):
D = Darwin(2,2)
D.add_creature("y",1,1)
self.assertEqual(D.grid[1][1],'y')