Example #1
0
def route_score(playerData, carId):
    """The engine calls this function 
        during route 1 to validate your route scoring
    
    Parameters:
        playerData - your player data as always
        carId - the id of the car where the route starts (1-32)
        
    You return:
        score - score is the length of the current route from the carId.
                if it reaches the power station, 
                the score is equal to twice the length.
    """
    
    # get position of first tile
    myCar = CarData(carId)
    currTile = playerData.tiles[myCar.entryTile]
    currNode = myCar.entryNode
    
    # initialize score
    score = 1
    
    # traverse route until complete or dead-end
    while True:
        exitNode = currTile.routeMap[currNode]
        
        if (exitNode == None):
            score -= 1
            myCar.score = score
            return score
        elif (currTile.isTerminalNode(exitNode) is True):
            myCar.score = score
            return score
        elif (currTile.isPsNode(exitNode) is True):
            score *=2
            myCar.score = score
            return score
        elif (exitNode == 1): 
            score += 1
            currNode = 4
            currTile = playerData.tiles[(currTile.position[0]-1,currTile.position[1])]
        elif (exitNode == 3):
            score += 1
            currNode = 6
            currTile = playerData.tiles[(currTile.position[0],currTile.position[1]+1)]
        elif (exitNode == 5):
            score += 1
            currNode = 0
            currTile = playerData.tiles[(currTile.position[0]+1,currTile.position[1])]
        elif (exitNode == 7):
            score += 1
            currNode = 2
            currTile = playerData.tiles[(currTile.position[0],currTile.position[1]-1)]
    
    myCar.score = score
    return score
Example #2
0
def route_complete(playerData, carId):
    """The engine calls this function 
        during part 1 to validate your route checking
    
    Parameters:
        playerData - your player data as always
        carId - the id of the car where the route starts (1-32)
        
    You return:
        isComplete - true or false depending on whether or not this car
             connects to another car or power station"""

    # get position of first tile
    myCar = CarData(carId)
    currTile = playerData.tiles[myCar.entryTile]
    currNode = myCar.entryNode
    # traverse route until complete or dead-end
    while True:
        exitNode = currTile.routeMap[currNode]
        if (exitNode == None):
            return False
        elif (currTile.isTerminalNode(exitNode) is True):
            myCar.complete = True
            return True
        elif (currTile.isPsNode(exitNode) is True):
            myCar.complete = True
            return True
        elif (exitNode == 1):
            currNode = 4
            currTile = playerData.tiles[(currTile.position[0] - 1,
                                         currTile.position[1])]
        elif (exitNode == 3):
            currNode = 6
            currTile = playerData.tiles[(currTile.position[0],
                                         currTile.position[1] + 1)]
        elif (exitNode == 5):
            currNode = 0
            currTile = playerData.tiles[(currTile.position[0] + 1,
                                         currTile.position[1])]
        elif (exitNode == 7):
            currNode = 2
            currTile = playerData.tiles[(currTile.position[0],
                                         currTile.position[1] - 1)]
Example #3
0
def route_score(playerData, carId):
    """The engine calls this function 
        during route 1 to validate your route scoring
    
    Parameters:
        playerData - your player data as always
        carId - the id of the car where the route starts (1-32)
        
    You return:
        score - score is the length of the current route from the carId.
                if it reaches the power station, 
                the score is equal to twice the length.
    """

    # get position of first tile
    myCar = CarData(carId)
    currTile = playerData.tiles[myCar.entryTile]
    currNode = myCar.entryNode

    # initialize score
    score = 1

    # traverse route until complete or dead-end
    while True:
        exitNode = currTile.routeMap[currNode]

        if (exitNode == None):
            score -= 1
            myCar.score = score
            return score
        elif (currTile.isTerminalNode(exitNode) is True):
            myCar.score = score
            return score
        elif (currTile.isPsNode(exitNode) is True):
            score *= 2
            myCar.score = score
            return score
        elif (exitNode == 1):
            score += 1
            currNode = 4
            currTile = playerData.tiles[(currTile.position[0] - 1,
                                         currTile.position[1])]
        elif (exitNode == 3):
            score += 1
            currNode = 6
            currTile = playerData.tiles[(currTile.position[0],
                                         currTile.position[1] + 1)]
        elif (exitNode == 5):
            score += 1
            currNode = 0
            currTile = playerData.tiles[(currTile.position[0] + 1,
                                         currTile.position[1])]
        elif (exitNode == 7):
            score += 1
            currNode = 2
            currTile = playerData.tiles[(currTile.position[0],
                                         currTile.position[1] - 1)]

    myCar.score = score
    return score
Example #4
0
def route_complete(playerData, carId):
    """The engine calls this function 
        during part 1 to validate your route checking
    
    Parameters:
        playerData - your player data as always
        carId - the id of the car where the route starts (1-32)
        
    You return:
        isComplete - true or false depending on whether or not this car
             connects to another car or power station"""
    
    # get position of first tile
    myCar = CarData(carId)
    currTile = playerData.tiles[myCar.entryTile]
    currNode = myCar.entryNode
    # traverse route until complete or dead-end
    while True:
        exitNode = currTile.routeMap[currNode]
        if (exitNode == None):
            return False
        elif (currTile.isTerminalNode(exitNode) is True):
            myCar.complete = True
            return True
        elif (currTile.isPsNode(exitNode) is True):
            myCar.complete = True
            return True
        elif (exitNode == 1):
            currNode = 4
            currTile = playerData.tiles[(currTile.position[0]-1,currTile.position[1])]
        elif (exitNode == 3): 
            currNode = 6
            currTile = playerData.tiles[(currTile.position[0],currTile.position[1]+1)]
        elif (exitNode == 5): 
            currNode = 0
            currTile = playerData.tiles[(currTile.position[0]+1,currTile.position[1])]
        elif (exitNode == 7): 
            currNode = 2
            currTile = playerData.tiles[(currTile.position[0],currTile.position[1]-1)]