本文整理汇总了Python中chess.board.Board.convert_pos_to_array方法的典型用法代码示例。如果您正苦于以下问题:Python Board.convert_pos_to_array方法的具体用法?Python Board.convert_pos_to_array怎么用?Python Board.convert_pos_to_array使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chess.board.Board
的用法示例。
在下文中一共展示了Board.convert_pos_to_array方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestBoard
# 需要导入模块: from chess.board import Board [as 别名]
# 或者: from chess.board.Board import convert_pos_to_array [as 别名]
class TestBoard(unittest.TestCase):
def setUp(self):
self.board = Board()
def test_init(self):
self.assertEqual(self.board.__board__, [[None for x in range(8)] for y in range(8)])
def test_convert_pos_to_array(self):
posx, posy = self.board.convert_pos_to_array('c', 5)
self.assertEqual(posx, 2)
self.assertEqual(posy, 4)
posx, posy = self.board.convert_pos_to_array('h', 1)
self.assertEqual(posx, 7)
self.assertEqual(posy, 0)
self.assertRaises(InvalidInputException, lambda: self.board.convert_pos_to_array('i', 1))
self.assertRaises(InvalidInputException, lambda: self.board.convert_pos_to_array('a', 9))
self.assertRaises(InvalidInputException, lambda: self.board.convert_pos_to_array('a', -1))
self.assertRaises(InvalidInputException, lambda: self.board.convert_pos_to_array('a', 0))
self.assertRaises(InvalidInputException, lambda: self.board.convert_pos_to_array('i', 0))
def test_convert_array_to_pos(self):
self.assertEqual(self.board.convert_array_to_pos(2, 3), '<C:4>')
self.assertRaises(InvalidInputException, lambda: self.board.convert_array_to_pos(0, 8))
self.assertRaises(InvalidInputException, lambda: self.board.convert_array_to_pos(-1, 8))
self.assertRaises(InvalidInputException, lambda: self.board.convert_array_to_pos(-1, 9))
def test_get_piece_at(self):
self.board.__board__[1][2] = 1
self.assertIsNone(self.board.get_pieceAt(0,0))
self.assertIsNotNone(self.board.get_pieceAt(1,2))
self.assertIsNone(self.board.get_pieceAt(-1, 0))
self.assertIsNone(self.board.get_pieceAt(1, 9))
示例2: TestPawnInit
# 需要导入模块: from chess.board import Board [as 别名]
# 或者: from chess.board.Board import convert_pos_to_array [as 别名]
class TestPawnInit(unittest.TestCase):
def setUp(self):
self.board = Board()
def test_init_pawn(self):
pawn = Pawn(self.board, 'c', '5', 'white')
posx, posy = self.board.convert_pos_to_array('c', 5)
self.assertIsNotNone(self.board.__board__[posx][posy])
self.assertTrue(pawn in self.board.white_set)
self.assertFalse(pawn in self.board.black_set)