本文整理匯總了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)
#.........這裏部分代碼省略.........