当前位置: 首页>>代码示例>>Python>>正文


Python Board.isFrozen方法代码示例

本文整理汇总了Python中Board.isFrozen方法的典型用法代码示例。如果您正苦于以下问题:Python Board.isFrozen方法的具体用法?Python Board.isFrozen怎么用?Python Board.isFrozen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Board的用法示例。


在下文中一共展示了Board.isFrozen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: evaluateBoard

# 需要导入模块: import Board [as 别名]
# 或者: from Board import isFrozen [as 别名]
    def evaluateBoard(self, board, color, combined, start_row = 0, start_col = 0, end_row = 7, end_col = 7):
        
        value = 0
        

        for row in range(start_row, end_row + 1):
            for col in range (start_col, end_col + 1):
                piece = board[row][col]

                # If it's my piece, then add to my total.
                if color == Piece.pieceColor(piece):
                    value = value + self.__getMaterialValue(board, color, piece)
                    value = value + self.__getPositionValue(color, piece, row, col)
                
                    if Board.isFrozen(board, piece, row, col):
                        value = value + self.__getFrozenValue(color, piece, row, col)  
                   
                # Else, it's the opponent's piece, the value goes down.
                elif combined == True:
                    value = value - self.__getMaterialValue(board, color, piece)
                    value = value - self.__getPositionValue(color, piece, row, col)

                    if Board.isFrozen(board, piece, row, col):
                        value = value - self.__getFrozenValue(color, piece, row, col)
        
        return value
开发者ID:boomft,项目名称:arimaa,代码行数:28,代码来源:Evaluation.py

示例2: __genSteps

# 需要导入模块: import Board [as 别名]
# 或者: from Board import isFrozen [as 别名]
 def __genSteps(self, steps, start_row, start_col, end_row, end_col):
     moves = []
     steps_left = MoveGenerator.MAX_STEPS
     last_step = Step.Step("")
     push = ""
     
     # Go through all the previous steps.
     # Decrement number of steps left and determine what the last step was.
     # We need to know the last step for pushes and pulls.
     for step in steps:
         if step.dir != "x" or step.dir != "X":
             steps_left = steps_left - 1
             last_step = step
     
     if steps_left <= 0:
         return moves
     
     # Next move type gives information about what the next step can/must be
     next_move_type = self.__nextMoveType(steps)
     
     # If we're in the process of making a push, we have to complete the push.
     # Multiple pieces could move into that position, just as long as their
     # stronger and aren't on the same team.
     if next_move_type == Step.Step.MUST_PUSH:
         occ_adj_pos = Board.getAdjacentPositions(self.board, last_step.start_row, last_step.start_col, True)
         for pos in occ_adj_pos:
             row = pos[0]
             col = pos[1]
             piece = self.board[row][col]
             color = Piece.pieceColor(piece)
             if piece == " " or piece == "x" or piece == "X":
                 continue
             # A piece can't move into it's friendly space.
             elif color != last_step.color:
                 # See if this piece is stronger than the one that was just moved
                 if Piece.isStronger(piece, last_step.piece):
                     
                     # Can this piece even move? Or is it frozen.
                     if not Board.isFrozen(self.board, piece, row, col):
                         step = self.__makeStep(piece, row, col, [[last_step.start_row, last_step.start_col]])
                         moves.append(step)
                         
     # Were not completing a push, we are free to do what we want
     else:
         for row in range(start_row, end_row + 1):
             for col in range(start_col, end_col + 1):
                 piece = self.board[row][col]
 
                 # Don't care for blank spaces or trap squares
                 if piece == " " or re.match("x", piece, re.IGNORECASE):
                     continue
                                 
                 piece_color = Piece.pieceColor(piece)
                 
                 # Get all the unoccupied and occupied adjacent positions to this piece
                 unocc_adj_pos = Board.getAdjacentPositions(self.board, row, col, False)
                 occ_adj_pos = Board.getAdjacentPositions(self.board, row, col, True)
                 
                 # Only generate moves for the current player
                 if piece_color == self.color:
 
                     # Is the piece NOT frozen
                     if not Board.isFrozen(self.board, piece, row, col):
                         unocc_adj_pos = self.__adjustRabbitPositions(piece, row, col, unocc_adj_pos)
                         step = self.__makeStep(piece, row, col, unocc_adj_pos)
                         moves.append(step)
                         
                 # If we're here, then we found the opponent piece.
                 # Lets see if we can push or pull it.
                 else:
                     
                     # Try doing a pull if the last move we did can initialize a pull.
                     if (next_move_type == Step.Step.CAN_PULL):
                         
                         # Get all the occupied positions to the last step.
                         prev_adj_occ_pos = Board.getAdjacentPositions(self.board, last_step.start_row, last_step.start_col, True)
                         for prev_adj_pos in prev_adj_occ_pos:
                             if piece_color != self.color and \
                                Piece.isStronger(last_step.piece, piece):
                                     prev_adj_row = prev_adj_pos[0]
                                     prev_adj_col = prev_adj_pos[1]
                                     if row == prev_adj_row and col == prev_adj_col:
                                         step = self.__makeStep(piece, row, col, [[last_step.start_row, last_step.start_col]])
                                         moves.append(step)
                                         
                                     
                     
                     # Try performing a push on this piece.
                     if (steps_left >= 2):
                         for pos in occ_adj_pos:
                             adj_row = pos[0]
                             adj_col = pos[1]
                             adj_piece = self.board[adj_row][adj_col]
                             adj_color = Piece.pieceColor(adj_piece)
                             if adj_color == self.color and \
                                 Piece.isStronger(adj_piece, piece):
                                 if not Board.isFrozen(self.board, adj_piece, row, col):
                                     step = self.__makeStep(piece, row, col, unocc_adj_pos)
                                     moves.append(step)
                             
#.........这里部分代码省略.........
开发者ID:boomft,项目名称:arimaa,代码行数:103,代码来源:MoveGenerator.py


注:本文中的Board.isFrozen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。