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