本文整理汇总了Python中Darwin.Darwin.run方法的典型用法代码示例。如果您正苦于以下问题:Python Darwin.run方法的具体用法?Python Darwin.run怎么用?Python Darwin.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Darwin.Darwin
的用法示例。
在下文中一共展示了Darwin.run方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_run1
# 需要导入模块: from Darwin import Darwin [as 别名]
# 或者: from Darwin.Darwin import run [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: test_game_1
# 需要导入模块: from Darwin import Darwin [as 别名]
# 或者: from Darwin.Darwin import run [as 别名]
def test_game_1(self):
game = Darwin(4,4)
food = Species("food")
food.add_instruction("right")
food.add_instruction("go 0")
f1 = Creature(food)
game.place_creature(f1,2,2, "north")
self.assertNotEqual(game.run(4),[])
示例3: test_run2
# 需要导入模块: from Darwin import Darwin [as 别名]
# 或者: from Darwin.Darwin import run [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)
示例4: test_run3
# 需要导入模块: from Darwin import Darwin [as 别名]
# 或者: from Darwin.Darwin import run [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)
示例5: print
# 需要导入模块: from Darwin import Darwin [as 别名]
# 或者: from Darwin.Darwin import run [as 别名]
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)
g2.add_creature(t1, 0, 0)
g2.add_creature(h1, 3, 2)
g2.add_creature(r1, 5, 4)
g2.add_creature(t2, 6, 8)
g2.run(5)