本文整理汇总了Python中chess.board.Board类的典型用法代码示例。如果您正苦于以下问题:Python Board类的具体用法?Python Board怎么用?Python Board使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Board类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_player_should_to_get_out_of_check
def test_player_should_to_get_out_of_check():
board = Board({'e1': King('black'), 'f8': Rook('white'), 'a1': King('white')})
assert board.check is None
board.move('f8', 'e8')
assert board.check == 'black'
with pytest.raises(ImpossibleMove):
board.move('e1', 'e2')
示例2: test_check_if_player_is_not_in_check_anymore
def test_check_if_player_is_not_in_check_anymore(self):
board = Board({'e1': King('black'), 'f8': Rook('white'), 'a1': King('white')})
self.assertIsNone(board.check)
board.move('f8', 'e8')
self.assertEqual('black', board.check)
board.move('e1', 'f1')
self.assertIsNone(board.check)
示例3: test_players_can_get_out_of_check
def test_players_can_get_out_of_check():
board = Board({'e1': King('black'), 'f8': Rook('white'), 'a1': King('white')})
assert board.check is None
board.move('f8', 'e8')
assert board.check == 'black'
board.move('e1', 'f1')
assert board.check is None
示例4: test_castling_left_white
def test_castling_left_white(self):
board = Board(initial_pieces={'e1': King('white'), 'a1': Rook('white')})
king = board.squares['e1']
rook = board.squares['a1']
board.move('e1', 'c1')
self.assertIs(king, board.squares['c1'])
self.assertIs(rook, board.squares['d1'])
self.assertIsNone(board.squares['e1'])
self.assertIsNone(board.squares['a1'])
示例5: test_copy
def test_copy():
board = Board()
king = King(BLACK, 0, 0)
rook = Rook(WHITE, 2, 2)
board._pieces = {king, rook}
clone = board.copy()
assert len(clone._pieces) == len(board._pieces)
for piece in clone._pieces:
assert piece not in board._pieces
示例6: test_castling_left_black
def test_castling_left_black(self):
board = Board(initial_pieces={'a2': Pawn('white'), 'e8': King('black'), 'a8': Rook('black')})
king = board.squares['e8']
rook = board.squares['a8']
board.move('a2', 'a3') # just because white have to move first
board.move('e8', 'c8')
self.assertIs(king, board.squares['c8'])
self.assertIs(rook, board.squares['d8'])
self.assertIsNone(board.squares['e8'])
self.assertIsNone(board.squares['a8'])
示例7: test_king_can_moves
def test_king_can_moves():
king = King('white')
#
# I have to pass a second king because the board look for a second
# king when you set the first one. Maybe a have to add an attribute
# to the board class to say wether the match is tutorial or not.
#
board = Board(initial_pieces={'f5': king, 'h1': King('black')})
board.move('f5', 'e5')
assert board.get_piece('e5') is king
assert board.get_piece('f5') is None
示例8: test_fail_castling_when_king_already_moved
def test_fail_castling_when_king_already_moved(self):
board = Board(initial_pieces={
'a8': King('black'),
'a7': Pawn('black'),
'e1': King('white'),
'h1': Rook('white')})
board.move('e1', 'f1')
board.move('a7', 'a6') # pawn moves
board.move('f1', 'e1')
board.move('a6', 'a5') # pawn moves
self.assertRaises(ImpossibleMove, board.move, 'e1', 'g1')
示例9: test_knight_capture
def test_knight_capture(self):
board = Board(initial_pieces={'a8': King('black'), 'e5': Pawn('black'), 'f3': Knight('white')})
pieces = [piece for piece in board.squares.values() if piece is not None]
self.assertEqual(3, len(pieces))
knight = board.squares['f3']
board.move('f3', 'e5')
self.assertIs(knight, board.squares['e5'])
pieces = [piece for piece in board.squares.values() if piece is not None]
self.assertEqual(2, len(pieces))
示例10: assignment
def assignment():
""" Assignment """
board = Board(5, 5)
pieces = {}
pieces['king'] = 2
pieces['queen'] = 2
pieces['bishop'] = 2
pieces['rook'] = 0
pieces['knight'] = 1
start = datetime.datetime.now()
print 'Start', start
board.set_pieces(pieces)
board.put_pieces()
end = datetime.datetime.now()
print 'End', end
print 'Duration', end-start
print 'Found '+str(len(board.solutions))+ ' solutions'
exit()
示例11: test_pieces_can_capture_opponent_pieces
def test_pieces_can_capture_opponent_pieces():
board = Board(initial_pieces={'a8': King('black'), 'e5': Pawn('black'), 'f3': Knight('white')})
assert board.pieces_quantity() == 3
knight = board.get_piece('f3')
board.move('f3', 'e5')
assert board.get_piece('e5') is knight
assert board.pieces_quantity() == 2
示例12: TestPawnInit
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)
示例13: test_alternating_between_players
def test_alternating_between_players():
board = Board()
assert board.turn == 'white'
board.move('g2', 'g3') # white pawn moves
assert board.turn == 'black'
board.move('b7', 'b6') # black pawn moves
assert board.turn == 'white'
board.move('f1', 'g2') # white bishop moves
assert board.turn == 'black'
示例14: test_check_small
def test_check_small():
board = Board()
king = King(BLACK, 0, 0)
rook = Rook(WHITE, 2, 2)
board._pieces = {king, rook}
assert not board.checked(BLACK)
board.move(rook, 2, 0)
assert board.checked(BLACK)
示例15: test_check_medium
def test_check_medium():
board = Board()
king = King(BLACK, 0, 0)
rook = Rook(WHITE, 2, 2)
pawn = Pawn(WHITE, 7, 3)
bishop = Bishop(WHITE, 1, 3)
enemy_king = King(WHITE, 6, 6)
board._pieces = {king, rook, pawn, bishop, enemy_king}
assert not board.checked(BLACK)
board.move(rook, 2, 0)
assert board.checked(BLACK)
assert not board.checked(WHITE)