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


Python board.Board方法代碼示例

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


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

示例1: minimax

# 需要導入模塊: import board [as 別名]
# 或者: from board import Board [as 別名]
def minimax(board: Board, maximizing: bool, original_player: Piece, max_depth: int = 8) -> float:
    # Base case – terminal position or maximum depth reached
    if board.is_win or board.is_draw or max_depth == 0:
        return board.evaluate(original_player)

    # Recursive case - maximize your gains or minimize the opponent's gains
    if maximizing:
        best_eval: float = float("-inf") # arbitrarily low starting point
        for move in board.legal_moves:
            result: float = minimax(board.move(move), False, original_player, max_depth - 1)
            best_eval = max(result, best_eval) # we want the move with the highest evaluation
        return best_eval
    else: # minimizing
        worst_eval: float = float("inf")
        for move in board.legal_moves:
            result = minimax(board.move(move), True, original_player, max_depth - 1)
            worst_eval = min(result, worst_eval) # we want the move with the lowest evaluation
        return worst_eval 
開發者ID:davecom,項目名稱:ClassicComputerScienceProblemsInPython,代碼行數:20,代碼來源:minimax.py

示例2: alphabeta

# 需要導入模塊: import board [as 別名]
# 或者: from board import Board [as 別名]
def alphabeta(board: Board, maximizing: bool, original_player: Piece, max_depth: int = 8, alpha: float = float("-inf"), beta: float = float("inf")) -> float:
    # Base case – terminal position or maximum depth reached
    if board.is_win or board.is_draw or max_depth == 0:
        return board.evaluate(original_player)

    # Recursive case - maximize your gains or minimize the opponent's gains
    if maximizing:
        for move in board.legal_moves:
            result: float = alphabeta(board.move(move), False, original_player, max_depth - 1, alpha, beta)
            alpha = max(result, alpha)
            if beta <= alpha:
                break
        return alpha
    else:  # minimizing
        for move in board.legal_moves:
            result = alphabeta(board.move(move), True, original_player, max_depth - 1, alpha, beta)
            beta = min(result, beta)
            if beta <= alpha:
                break
        return beta


# Find the best possible move in the current position
# looking up to max_depth ahead 
開發者ID:davecom,項目名稱:ClassicComputerScienceProblemsInPython,代碼行數:26,代碼來源:minimax.py

示例3: move

# 需要導入模塊: import board [as 別名]
# 或者: from board import Board [as 別名]
def move(self, location: Move) -> Board:
        temp_position: List[TTTPiece] = self.position.copy()
        temp_position[location] = self._turn
        return TTTBoard(temp_position, self._turn.opposite) 
開發者ID:davecom,項目名稱:ClassicComputerScienceProblemsInPython,代碼行數:6,代碼來源:tictactoe.py

示例4: move

# 需要導入模塊: import board [as 別名]
# 或者: from board import Board [as 別名]
def move(self, location: Move) -> Board:
        temp_position: List[C4Board.Column] = self.position.copy()
        for c in range(C4Board.NUM_COLUMNS):
            temp_position[c] = self.position[c].copy()
        temp_position[location].push(self._turn)
        return C4Board(temp_position, self._turn.opposite) 
開發者ID:davecom,項目名稱:ClassicComputerScienceProblemsInPython,代碼行數:8,代碼來源:connectfour.py

示例5: find_best_move

# 需要導入模塊: import board [as 別名]
# 或者: from board import Board [as 別名]
def find_best_move(board: Board, max_depth: int = 8) -> Move:
    best_eval: float = float("-inf")
    best_move: Move = Move(-1)
    for move in board.legal_moves:
        result: float = alphabeta(board.move(move), False, board.turn, max_depth)
        if result > best_eval:
            best_eval = result
            best_move = move
    return best_move 
開發者ID:davecom,項目名稱:ClassicComputerScienceProblemsInPython,代碼行數:11,代碼來源:minimax.py

示例6: __init__

# 需要導入模塊: import board [as 別名]
# 或者: from board import Board [as 別名]
def __init__(self, fen=default_fen, validate=True):
        """
        Initialize the game board to the supplied FEN state (or the default
        starting state if none is supplied), and determine whether to check
        the validity of moves returned by `get_moves()`.
        """
        self.board = Board()
        self.state = State(' ', ' ', ' ', ' ', ' ')
        self.move_history = []
        self.fen_history = []
        self.validate = validate
        self.set_fen(fen=fen) 
開發者ID:lamesjim,項目名稱:Chess-AI,代碼行數:14,代碼來源:game.py

示例7: main

# 需要導入模塊: import board [as 別名]
# 或者: from board import Board [as 別名]
def main(argv):
   actions = {}
   actions["train"] = main_train
   actions["show_tiles"] = main_show_tiles
   actions["dev"] = main_dev


   parser = argparse.ArgumentParser(description='A chess OCR application.')
   parser.add_argument('filenames', metavar='filename', type=str, nargs='+',
                       help='The files to process.')

   parser.add_argument('-e', dest='extract_boards', action='store_const',
                       const=True, default=False,
                       help='extract boards from images (default: use image as-is)')

   parser.add_argument('-a', dest='action', default="show_tiles",
                       choices=["train", "show_tiles", "dev"],
                       help='action to perform (default: show_tiles)')

   args = parser.parse_args()

   action = actions[args.action]



   for filename in args.filenames:
      image = cv2.imread(filename)
      print("---- %s ----" % filename)

      if args.extract_boards:
         print("Extracting Boards")
         boards = extractBoards(image, extract_width, extract_height)
      else:
         boards = [image]

      for b in boards:
         print("Extracting Grid")
         grid = extractGrid(b, 9, 9)

         print(grid)
         if grid is None:
            print("Could not find Grid")
            continue

         print("Extracting Tiles")
         tiles = extractTiles(b, grid, 100, 100)

         b = Board(tiles, 8, 8)

         print("Running action")
         action(b, args) 
開發者ID:nebbles,項目名稱:DE3-ROB1-CHESS,代碼行數:53,代碼來源:main.py


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