本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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]))