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


Python Board.move方法代碼示例

本文整理匯總了Python中chess.board.Board.move方法的典型用法代碼示例。如果您正苦於以下問題:Python Board.move方法的具體用法?Python Board.move怎麽用?Python Board.move使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在chess.board.Board的用法示例。


在下文中一共展示了Board.move方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_players_can_get_out_of_check

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
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,代碼行數:9,代碼來源:test_board.py

示例2: test_player_should_to_get_out_of_check

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
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,代碼行數:9,代碼來源:test_board.py

示例3: test_check_if_player_is_not_in_check_anymore

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
 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,代碼行數:9,代碼來源:test_board.py

示例4: test_pieces_can_capture_opponent_pieces

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
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,代碼行數:10,代碼來源:test_board.py

示例5: test_check_small

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
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,代碼行數:10,代碼來源:test_others.py

示例6: test_castling_left_white

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
 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,代碼行數:11,代碼來源:test_board.py

示例7: test_king_can_do_castling_to_left

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
def test_king_can_do_castling_to_left():
    board = Board(initial_pieces={'e1': King('white'), 'a1': Rook('white')})
    king = board.get_piece('e1')
    rook = board.get_piece('a1')
    board.move('e1', 'c1')
    assert board.get_piece('c1') == king
    assert board.get_piece('d1') == rook
    assert board.get_piece('e1') is None
    assert board.get_piece('a1') is None
開發者ID:deniscostadsc,項目名稱:chess,代碼行數:11,代碼來源:test_king.py

示例8: test_castling_left_black

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
 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,代碼行數:12,代碼來源:test_board.py

示例9: test_king_can_moves

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
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,代碼行數:13,代碼來源:test_king.py

示例10: test_knight_capture

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
    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,代碼行數:13,代碼來源:test_board.py

示例11: test_fail_castling_when_king_already_moved

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
 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,代碼行數:13,代碼來源:test_board.py

示例12: test_board_regular_move

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
    def test_board_regular_move(self):
        board = Board()
        knight = board.squares['g1']
        board.move('g1', 'f3')
        self.assertIs(knight, board.squares['f3'])
        self.assertIsNone(board.squares['g1'])

        board = Board()
        pawn = board.squares['e2']
        board.move('e2', 'e3')
        self.assertIs(pawn, board.squares['e3'])
        self.assertIsNone(board.squares['e2'])
開發者ID:giovaneliberato,項目名稱:chess,代碼行數:14,代碼來源:test_board.py

示例13: test_check_medium

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
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,代碼行數:14,代碼來源:test_others.py

示例14: test_alternating_between_players

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
 def test_alternating_between_players(self):
     board = Board()
     self.assertEqual('white', board.turn)
     board.move('g2', 'g3')  # white pawn moves
     self.assertEqual('black', board.turn)
     board.move('b7', 'b6')  # black pawn moves
     self.assertEqual('white', board.turn)
     board.move('f1', 'g2')  # white bishop moves
     self.assertEqual('black', board.turn)
     board.move('g8', 'f6')  # black knight moves
     self.assertEqual('white', board.turn)
     board.move('g2', 'a8')  # white bishop capture white rook
     self.assertEqual('black', board.turn)
開發者ID:giovaneliberato,項目名稱:chess,代碼行數:15,代碼來源:test_board.py

示例15: test_alternating_between_players

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import move [as 別名]
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,代碼行數:11,代碼來源:test_board.py


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