本文整理汇总了Python中board.Board.add方法的典型用法代码示例。如果您正苦于以下问题:Python Board.add方法的具体用法?Python Board.add怎么用?Python Board.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类board.Board
的用法示例。
在下文中一共展示了Board.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_check
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_is_check(self):
board = Board(6, 6)
p_king_white = Piece (Piece.KING, Piece.WHITE)
board.add(p_king_white, 0, 2)
p_queen_black = Piece (Piece.QUEEN, Piece.BLACK)
board.add(p_queen_black, 2, 4)
self.assertTrue(board.is_check_for_enemy(Piece.WHITE))
示例2: create_board_from_str
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def create_board_from_str(board_str, empty_location_str='-'):
"""
:param board_str: str representing desired board configuration
:return: Board
"""
# Remove spaces
board_str = board_str.replace(' ', '')
# Split by lines
board_rows = board_str.split('\n')
# Remove empty lines
board_rows = [row for row in board_rows if row]
board = Board(len(board_rows))
for r, row in enumerate(board_rows):
for c, piece_color_str in enumerate(row):
if piece_color_str == empty_location_str: continue
color = piece_str_to_color(piece_color_str)
board.add(color=color, position=(r,c))
return board
示例3: test_is_check_only_two_kings
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_is_check_only_two_kings(self):
board = Board(4, 4)
p_king_black = Piece(Piece.KING, Piece.BLACK)
p_king_white = Piece(Piece.KING, Piece.WHITE)
board.add(p_king_black, 0, 0)
board.add(p_king_white, 0, 1)
self.assertTrue(board.is_check_for_enemy(Piece.WHITE))
self.assertTrue(board.is_check_for_enemy(Piece.BLACK))
示例4: test_is_legal_movement_queen
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_is_legal_movement_queen(self):
board = Board(6, 6)
piece_king_white = Piece(Piece.KING, Piece.WHITE)
piece_queen_black = Piece(Piece.QUEEN, Piece.BLACK)
board.add(piece_king_white, 0, 2)
board.add(piece_queen_black, 3, 3)
available_positions = [[3, 2], [2, 3], [1, 3], [0, 3], [2, 2], [1, 1], [0, 0], [2, 4]]
self.assertEqual(board.is_legal_movement(3, 3), available_positions)
示例5: test_is_legal_movement_king
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_is_legal_movement_king(self):
board = Board(20, 20)
piece_king_white = Piece(Piece.KING, Piece.WHITE)
piece_king_black = Piece(Piece.KING, Piece.BLACK)
board.add(piece_king_white, 10, 10)
board.add(piece_king_black, 15, 10)
available_positions = [[11, 11], [11, 10], [11, 9]]
self.assertEqual(board.is_legal_movement(10, 10).sort(), available_positions.sort())
示例6: test_is_legal_movement_rook_left
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_is_legal_movement_rook_left(self):
board = Board (20, 20)
piece_king_white = Piece(Piece.KING, Piece.WHITE)
piece_rook_black = Piece(Piece.ROOK, Piece.BLACK)
board.add(piece_king_white, 15, 7)
board.add(piece_rook_black, 15, 10)
available_positions = [[15, 9], [15, 8], [15, 7]]
self.assertEqual(board.is_legal_movement(15, 10), available_positions)
示例7: test_is_check_but_not_terminal
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_is_check_but_not_terminal(self):
board = Board(4, 4)
p_king_black = Piece(Piece.KING, Piece.BLACK)
p_king_white = Piece(Piece.KING, Piece.WHITE)
board.add(p_king_black, 0, 0)
board.add(p_king_white, 0, 1)
player_one = Player(Player.HUMAN, Piece.WHITE)
player_two = Player(Player.HUMAN, Piece.BLACK)
g_game = Game(player_one, player_two)
self.assertFalse(g_game.is_terminal(board))
示例8: test_another_is_legal_movement_rook_up
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_another_is_legal_movement_rook_up(self):
board = Board(6, 6)
piece_king_white = Piece(Piece.KING, Piece.WHITE)
piece_rook_black = Piece(Piece.ROOK, Piece.BLACK)
piece_pawn_black = Piece(Piece.PAWN, Piece.BLACK)
board.add(piece_king_white, 0, 2)
board.add(piece_rook_black, 3, 3)
board.add(piece_pawn_black, 3, 2)
available_positions = [[2, 3], [1, 3], [0, 3]]
self.assertEqual(board.is_legal_movement(3, 3), available_positions)
示例9: test_is_legal_movement_rook_all
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_is_legal_movement_rook_all(self):
board = Board (20, 20)
piece_king_white = Piece(Piece.KING, Piece.WHITE)
piece_rook_black = Piece(Piece.ROOK, Piece.BLACK)
piece_pawn_black = Piece(Piece.PAWN, Piece.BLACK)
board.add(piece_king_white, 12, 8)
board.add(piece_rook_black, 18, 10)
board.add(piece_pawn_black, 17, 10)
available_positions = [[18, 9], [18, 8], [18, 7]]
self.assertEqual(board.is_legal_movement(18, 10), available_positions)
示例10: test_utility_is_inf_black
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_utility_is_inf_black(self):
board = Board(4, 4)
p_king_black = Piece(Piece.KING, Piece.BLACK)
p_king_white = Piece(Piece.KING, Piece.WHITE)
board.add(p_king_black, 0, 0)
board.add(p_king_white, 0, 1)
player_one = Player(Player.IDIOT, Piece.WHITE)
player_two = Player(Player.IDIOT, Piece.BLACK)
g_game = Game(player_one, player_two)
inf = 99999999
self.assertEqual(inf, g_game.utility(board, player_two))
示例11: test_move_a_pawn
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_move_a_pawn(self):
board = Board(6, 6)
piece_pawn_black = Piece(Piece.PAWN, Piece.BLACK)
piece_pawn_white = Piece(Piece.PAWN, Piece.WHITE)
board.add(piece_pawn_black, 3, 3)
board.add(piece_pawn_white, 4, 3)
self.assertFalse(board.move_piece(3,3,4,3))
self.assertEqual(board.get_piece_in_pos(3,3), piece_pawn_black)
self.assertFalse(board.move_piece(4,3,3,3))
self.assertEqual(board.get_piece_in_pos(4,3), piece_pawn_white)
示例12: test_add_pieces_to_board
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_add_pieces_to_board(self):
piece_one = Piece(Piece.PAWN, Piece.BLACK)
piece_two = Piece(Piece.PAWN, Piece.BLACK)
piece_three = Piece(Piece.PAWN, Piece.WHITE)
piece_four = Piece(Piece.PAWN, Piece.WHITE)
board = Board(6, 4)
pieces = [piece_one,piece_two,piece_three,piece_four]
self.assertTrue(board.add(piece_one, 3, 2))
self.assertTrue(board.add(piece_two, 4, 1))
self.assertFalse(board.add(piece_three, 6, 4))
self.assertFalse(board.add(piece_four, 7, 0))
示例13: test_is_legal_movement_bishop_left_down
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_is_legal_movement_bishop_left_down(self):
board = Board (20, 20)
piece_king_white = Piece(Piece.KING, Piece.WHITE)
piece_bishop_black = Piece(Piece.BISHOP, Piece.BLACK)
piece_pawn_black = Piece(Piece.PAWN, Piece.BLACK)
piece_pawn_black_two = Piece(Piece.PAWN, Piece.BLACK)
piece_pawn_black_three = Piece(Piece.PAWN, Piece.BLACK)
board.add(piece_king_white, 19, 8)
board.add(piece_bishop_black, 18, 10)
board.add(piece_pawn_black, 17, 9)
board.add(piece_pawn_black_two, 16 , 11)
board.add(piece_pawn_black_three, 17 , 11)
available_positions = [[19, 9]]
self.assertEqual(board.is_legal_movement(18, 10), available_positions)
示例14: test_utility_in_random_board_should_be_zero
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_utility_in_random_board_should_be_zero(self):
board = Board(4, 4)
p_king_black = Piece(Piece.KING, Piece.BLACK)
p_rook_black = Piece(Piece.ROOK, Piece.BLACK)
p_rook_white = Piece(Piece.ROOK, Piece.WHITE)
p_king_white = Piece(Piece.KING, Piece.WHITE)
board.add(p_king_black, 0, 0)
board.add(p_rook_black, 2, 0)
board.add(p_rook_white, 1, 1)
board.add(p_king_white, 0, 2)
player_one = Player(Player.IDIOT, Piece.WHITE)
player_two = Player(Player.IDIOT, Piece.BLACK)
g_game = Game(player_one, player_two)
self.assertEqual(0, g_game.utility(board, player_one))
示例15: test_is_legal_movement_bishop_rigth_up
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add [as 别名]
def test_is_legal_movement_bishop_rigth_up(self):
board = Board (20, 20)
piece_king_white = Piece(Piece.KING, Piece.WHITE)
piece_bishop_black = Piece(Piece.BISHOP, Piece.BLACK)
piece_pawn_black = Piece(Piece.PAWN, Piece.BLACK)
piece_pawn_black_two = Piece(Piece.PAWN, Piece.BLACK)
piece_pawn_black_three = Piece(Piece.PAWN, Piece.BLACK)
board.add(piece_king_white, 15, 13)
board.add(piece_bishop_black, 18, 10)
board.add(piece_pawn_black, 17, 19)
board.add(piece_pawn_black_two, 14 , 14)
available_positions = [[17, 11],[16, 12], [15, 13]]
self.assertEqual(board.is_legal_movement(18, 10), available_positions)