当前位置: 首页>>代码示例>>Python>>正文


Python Species.add_instr方法代码示例

本文整理汇总了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)
开发者ID:JiannanZhang,项目名称:Darwin-World,代码行数:28,代码来源:TestDarwin.py

示例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')
开发者ID:JiannanZhang,项目名称:Darwin-World,代码行数:33,代码来源:RunDarwin.py

示例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')
开发者ID:JiannanZhang,项目名称:Darwin-World,代码行数:7,代码来源:TestDarwin.py

示例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')
开发者ID:JiannanZhang,项目名称:Darwin-World,代码行数:6,代码来源:TestDarwin.py

示例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')
开发者ID:JiannanZhang,项目名称:Darwin-World,代码行数:7,代码来源:TestDarwin.py

示例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)
开发者ID:JiannanZhang,项目名称:Darwin-World,代码行数:44,代码来源:TestDarwin.py

示例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)
开发者ID:JiannanZhang,项目名称:Darwin-World,代码行数:47,代码来源:TestDarwin.py


注:本文中的Darwin.Species.add_instr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。