Beispiel #1
0
def cardPath(gameMap, startLocation, cards):
    '''Return a list of MovePoints containing every step resulting from 
    applying cards at startLocation.
    
    Ignores all robots on the map but does take into account walls, 
    conveyor belts and gears.
    
    gameMap -- the current state of the game map.
    startLocation -- the starting BoardLocation of the move.
    cards -- list of robot Card moves, to be applied in order.
    
    '''
    #if we can't move, we end up where we started
    points = [MovePoint(startLocation)]
    
    for card in cards:
        #move robot
        endPoint = move(gameMap, startLocation, card.move)
        if endPoint.dead:
            points.append(endPoint)
            return points
        if endPoint.location != startLocation:
            startLocation = endPoint.location
            points.append(MovePoint(startLocation))
        
        sq = gameMap.getSquare(startLocation.mapPosition)
        
        #conveyor belt - may cause a 1/4 turn.
        speed = 1
        while sq.conveyor is not None and speed <= sq.conveyor.speed:
            endPoint = move(gameMap, startLocation.mapPosition, 
                            sq.conveyor.direction)
            locMove = BoardLocation(endPoint.location.mapPosition, 
                                    startLocation.direction)
            sq = gameMap.getSquare(endPoint.location.mapPosition)
            if sq.conveyor is not None:
                dirEnter = moveDirection(startLocation.mapPosition, 
                                         endPoint.location.mapPosition)
                if dirEnter is None:
                    dirEnter = startLocation.direction
                locMove = locMove.rotate(DIRS[sq.conveyor.direction] - DIRS[dirEnter])
            startLocation = locMove
            points.append(MovePoint(startLocation))
            speed += 1
        
        #gears
        if   sq.type == "ROTATE_CLOCKWISE":
            startLocation = startLocation.rotate(1)
        elif sq.type == "ROTATE_COUNTERCLOCKWISE":
            startLocation = startLocation.rotate(-1)
        else:
            assert sq.type in TYPE
        
        points.append(MovePoint(startLocation))
        
        #damage
        damage = calcLaserDamage(gameMap, startLocation)
        if damage != 0:
            points[-1].damage = damage
    return points