<commit_before>
import sys, random
from rando.Items import ItemManager
from utils import getRangeDict, chooseFromRange

# Holder for settings and a few utility functions related to them
# (especially for plando/rando).
# Holds settings not related to graph layout.
class RandoSettings(object):
    def __init__(self, maxDiff, progSpeed, progDiff, qty, restrictions,
                 superFun, runtimeLimit_s, plandoRandoItemLocs):
        self.progSpeed = progSpeed.lower()
        self.progDiff = progDiff.lower()
        self.maxDiff = maxDiff
        self.qty = qty
        self.restrictions = restrictions
        self.superFun = superFun
        self.runtimeLimit_s = runtimeLimit_s
        if self.runtimeLimit_s <= 0:
            self.runtimeLimit_s = sys.maxsize
        self.plandoRandoItemLocs = plandoRandoItemLocs

    def getItemManager(self, smbm):
        if self.plandoRandoItemLocs is None:
            return ItemManager(self.restrictions['MajorMinor'], self.qty, smbm)
        else:
            return ItemManager('Plando', self.qty, smbm)

    def getExcludeItems(self, locations):
        if self.plandoRandoItemLocs is None:
            return None
        exclude = {'total':0}
        # plandoRando is a dict {'loc name': 'item type'}
        for locName,itemType in self.plandoRandoItemLocs.items():
            if not any(loc['Name'] == locName for loc in locations):
                continue
            if itemType not in exclude:
                exclude[itemType] = 0
            exclude[itemType] += 1
            exclude['total'] += 1

        return exclude

    def collectAlreadyPlacedItemLocations(self, container):
        if self.plandoRandoItemLocs is None:
            return
        for locName,itemType in self.plandoRandoItemLocs.items():
            if not any(loc['Name'] == locName for loc in container.unusedLocations):
                continue
            item = container.getNextItemInPool(itemType)
            assert item is not None, "Invalid plando item pool"
            location = container.getLocs(lambda loc: loc['Name'] == locName)[0]
            itemLoc = {'Item':item, 'Location':location}
            container.collect(itemLoc, pickup=False)

# Holds settings and utiliy functions related to graph layout
class GraphSettings(object):
    def __init__(self, startAP, areaRando, bossRando, escapeRando, dotFile, plandoRandoTransitions):
        self.bidir = True
        self.startAP = startAP
        self.areaRando = areaRando
        self.bossRando = bossRando
        self.escapeRando = escapeRando
        self.dotFile = dotFile
        self.plandoRandoTransitions = plandoRandoTransitions

    # used by FillerRandom to know how many front fill steps it must perform
    def getRandomFillHelp(self):
        helpByAp = {
            "Firefleas Top": 3,
            "Aqueduct": 1,
            "Mama Turtle": 1,
            "Watering Hole": 2,
            "Etecoons Supers": 2,
            "Gauntlet Top":1,
            "Bubble Mountain":1
        }
        return helpByAp[self.startAP] if self.startAP in helpByAp else 0

# algo settings depending on prog speed (slowest to fastest+variable,
# other "speeds" are actually different algorithms)
class ProgSpeedParameters(object):
    def __init__(self, restrictions):
        self.restrictions = restrictions

    def getVariableSpeed(self):
        ranges = getRangeDict({
            'slowest':7,
            'slow':20,
            'medium':35,
            'fast':27,
            'fastest':11
        })
        return chooseFromRange(ranges)

    def getMinorHelpProb(self, progSpeed):
        if self.restrictions.split != 'Major':
            return 0
        if progSpeed == 'slowest':
            return 0.16
        elif progSpeed == 'slow':
            return 0.33
        elif progSpeed == 'medium':
            return 0.5
        return 1

    def getItemLimit(self, progSpeed):
        itemLimit = 105
        if progSpeed == 'slow':
            itemLimit = 21
        elif progSpeed == 'medium':
            itemLimit = 9
        elif progSpeed == 'fast':
            itemLimit = 6
        elif progSpeed == 'fastest':
            itemLimit = 1
        if self.restrictions.split == 'Chozo':
            itemLimit = int(itemLimit / 4)
        minLimit = itemLimit - int(itemLimit/5)
        maxLimit = itemLimit + int(itemLimit/5)
        if minLimit == maxLimit:
            itemLimit = minLimit
        else:
            itemLimit = random.randint(minLimit, maxLimit)
        return itemLimit

    def getLocLimit(self, progSpeed):
        locLimit = -1
        if progSpeed == 'slow':
            locLimit = 1
        elif progSpeed == 'medium':
            locLimit = 2
        elif progSpeed == 'fast':
            locLimit = 3<commit_msg>rando: sped up fast speed a bit<commit_after>
import sys, random
from rando.Items import ItemManager
from utils import getRangeDict, chooseFromRange

# Holder for settings and a few utility functions related to them
# (especially for plando/rando).
# Holds settings not related to graph layout.
class RandoSettings(object):
    def __init__(self, maxDiff, progSpeed, progDiff, qty, restrictions,
                 superFun, runtimeLimit_s, plandoRandoItemLocs):
        self.progSpeed = progSpeed.lower()
        self.progDiff = progDiff.lower()
        self.maxDiff = maxDiff
        self.qty = qty
        self.restrictions = restrictions
        self.superFun = superFun
        self.runtimeLimit_s = runtimeLimit_s
        if self.runtimeLimit_s <= 0:
            self.runtimeLimit_s = sys.maxsize
        self.plandoRandoItemLocs = plandoRandoItemLocs

    def getItemManager(self, smbm):
        if self.plandoRandoItemLocs is None:
            return ItemManager(self.restrictions['MajorMinor'], self.qty, smbm)
        else:
            return ItemManager('Plando', self.qty, smbm)

    def getExcludeItems(self, locations):
        if self.plandoRandoItemLocs is None:
            return None
        exclude = {'total':0}
        # plandoRando is a dict {'loc name': 'item type'}
        for locName,itemType in self.plandoRandoItemLocs.items():
            if not any(loc['Name'] == locName for loc in locations):
                continue
            if itemType not in exclude:
                exclude[itemType] = 0
            exclude[itemType] += 1
            exclude['total'] += 1

        return exclude

    def collectAlreadyPlacedItemLocations(self, container):
        if self.plandoRandoItemLocs is None:
            return
        for locName,itemType in self.plandoRandoItemLocs.items():
            if not any(loc['Name'] == locName for loc in container.unusedLocations):
                continue
            item = container.getNextItemInPool(itemType)
            assert item is not None, "Invalid plando item pool"
            location = container.getLocs(lambda loc: loc['Name'] == locName)[0]
            itemLoc = {'Item':item, 'Location':location}
            container.collect(itemLoc, pickup=False)

# Holds settings and utiliy functions related to graph layout
class GraphSettings(object):
    def __init__(self, startAP, areaRando, bossRando, escapeRando, dotFile, plandoRandoTransitions):
        self.bidir = True
        self.startAP = startAP
        self.areaRando = areaRando
        self.bossRando = bossRando
        self.escapeRando = escapeRando
        self.dotFile = dotFile
        self.plandoRandoTransitions = plandoRandoTransitions

    # used by FillerRandom to know how many front fill steps it must perform
    def getRandomFillHelp(self):
        helpByAp = {
            "Firefleas Top": 3,
            "Aqueduct": 1,
            "Mama Turtle": 1,
            "Watering Hole": 2,
            "Etecoons Supers": 2,
            "Gauntlet Top":1,
            "Bubble Mountain":1
        }
        return helpByAp[self.startAP] if self.startAP in helpByAp else 0

# algo settings depending on prog speed (slowest to fastest+variable,
# other "speeds" are actually different algorithms)
class ProgSpeedParameters(object):
    def __init__(self, restrictions):
        self.restrictions = restrictions

    def getVariableSpeed(self):
        ranges = getRangeDict({
            'slowest':7,
            'slow':20,
            'medium':35,
            'fast':27,
            'fastest':11
        })
        return chooseFromRange(ranges)

    def getMinorHelpProb(self, progSpeed):
        if self.restrictions.split != 'Major':
            return 0
        if progSpeed == 'slowest':
            return 0.16
        elif progSpeed == 'slow':
            return 0.33
        elif progSpeed == 'medium':
            return 0.5
        return 1

    def getItemLimit(self, progSpeed):
        itemLimit = 105
        if progSpeed == 'slow':
            itemLimit = 21
        elif progSpeed == 'medium':
            itemLimit = 9
        elif progSpeed == 'fast':
            itemLimit = 5
        elif progSpeed == 'fastest':
            itemLimit = 1
        if self.restrictions.split == 'Chozo':
            itemLimit = int(itemLimit / 4)
        minLimit = itemLimit - int(itemLimit/5)
        maxLimit = itemLimit + int(itemLimit/5)
        if minLimit == maxLimit:
            itemLimit = minLimit
        else:
            itemLimit = random.randint(minLimit, maxLimit)
        return itemLimit

    def getLocLimit(self, progSpeed):
        locLimit = -1
        if progSpeed == 'slow':
            locLimit = 1
        elif progSpeed == 'medium':
            locLimit = 2
        elif progSpeed == 'fast':
            locLimit = 3
{'fraction_non_alphanumeric': 0.08610587989119063, 'fraction_numerical': 0.010043942247332079, 'mean_word_length': 2.1207966046359776, 'pattern_counts': {'":': 14, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '623720', 'n_tokens_mistral': 2798, 'n_tokens_neox': 2643, 'n_words': 747}