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


Python Species.add_instruction方法代码示例

本文整理汇总了Python中Darwin.Species.add_instruction方法的典型用法代码示例。如果您正苦于以下问题:Python Species.add_instruction方法的具体用法?Python Species.add_instruction怎么用?Python Species.add_instruction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Darwin.Species的用法示例。


在下文中一共展示了Species.add_instruction方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_species_add_instruction4

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [as 别名]
 def test_species_add_instruction4(self):
     x = Species()
     y = "hop"
     x.add_instruction(y)
     x.add_instruction("YUH sup")
     z = x.program
     self.assertEqual(z, ["hop", "YUH sup"] )
开发者ID:KHJRizen,项目名称:cs313e-darwin,代码行数:9,代码来源:TestDarwin.py

示例2: test_game_1

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [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),[])
开发者ID:ibrahimnagib,项目名称:Darwins-World,代码行数:10,代码来源:TestDarwin.py

示例3: test_darwin_hop1

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [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)
开发者ID:KHJRizen,项目名称:cs313e-darwin,代码行数:13,代码来源:TestDarwin.py

示例4: test_darwin_cycle1

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [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)
开发者ID:KHJRizen,项目名称:cs313e-darwin,代码行数:15,代码来源:TestDarwin.py

示例5: test_species_add_instruction8

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [as 别名]
 def test_species_add_instruction8(self):
     x = Species()
     y = "12356"
     x.add_instruction(y)
     z = x.program
     self.assertEqual(z, ["12356"] )
开发者ID:KHJRizen,项目名称:cs313e-darwin,代码行数:8,代码来源:TestDarwin.py

示例6: test_species_add_instruction7

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [as 别名]
 def test_species_add_instruction7(self):
     x = Species()
     y = "bo343"
     x.add_instruction(y)
     z = x.program
     self.assertEqual(z, ["bo343"] )
开发者ID:KHJRizen,项目名称:cs313e-darwin,代码行数:8,代码来源:TestDarwin.py

示例7: test_species_add_instruction2

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [as 别名]
 def test_species_add_instruction2(self):
     x = Species()
     y = "yo"
     x.add_instruction(y)
     z = x.program
     self.assertEqual(z, ["yo"] )
开发者ID:KHJRizen,项目名称:cs313e-darwin,代码行数:8,代码来源:TestDarwin.py

示例8: test_darwin_take_action4

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [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) 
开发者ID:KHJRizen,项目名称:cs313e-darwin,代码行数:25,代码来源:TestDarwin.py

示例9: test_Species_13

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [as 别名]
 def test_Species_13(self):
     s = Species("food")
     s.add_instruction("infect")
     s.add_instruction("hop")
     self.assertEqual(len(s.instruction_list), 2)
开发者ID:ibrahimnagib,项目名称:Darwins-World,代码行数:7,代码来源:TestDarwin.py

示例10: test_Species_12

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [as 别名]
 def test_Species_12(self):
     best = Species("best")
     best.add_instruction("hop")
     self.assertEqual(len(best.instruction_list), 1)
     best.add_instruction("left")
     self.assertEqual(len(best.instruction_list), 2)
开发者ID:ibrahimnagib,项目名称:Darwins-World,代码行数:8,代码来源:TestDarwin.py

示例11: test_Species_10

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [as 别名]
 def test_Species_10(self):
     s = Species("rover")
     s.add_instruction("hop")
     self.assertEqual(s.instruction_list[0], "hop")
开发者ID:ibrahimnagib,项目名称:Darwins-World,代码行数:6,代码来源:TestDarwin.py

示例12: test_Species_8

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [as 别名]
 def test_Species_8(self):
     s = Species("food")
     s.add_instruction("infect")
     s.add_instruction("hop")
     self.assertEqual(s.name, "food")
开发者ID:ibrahimnagib,项目名称:Darwins-World,代码行数:7,代码来源:TestDarwin.py

示例13: test_Species_7

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [as 别名]
 def test_Species_7(self):
     s = Species("food")
     s.add_instruction("hop")
     self.assertEqual(s.instruction_list, ["hop"])
开发者ID:ibrahimnagib,项目名称:Darwins-World,代码行数:6,代码来源:TestDarwin.py

示例14: main

# 需要导入模块: from Darwin import Species [as 别名]
# 或者: from Darwin.Species import add_instruction [as 别名]
def main():

    # ------
    # hopper
    # ------

    hopper = Species()
    hopper.add_instruction("hop")
    hopper.add_instruction("go 0")

    # ----
    # food
    # ---- 
   
    food = Species()
    food.add_instruction("left")
    food.add_instruction("go 0")
        
    # -----
    # rover
    # -----
    
    rover = Species()
    rover.add_instruction("if_enemy 9")
    rover.add_instruction("if_empty 7")
    rover.add_instruction("if_random 5")
    rover.add_instruction("left")
    rover.add_instruction("go 0")
    rover.add_instruction("right")
    rover.add_instruction("go 0")
    rover.add_instruction("hop")
    rover.add_instruction("go 0")
    rover.add_instruction("infect")
    rover.add_instruction("go 0")

    # ----
    # trap
    # ----
    
    trap = Species()
    trap.add_instruction("if_enemy 3")
    trap.add_instruction("left")
    trap.add_instruction("go 0")
    trap.add_instruction("infect")
    trap.add_instruction("go 0")
      

    # ----
    # best
    # ----

    best = Species()
    best.add_instruction("if_wall 4")
    best.add_instruction("if_enemy 6")
    best.add_instruction("hop")
    best.add_instruction("go 0")
    best.add_instruction("left")
    best.add_instruction("go 0")
    best.add_instruction("infect")
    best.add_instruction("go 0")
    
    
    # ----
    # darwin8x8()
    # ----
    
    print("*** Darwin 8x8 ***")
    grid = Darwin(8, 8)
      
    f1 = Creature(food, "f", 1, 0, 0)
    h1 = Creature(hopper, "h", 0, 3, 3)
    h2 = Creature(hopper, "h", 1, 3, 4)
    h3 = Creature(hopper, "h", 2, 4, 4)
    h4 = Creature(hopper, "h", 3, 4, 3)
    f2 = Creature(food, "f", 0, 7, 7)
        
    grid.add_creature(f1)
    grid.add_creature(f2)
    grid.add_creature(h1)
    grid.add_creature(h2)
    grid.add_creature(h3)
    grid.add_creature(h4)
    
    for i in range(6):
        #printed which turn it is
        print("Turn = " + str(i))
        grid.print_grid()
        grid.cycle()
        print()
    
    
    # ----
    # darwin7x9
    # ----
    
    print("*** Darwin 7x9 ***")
    grid = Darwin(7, 9)
    seed(0);
    
    t1 = Creature(trap, "t", 2, 0, 0)
#.........这里部分代码省略.........
开发者ID:KHJRizen,项目名称:cs313e-darwin,代码行数:103,代码来源:RunDarwin.py


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