當前位置: 首頁>>代碼示例>>Python>>正文


Python Darwin.add方法代碼示例

本文整理匯總了Python中Darwin.Darwin.add方法的典型用法代碼示例。如果您正苦於以下問題:Python Darwin.add方法的具體用法?Python Darwin.add怎麽用?Python Darwin.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Darwin.Darwin的用法示例。


在下文中一共展示了Darwin.add方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_darwin8

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_darwin8(self):
   d = Darwin(2,2)
   s = Species('dog')
   c = Creature(s,'south')
   d.add(c,0,1)
   d.go(0,0)
   self.assertEqual(str(d),'  01\n0 .d\n1 ..\n')
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:9,代碼來源:TestDarwin.py

示例2: test_darwin21

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_darwin21(self):
   d = Darwin(1,2)
   s = Species('cat')
   s.addInstruction('infect')
   c = Creature(s,'east')
   d.add(c,0,0)
   d.go(0,0)
   self.assertEqual(str(d), '  01\n0 c.\n')
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:10,代碼來源:TestDarwin.py

示例3: test_darwin19

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_darwin19(self):
   d = Darwin(1,2)
   s = Species('cat')
   s.addInstruction('hop')
   c = Creature(s,'east')
   d.add(c,0,0)
   d.go(0,0)
   self.assertEqual(False,d.isEnemy())  
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:10,代碼來源:TestDarwin.py

示例4: test_darwin16

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_darwin16(self):
   d = Darwin(1,2)
   s = Species('cat')
   s.addInstruction('infect')
   c = Creature(s,'east')
   d.add(c,0,0)
   d.go(0,0)
   self.assertEqual(False,d.isWall())
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:10,代碼來源:TestDarwin.py

示例5: test_darwin10

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_darwin10(self):
   d = Darwin(1,2)
   s = Species('cat')
   s.addInstruction('hop')
   c = Creature(s, 'east')
   d.add(c,0,0)
   d.turn()
   self.assertEqual(str(d),'  01\n0 .c\n')
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:10,代碼來源:TestDarwin.py

示例6: test_darwin9

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_darwin9(self):
   d = Darwin(1,2)
   s = Species('cat')
   s.addInstruction('hop')
   c = Creature(s, 'east')
   d.add(c,0,0)
   d.turn()
   self.assertEqual(d.turns, 1)    
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:10,代碼來源:TestDarwin.py

示例7: test_darwin7

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_darwin7(self):
   d = Darwin(2,2)
   s = Species('dog')
   s.addInstruction('hop')
   c = Creature(s,'north')
   d.add(c,0,1)
   d.go(0,1)
   self.assertEqual(str(d),'  01\n0 .d\n1 ..\n')
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:10,代碼來源:TestDarwin.py

示例8: test_darwin3

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_darwin3(self):  
   d = Darwin(1,3)
   s = Species('cat')
   c1 = Creature(s,'south')
   c2 = Creature(s,'south')
   c3 = Creature(s,'south')
   d.add(c1,0,0)
   self.assertEqual(str(d),'  012\n0 c..\n')
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:10,代碼來源:TestDarwin.py

示例9: test_creature7

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_creature7(self):
   d = Darwin(1,2)
   s = Species('cat')
   s.addInstruction('infect')
   c = Creature(s,'south')
   d.add(c,0,0)
   d.go(0,0)
   
   c.left()
   self.assertEqual('east', c.direction)  
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:12,代碼來源:TestDarwin.py

示例10: test_darwin23

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_darwin23(self):
   d = Darwin(1,2)
   s = Species('cat')
   s.addInstruction('infect')
   c = Creature(s,'east')
   d.add(c,0,0)
   c1 = Creature(s,'east')
   d.add(c,1,0)
   d.go(0,0)
   assert c != c1
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:12,代碼來源:TestDarwin.py

示例11: test_creature12

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_creature12(self):
   d = Darwin(1,2)
   s = Species('cat')
   s.addInstruction('infect')
   c = Creature(s,'west')
   d.add(c,0,0)
   d.go(0,0)
   
   c.right()
   self.assertEqual('north',c.direction)
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:12,代碼來源:TestDarwin.py

示例12: test_darwin20

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_darwin20(self):
   d = Darwin(1,2)
   s = Species('cat')
   s.addInstruction('hop')
   s1 = Species('dog')
   s1.addInstruction('hop')
   c = Creature(s,'east')
   c1 = Creature(s1,'east')
   d.add(c,0,0)
   d.add(c1,0,1)
   d.go(0,0)
   self.assertEqual(True,d.isEnemy()) 
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:14,代碼來源:TestDarwin.py

示例13: test_creature18

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
 def test_creature18(self):
   s = Species('dog')
   c = Creature(s,'east')
   s.addInstruction('hop')
   s.addInstruction('if_enemy 2')
   s.addInstruction('if_empty 3')
   s.addInstruction('if_random 4')
   s.addInstruction('go 0')
   d = Darwin(2,2)
   d.add(c,0,0)
   d.go(0,0)
   cmd = c.execute()
   self.assertEqual(cmd, 'hop')
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:15,代碼來源:TestDarwin.py

示例14: print

# 需要導入模塊: from Darwin import Darwin [as 別名]
# 或者: from Darwin.Darwin import add [as 別名]
r.addInstruction('if_random 5')
r.addInstruction('left')
r.addInstruction('go 0')
r.addInstruction('right')
r.addInstruction('go 0')
r.addInstruction('hop')
r.addInstruction('go 0')
r.addInstruction('infect')
r.addInstruction('go 0')


print('*** Darwin 8x8 ***')
seed(0)
d = Darwin(8,8)
c1 = Creature(f,'east')
d.add(c1,0,0)
c2 = Creature(h,'north')
d.add(c2,3,3)
d.add(Creature(h,'east'),3,4)
d.add(Creature(h,'south'),4,4)
d.add(Creature(h,'west'),4,3)
d.add(Creature(f,'north'),7,7)

for i in range(6):
  print('Turn = ' + str(d.turns) + '.')
  print(d)
  d.turn()

print('*** Darwin 7x9 ***')
seed(0)
開發者ID:jjloftin,項目名稱:cs313e-darwin,代碼行數:32,代碼來源:RunDarwin.py


注:本文中的Darwin.Darwin.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。