本文整理汇总了Python中Darwin.Species.add_instr方法的典型用法代码示例。如果您正苦于以下问题:Python Species.add_instr方法的具体用法?Python Species.add_instr怎么用?Python Species.add_instr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Darwin.Species
的用法示例。
在下文中一共展示了Species.add_instr方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_run1
# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instr [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)
示例2: Species
# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instr [as 别名]
from Darwin import Species, Creature, Darwin
import random
from random import randrange, seed
import sys
# 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')
示例3: test_add_instr1
# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instr [as 别名]
def test_add_instr1(self):
s1 = Species([],'h')
s1.add_instr('go')
self.assertEqual(s1.type,'h')
self.assertEqual(s1.program[0],'go')
示例4: test_next_instr4
# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instr [as 别名]
def test_next_instr4(self):
s1 = Species([],'h')
s1.add_instr('hop3')
self.assertEqual(s1.next_instr(0),'hop3')
示例5: test_add_instr3
# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instr [as 别名]
def test_add_instr3(self):
s1 = Species([],'p')
s1.add_instr('go haha')
self.assertEqual(s1.type,'p')
self.assertEqual(s1.program[0],'go haha')
示例6: test_run3
# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instr [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)
示例7: test_run2
# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instr [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)