本文整理匯總了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)