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


Python Board.addPiece方法代码示例

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


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

示例1: testSlidePairFatty

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import addPiece [as 别名]
 def testSlidePairFatty(self):
     b = Board(4,3)
     #add a fatty to column 1 and another to column 0
     fat1 = DummyPiece(2,2)
     fat1.name = "fat right"
     fat0 = DummyPiece(2,2)
     fat0.name = "fat left"
     fat0.slidePriority = 0
     fat1.slidePriority = 0
     
     b.addPiece(fat1, 1) #fat right is added first        
     b.addPiece(fat0, 0)        
     self.assertTrue(b.selfConsistent())
     b.normalize()
     
     #fat right (fat1) should be below fat left (fat0)
     self.assertEqual(fat0.position, [2,0])
     self.assertEqual(fat1.position, [0,1])
     self.assertTrue(b.selfConsistent)
     
     ##make fat0 have priority
     logging.debug("priority is about to be changed")
     fat0.slidePriority = 5
     b.normalize()
     
     
     ##fat0 should now be below fat1
     self.assertEqual(fat0.position, [0,0])
     self.assertEqual(fat1.position, [2,1])
     self.assertTrue(b.selfConsistent)
开发者ID:jneem,项目名称:clashadash,代码行数:32,代码来源:test_board.py

示例2: testSlideFatty

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import addPiece [as 别名]
 def testSlideFatty(self):
     b = Board(4, 4)
     #add two small pieces in front of fatty
     piece1 = DummyPiece(1, 1, chargeable = False)
     piece2 = DummyPiece(1, 1, chargeable = False)
     fatpiece = DummyPiece(2, 2, chargeable = False)
     fatpiece.name = "fatty"
     
     b.addPiece(piece1, 0)
     b.addPiece(piece2, 0)
     b.addPiece(fatpiece, 0)        
     b.normalize()
     
     #the two squares (0,1) and (1,1) in front of fatty should be empty        
     self.assertEqual(b[0,1], None)
     self.assertEqual(b[1,1], None)
     #fatty should be at position (2, 0)
     self.assertEqual(fatpiece.position, [2,0])
     self.assertTrue(b.selfConsistent)
     
     #now make fatty slide in front
     fatpiece.slidePriority = 5 
     b.normalize()
     #fatty should occupy the (0,0) position
     self.assertEqual(fatpiece.position,[0,0])
     self.assertTrue(b.selfConsistent)
开发者ID:jneem,项目名称:clashadash,代码行数:28,代码来源:test_board.py

示例3: testAddPiece

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import addPiece [as 别名]
 def testAddPiece(self):
     b = Board(2, 3)
     b.addPiece(DummyPiece(1,1), 1)
     b.addPiece(DummyPiece(1,1), 1)
     
     with self.assertRaises(IndexError):
         b.addPiece(DummyPiece(1,1), 1)
开发者ID:jneem,项目名称:clashadash,代码行数:9,代码来源:test_board.py

示例4: testTransform

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import addPiece [as 别名]
    def testTransform(self):
        b = Board(6, 8)
        pieces = [DummyPiece(1, 1, transformable = True) for c in range(4)]
        for c in range(4):
            b.addPiece(pieces[c], c)

        transformedPieces = []
        def transformHandler(p): transformedPieces.append(p)
        b.wallMade.addHandler(transformHandler)
        b.normalize()

        self.assertEqual(len(transformedPieces[0][0]), 4)
开发者ID:jneem,项目名称:clashadash,代码行数:14,代码来源:test_board.py

示例5: testColToAdd

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import addPiece [as 别名]
    def testColToAdd(self):
        # We create a variety of boards in which there is only one place
        # to add a new piece. Then we check that colToAdd puts the piece
        # in the correct place.
        b = Board(2, 4)
        b.addPiece(DummyPiece(1, 1), 0)
        b.addPiece(DummyPiece(1, 1), 1)
        self.assertEqual(b.colToAdd(DummyPiece(2, 2)), 2)

        b = Board(2, 4)
        b.addPiece(DummyPiece(1, 1), 1)
        self.assertEqual(b.colToAdd(DummyPiece(2, 2)), 2)

        b = Board(2, 4)
        b.addPiece(DummyPiece(1, 1), 2)
        self.assertEqual(b.colToAdd(DummyPiece(2, 2)), 0)

        b.addPiece(DummyPiece(1, 1), 1)
        self.assertEqual(b.colToAdd(DummyPiece(2, 2)), None)
开发者ID:jneem,项目名称:clashadash,代码行数:21,代码来源:test_board.py

示例6: testPieceUpdate

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import addPiece [as 别名]
    def testPieceUpdate(self):
        b = Board(3, 3)
        piece1 = DummyPiece(1, 1)
        piece2 = DummyPiece(1, 1)
        piece3 = DummyPiece(1, 1)
        piece3.slidePriority = 5
        updates = [None]

        def updateHandler(p): updates[0] = p
        b.pieceUpdated.addHandler(updateHandler)

        b.addPiece(piece1, 0)
        b.normalize()
        self.assertEqual(updates[0], set([piece1]))
        b.addPiece(piece2, 1)
        b.normalize()
        self.assertEqual(updates[0], set([piece2]))
        b.addPiece(piece3, 0)
        b.normalize()
        self.assertEqual(updates[0], set([piece1, piece3]))

        b.deletePiece(piece1)
        self.assertEqual(updates[0], set([piece1]))
开发者ID:jneem,项目名称:clashadash,代码行数:25,代码来源:test_board.py


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