當前位置: 首頁>>代碼示例>>Python>>正文


Python board.Board類代碼示例

本文整理匯總了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')
開發者ID:deniscostadsc,項目名稱:chess,代碼行數:7,代碼來源:test_board.py

示例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)
開發者ID:giovaneliberato,項目名稱:chess,代碼行數:7,代碼來源:test_board.py

示例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
開發者ID:deniscostadsc,項目名稱:chess,代碼行數:7,代碼來源:test_board.py

示例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'])
開發者ID:giovaneliberato,項目名稱:chess,代碼行數:9,代碼來源:test_board.py

示例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
開發者ID:adamchalmers,項目名稱:pychess,代碼行數:9,代碼來源:test_others.py

示例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'])
開發者ID:giovaneliberato,項目名稱:chess,代碼行數:10,代碼來源:test_board.py

示例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
開發者ID:deniscostadsc,項目名稱:chess,代碼行數:11,代碼來源:test_king.py

示例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')
開發者ID:giovaneliberato,項目名稱:chess,代碼行數:11,代碼來源:test_board.py

示例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))
開發者ID:giovaneliberato,項目名稱:chess,代碼行數:11,代碼來源:test_board.py

示例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()
開發者ID:jqadrad,項目名稱:chess,代碼行數:18,代碼來源:__main__.py

示例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
開發者ID:deniscostadsc,項目名稱:chess,代碼行數:8,代碼來源:test_board.py

示例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)
開發者ID:rmathure,項目名稱:HumbleBumble,代碼行數:10,代碼來源:test_pawn.py

示例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'
開發者ID:deniscostadsc,項目名稱:chess,代碼行數:9,代碼來源:test_board.py

示例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)
開發者ID:adamchalmers,項目名稱:pychess,代碼行數:8,代碼來源:test_others.py

示例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)
開發者ID:adamchalmers,項目名稱:pychess,代碼行數:12,代碼來源:test_others.py


注:本文中的chess.board.Board類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。