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


Python Board.convert_pos_to_array方法代码示例

本文整理汇总了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))
开发者ID:rmathure,项目名称:HumbleBumble,代码行数:35,代码来源:test_board.py

示例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)
开发者ID:rmathure,项目名称:HumbleBumble,代码行数:12,代码来源:test_pawn.py


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