Beispiel #1
0
def turns(path, tile_x_y):
    turns = 0
    for n in range(len(path) - 1):
        tile = path[n]
        tile_type = tile_x_y[tile[0]][tile[1]]
        exit = distance(path[n], path[n+1])
        if tile_type in (3,4,5,6):
            turns += 1
        elif tile_type == 7 and exit == left:
            turns += 1
        elif tile_type == 8 and exit == right:
            turns += 1
        elif tile_type == 9 and exit == top:
            turns += 1
        elif tile_type == 10 and exit == bot:
            turns += 1
        elif tile_type == 11 and n > 0:
            if exit != distance(path[n-1], path[n]):
                turn += 1
    return turns
Beispiel #2
0
def map_path(world, me, file = None):
    tiles_x_y = world.tiles_x_y
    waypoints = [tuple(x) for x in (world.waypoints + [world.waypoints[0]]) ]
    starting_direction = (int(round(cos(me.angle))),int(round(-sin(me.angle))))
    path = [waypoints[0]]
    entry_direction = starting_direction

    for n in range(1, len(waypoints)):
        shortest_path_between_wp = shortest_path_between_tiles(tiles_x_y, waypoints[n-1], waypoints[n], entry_direction)
        if shortest_path_between_wp != None:
            path.extend(shortest_path_between_wp)
            entry_direction = distance(path[-2], path[-1])
    
    if file != None:
        with open(file, 'rb+') as f:
            for tile in path:
                f.write(str(tile))
                f.write('\n')

    return path