<commit_before>#!/usr/bin/env python3

import argparse
import collections
import json
import os
import re
import string
import sys

#
# Hex Grid Calculations
#

# http://www.redblobgames.com/grids/hexagons/#coordinates
# SWN hex grids are an "odd-q" layout (flat bottoms, high top-left corner) with "offset" coordinates.

def offset_to_cube(col, row):
    x = col
    z = row - (col - (col % 2)) // 2
    y = -1 * x - z

    return CubeCoord(x, z, y)

def cube_distance(a, b):
    return max(abs(a.x - b.x), abs(a.y - b.y), abs(a.z - b.z))

def cube_distances_complete(systems):
    # Complete graph of the direct point-to-point distances between hexes
    direct = {s.name:{e.name:None for e in systems} for s in systems}

    for start in systems:
        for end in systems:
            # Optimise by reusing reverse distance (end->start)
            if direct[start.name][end.name] is None:
                distance = cube_distance(start.cube, end.cube)
                direct[start.name][end.name] = distance
                direct[end.name][start.name] = distance

    return direct

#
# Pathfinding
#

def pathfind(start, end, heuristic):
    # TODO A*
    pass

def find_jump_paths(direct_distances, drive_level):
    system_names = sorted(direct_distances.keys())

    # Optimal paths between systems at a particular drive level
    paths = {s:{e:None for e in system_names} for s in system_names}

    for start in system_names:
        for end in system_names:
            # Optimise by reusing reverse path (end->start)
            if paths[start][end] is None:
                path = pathfind(start, end, lambda s,e: direct_distances[s][e])
                paths[start][end] = path
                # TODO total cost will be the same in a reversed path, don't know how it will be stored yet
                paths[end][start] = list(reversed(path))

    return paths

def find_all_jump_paths(direct_distances, max_drive_level=6):
    # Optimal paths between systems at all drive levels between 1 and max_drive_level
    paths = dict()
    for level in range(1, max_drive_level + 1):
        paths[level] = find_jump_paths(direct_distances, level)
    return paths

#<commit_msg>Need to generate the graph for pathfinding when the drive level is known. Could do it later, but would be repeating the creation many times.<commit_after>#!/usr/bin/env python3

import argparse
import collections
import json
import os
import re
import string
import sys

#
# Hex Grid Calculations
#

# http://www.redblobgames.com/grids/hexagons/#coordinates
# SWN hex grids are an "odd-q" layout (flat bottoms, high top-left corner) with "offset" coordinates.

def offset_to_cube(col, row):
    x = col
    z = row - (col - (col % 2)) // 2
    y = -1 * x - z

    return CubeCoord(x, z, y)

def cube_distance(a, b):
    return max(abs(a.x - b.x), abs(a.y - b.y), abs(a.z - b.z))

def cube_distances_complete(systems):
    # Complete graph of the direct point-to-point distances between hexes
    direct = {s.name:{e.name:None for e in systems} for s in systems}

    for start in systems:
        for end in systems:
            # Optimise by reusing reverse distance (end->start)
            if direct[start.name][end.name] is None:
                distance = cube_distance(start.cube, end.cube)
                direct[start.name][end.name] = distance
                direct[end.name][start.name] = distance

    return direct

#
# Pathfinding
#

def pathfind(graph, start, end, heuristic):
    # TODO A*
    pass

def find_jump_paths(direct_distances, drive_level):
    system_names = sorted(direct_distances.keys())

    # Optimal paths between systems at a particular drive level
    paths = {s:{e:None for e in system_names} for s in system_names}

    # TODO need to pregenerate a graph with all possible jumps at this drive_level
    possible_jumps = None

    for start in system_names:
        for end in system_names:
            # Optimise by reusing reverse path (end->start)
            if paths[start][end] is None:
                path = pathfind(possible_jumps, start, end, lambda s,e: direct_distances[s][e])
                paths[start][end] = path
                # TODO total cost will be the same in a reversed path, don't know how it will be stored yet
                paths[end][start] = list(reversed(path))

    return paths

def find_all_jump_paths(direct_distances, max_drive_level=6):
    # Optimal paths between systems at all drive levels between 1 and max_drive_level
    paths = dict()
    for level in range(1, max_drive_level + 1):
        paths[level] = find_jump_paths(direct_distances, level)
    return paths

#
{'fraction_non_alphanumeric': 0.09465286761535144, 'fraction_numerical': 0.0034497628288055198, 'mean_word_length': 2.793131643499591, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2162326', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1409, 'n_words': 483}