本文整理汇总了Python中Darwin.Darwin.cycle方法的典型用法代码示例。如果您正苦于以下问题:Python Darwin.cycle方法的具体用法?Python Darwin.cycle怎么用?Python Darwin.cycle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Darwin.Darwin
的用法示例。
在下文中一共展示了Darwin.cycle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_darwin_hop1
# 需要导入模块: from Darwin import Darwin [as 别名]
# 或者: from Darwin.Darwin import cycle [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)
示例2: test_darwin_cycle1
# 需要导入模块: from Darwin import Darwin [as 别名]
# 或者: from Darwin.Darwin import cycle [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)
示例3: test_darwin_take_action4
# 需要导入模块: from Darwin import Darwin [as 别名]
# 或者: from Darwin.Darwin import cycle [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)
示例4: main
# 需要导入模块: from Darwin import Darwin [as 别名]
# 或者: from Darwin.Darwin import cycle [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)
#.........这里部分代码省略.........