def __init__(self, blueCell, aliveCellList, previousMove, previousState): SearchState.__init__(self, cell=None, previousMove=previousMove, previousState=previousState) self.blueCell = blueCell self.aliveCellList = sorted(aliveCellList)
def __init__(self, redMarbleCellList, blackMarbleCellList, previousMove=None, previousState=None): SearchState.__init__(self, cell=None, previousMove=previousMove, previousState=previousState) self.redMarbleCellList = sorted(redMarbleCellList) self.blackMarbleCellList = sorted(blackMarbleCellList)
def getAdjacentStateList(self, currentState): adjacentStateList = list() row, col = currentState.cell moveCode = self.getMoveCode(currentState) du, dv = self.arrowMovementCode[moveCode] distance = 1 while True: adjacentCell = u, v = row + du * distance, col + dv * distance if self.isCellOutsideGrid(adjacentCell): break sequenceCount = 1 if currentState.previousMove is None else currentState.previousMove.sequenceCount color = self.getColor(currentState.cell) newColor = self.getColor(adjacentCell) sequenceCount = 1 if newColor != color else sequenceCount + 1 move = ArrowSequenceMove(moveCode=moveCode, moveDistance=distance, sequenceCount=sequenceCount) newSearchState = SearchState(adjacentCell, previousMove=move, previousState=currentState) adjacentStateList.append(newSearchState) distance += 1 return filter( functools.partial(self.adjacentStateFilterFunc, currentState), adjacentStateList)
def getAdjacentStateList(self, currentState): adjacentStateList = list() row, col = currentState.cell currentPiece = self.mazeLayout.getRaw(row, col) if currentPiece == self.pawnToken: assert currentState.previousMove is not None currentPiece = currentState.previousMove.moveCode movementCodeDict = self.chessMovementCode[currentPiece] unit = movementCodeDict['unit'] cellDeltaList = movementCodeDict['cellList'] exploreList = list() for du, dv in cellDeltaList: adjacentCell = u, v = row + du, col + dv if self.isCellOutsideGrid(adjacentCell): continue if self.mazeLayout.getRaw(u, v) == self.emptyCell: exploreList.append((du, dv)) continue move = Move(moveCode=currentPiece, moveDistance=None) newSearchState = SearchState(adjacentCell, previousMove=move, previousState=currentState) adjacentStateList.append(newSearchState) if unit is not None: for du, dv in exploreList: u, v = row, col while True: adjacentCell = u, v = u + du, v + dv if self.isCellOutsideGrid(adjacentCell): break if self.mazeLayout.getRaw(u, v) != self.emptyCell: move = Move(moveCode=currentPiece, moveDistance=None) newSearchState = SearchState( adjacentCell, previousMove=move, previousState=currentState) adjacentStateList.append(newSearchState) break return filter( functools.partial(self.adjacentStateFilterFunc, currentState), adjacentStateList)
def getAdjacentStateList( self, currentState ): adjacentStateList = list() for directionTag, (du, dv) in self.allowedMovementCodes.items(): u, v = currentState.cell while True: x, y = u + du, v + dv if self.isCellOutsideGrid( (x, y) ) or (u, v, x, y) in self.blockedMoves: break u, v = x, y adjacentCell = u, v move = Move( moveCode=directionTag, moveDistance=None ) newSearchState = SearchState( adjacentCell, previousMove=move, previousState=currentState ) adjacentStateList.append( newSearchState ) return adjacentStateList
def getAdjacentStateList(self, currentState): adjacentStateList = list() row, col = currentState.cell previousMove = currentState.previousMove shape, color = self.mazeLayout.getRaw(row, col), self.getColorProperty( row, col) if shape == self.wildCardToken: shape, color = previousMove.shape, previousMove.color for directionTag, (du, dv) in self.allowedMovementCodes.items(): distance = 1 while True: adjacentCell = x, y = row + du * distance, col + dv * distance if self.isCellOutsideGrid(adjacentCell): break newShape, newColor = self.mazeLayout.getRaw( x, y), self.getColorProperty(x, y) isEmptyShape = newShape == self.emptyCellToken if isEmptyShape: break isWildcard = newShape == self.wildCardToken if isWildcard or newShape == shape or newColor == color: move = SequenceMove(moveCode=directionTag, moveDistance=distance) if previousMove is not None and previousMove.moveType( ) == move.moveType(): move.sequenceCount = previousMove.sequenceCount + 1 move.shape, move.color = shape, color move.matchType = (newShape == shape, newColor == color) newSearchState = SearchState(adjacentCell, previousMove=move, previousState=currentState) adjacentStateList.append(newSearchState) distance += 1 return filter( functools.partial(self.adjacentStateFilterFunc, currentState), adjacentStateList)
def getAdjacentStateList(self, currentState): adjacentStateList = list() allowedMoves = self.getAllowedMoves(currentState) try: stepCount = self.getStepCount(currentState) except UseDefaultImplementation: stepCount = self._defaultStepCount(currentState) row, col = currentState.cell for directionTag, (du, dv) in self.allowedMovementCodes.items(): if directionTag not in allowedMoves: continue adjacentCell = row + du * stepCount, col + dv * stepCount if self.isCellOutsideGrid(adjacentCell): continue move = Move(moveCode=directionTag, moveDistance=stepCount) newSearchState = SearchState(adjacentCell, previousMove=move, previousState=currentState) adjacentStateList.append(newSearchState) return adjacentStateList
def getStartState( self ): return SearchState( self.startCell, previousMove=None, previousState=None )
def __init__(self, previousMove, previousState, rollingBlock): SearchState.__init__(self, cell=None, previousMove=previousMove, previousState=previousState) self.rollingBlock = rollingBlock
def __init__(self, cell, previousMove, previousState, accumulator): SearchState.__init__(self, cell, previousMove, previousState) self.accumulator = accumulator