当前位置: 首页>>代码示例>>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;未经允许,请勿转载。