本文整理汇总了Python中Board.getAdjacentPositions方法的典型用法代码示例。如果您正苦于以下问题:Python Board.getAdjacentPositions方法的具体用法?Python Board.getAdjacentPositions怎么用?Python Board.getAdjacentPositions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Board
的用法示例。
在下文中一共展示了Board.getAdjacentPositions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __hasPiecesFrozen
# 需要导入模块: import Board [as 别名]
# 或者: from Board import getAdjacentPositions [as 别名]
def __hasPiecesFrozen(self, board, row, col, piece):
value = 0
piecesFrozen = 0
# Generate all the occupied adjacent positions.
adj_occ_pos = Board.getAdjacentPositions(board, row, col, True)
for pos in adj_occ_pos:
adj_row = pos[0]
adj_col = pos[1]
adj_piece = board[adj_row][adj_col]
# Make sure you're not looking at piece that
# you're friends with.
if not Piece.areFriends(piece, adj_piece):
# If you're stronger than the adjacent piece,
# then you've frozen it.
if Piece.isStronger(piece, adj_piece):
piecesFrozen = piecesFrozen + 1
# Return a value now based on the number of pieces frozen.
# If it has too many pieces frozen, then it has potential
# to being trapped. So it needs to be careful.
if piecesFrozen == 1:
value = 100
elif piecesFrozen == 2:
value = 1000
elif piecesFrozen == 3:
value = -100
if piecesFrozen == 4:
value = -1000
return value
示例2: __nextMoveType
# 需要导入模块: import Board [as 别名]
# 或者: from Board import getAdjacentPositions [as 别名]
def __nextMoveType(self, steps):
if len(steps) <= 0:
return Step.Step.REGULAR
# Get rid of traps, not necessary for this
for step in steps:
if step.dir == "x" or step.dir == "X":
steps.remove(step)
last_step = steps[-1]
# We may be in the process of doing a push
# or just completing a pull.
if last_step.color != self.color:
# We just completed a pull
if len(steps) >= 2:
prev_step = steps[-2]
if prev_step.start_row == last_step.end_row and \
prev_step.start_col == last_step.end_col:
return Step.Step.REGULAR
else:
return Step.Step.MUST_PUSH
# Or we're in the middle of a push
else:
return Step.Step.MUST_PUSH
else:
# Get all the occupied adjacent positions to see if we can attempt a pull.
adj_pos = Board.getAdjacentPositions(self.board, last_step.start_row, last_step.start_col, True)
for pos in adj_pos:
row = pos[0]
col = pos[1]
other_piece = self.board[row][col]
# Ensure that the piece we are trying to pull is not our own.
if Piece.pieceColor(other_piece) != self.color:
# Now are we actually stronger than that piece
if Piece.isStronger(last_step.piece, other_piece):
return Step.Step.CAN_PULL
return Step.Step.REGULAR
示例3: __genSteps
# 需要导入模块: import Board [as 别名]
# 或者: from Board import getAdjacentPositions [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)
#.........这里部分代码省略.........