예제 #1
0
파일: elite.py 프로젝트: terix2k12/elitemo
def bestdealReturn(marketId, proximity, cargohold):
    profits = []
    market1 = entities.market(marketId)
    for target in proximity:
        market2 = entities.market(target)
        dealsTo = deals(market1, market2)
        dealsFrom = deals(market2, market1)
        ct = cf = q = p = s = r = e = x = z = 0
        instructions = []
        for (ct, p, s) in dealsTo:
            if (x == cargohold):
                break
            if (x + s > cargohold):
                s = cargohold - x
            instructions.append((marketId, ct, p, s))
            x += s
            e += (p * s)
        if not len(dealsTo):
            instructions.append((marketId, 0, 0, 0))
        for (cf, q, r) in dealsFrom:
            if (z == cargohold):
                break
            if (z + r > cargohold):
                r = cargohold - z
            instructions.append((target, cf, q, r))
            z += r
            e += (q * r)
        profits.append((e, instructions))
        if not len(dealsFrom):
            instructions.append((target, 0, 0, 0))

    profits.sort(key=lambda (profit, instructions): profit, reverse=True)
    return profits[0]
예제 #2
0
    def slow_test_create_galaxy_minipickle(self):
        entities.reset()
        entities.systems = assets.systems("res/systems_populated.json")
        entities.stations = assets.systems("res/stations.json")
        entities.markets = assets.markets("res/listings.csv")

        eravate = entities.system(name="Eravate")

        opt = { "ly": 50 }

        systems = {}
        for system in galaxy.proximity(system=eravate, options=opt):
            systems[ system["id"] ] = system
        self.assertEqual(len(systems), 519)

        stations = {}
        for station in galaxy.hubs(system=eravate, options=opt):
            stations[ station["id"] ] = station
        self.assertEqual(len(stations), 2081)

        markets = {}
        for station in stations.values():
            markets[ station["id"] ] = entities.market(station["id"])
        self.assertEqual(len(markets), 2081)

        assets.doPickle(systems, "res/systems-mini-50.pic")
        assets.doPickle(stations, "res/stations-mini-50.pic")
        assets.doPickle(markets, "res/markets-mini-50.pic")
예제 #3
0
파일: elite.py 프로젝트: terix2k12/elitemo
def dealOneTrip(marketId, targetId, cargohold):
    profits = []
    market1 = entities.market(marketId)
    market2 = entities.market(targetId)

    dealsTo = deals(market1, market2)
    ct = p = s = x = e = 0
    instructions = []
    for (ct, p, s) in dealsTo:
        if (x == cargohold):
            break
        if (x + s > cargohold):
            s = cargohold - x
        instructions.append((marketId, target, ct, p * s, s))
        x += s
        e += (p * s)

    return instructions
예제 #4
0
파일: elite.py 프로젝트: terix2k12/elitemo
def bestdealOneway(marketId, proximity, cargohold):
    profits = []
    market1 = entities.market(marketId)
    for target in proximity:
        market2 = entities.market(target)
        dealsTo = deals(market1, market2)
        ct = p = s = x = e = 0
        instructions = []
        for (ct, p, s) in dealsTo:
            if (x == cargohold):
                break
            if (x + s > cargohold):
                s = cargohold - x
            instructions.append((marketId, target, ct, p * s, s))
            x += s
            e += (p * s)
        profits.append((e, instructions))
    profits.sort(key=lambda (profit, instructions): profit, reverse=True)
    return profits[0]
예제 #5
0
def hubs(system=None, station=None, options={}):
    if station:
        system = entities.system(station=station)
    proxies = []
    for sys in proximity(system=system, station=station, options=options):
        for station in entities.station(system=sys):
            if "landingpad" in options:
                if padsize(options["landingpad"]) > padsize(
                        station["max_landing_pad_size"]):
                    continue
            if "commodity" in options:
                isPresent = False
                for (commodityId, amount) in options["commodity"]:
                    market = entities.market(station["id"])
                    for item in market:
                        if int(item["supply"]) >= int(amount) and int(
                                commodityId) == int(item["commodity_id"]):
                            isPresent = True
                if not isPresent:
                    continue
            proxies.append(station)
    return proxies
예제 #6
0
 def test_entities_commodity_market_name(self):
     market = entities.market(1)
     commodity = entities.commodity(market=market, name="Clothing")
     self.assertEqual("123", commodity["buy_price"])
예제 #7
0
 def test_entities_commodity_at_market_id_str(self):
     market = entities.market(1)
     commodity = entities.commodity(market=market, id="5")
     self.assertEqual("123", commodity["buy_price"])
예제 #8
0
 def test_entities_market(self):
     market = entities.market(1)
     self.assertEqual(len(market), 7)
예제 #9
0
def compute(options, gcargohold, missiongoals):
    currentStationId = int(options["currentStationId"])

    steps = []

    # pseudocode
    # create node set from galaxy
    # kreuzprodukt aus graph
    #   applz mg auf nodeset
    #    sort nodeset
    #   schiff laden
    #   yiel auswaehlen (hihgest profi of cargohold)
    #   schiff ausladen
    #   mg aktualisieren
    #

    missionnodeset = [
    ]  # holds tuples of (source, target, profit, modifier, commodity, supply)
    cargohold = []  # holds tuples of (source, target, commodity, loading)
    maxcargospace = int(gcargohold["cargospace"])
    cargospace = maxcargospace  # compute gcargohold["emptycargospace"]

    if "ly" not in options:
        options["ly"] = 50

    currentStation = entities.station(id=currentStationId)
    allNeighbors = galaxy.hubs(station=currentStation, options=options)

    failsafe = 0
    while failsafe < 5:
        failsafe += 1
        instructions = []

        # Unload cargohold
        clone = []
        newinstructions = []
        dropped = {}
        for cargo in cargohold:
            (cargoTarget, cargoCommodityId, cargoVolume) = cargo
            if cargoTarget == currentStationId:
                instructions.append(('drop', cargo))
                newinstructions.append((cargoTarget, cargoCommodityId))
                if cargoCommodityId not in dropped:
                    dropped[cargoCommodityId] = 0
                dropped[cargoCommodityId] += cargoVolume
                cargospace += cargoVolume
            else:
                clone.append(cargo)
        cargohold = clone

        # Update mission goals
        clone = []
        for mission in missiongoals:
            (missionSource, missionTarget, missionCommodityId, missionVolume,
             missionReward, missionType) = mission
            if missionCommodityId in dropped:
                droppedAmount = dropped[missionCommodityId]
                if droppedAmount < missionVolume:
                    clone.append(
                        (missionSource, missionTarget, missionCommodityId,
                         missionVolume - droppedAmount, missionReward,
                         missionType))
            else:
                clone.append(mission)
        missiongoals = clone

        if len(missiongoals) == 0:
            steps.append((currentStationId, instructions))
            return steps

        nodeset = []

        # Only use neighbors with a missiongoal
        clone = []

        for neighbor in allNeighbors:
            neighborId = int(neighbor["id"])
            for missiongoal in missiongoals:
                (missionSource, missionTarget, missionCommodityId,
                 missionAmount, missionReward, missionType) = missiongoal
                # TODO other missiontypes
                if missionType in ["Source"]:
                    market2 = entities.market(neighborId)
                    for item in market2:
                        commodityId = int(item["commodity_id"])
                        supply = int(item["supply"])
                        if supply > 0 and missionCommodityId == commodityId:
                            clone.append(neighbor)
                            nodeset.append(
                                (neighborId, missionTarget, missionReward, 0,
                                 int(commodityId), missionAmount))
        neighbors = clone

        # Apply deals
        currentStation = entities.station(id=currentStationId)
        market1 = entities.market(currentStationId)
        for neighbor in neighbors:
            neighborId = int(neighbor["id"])
            market2 = entities.market(neighborId)
            deals = getdeals(market1, market2)
            for deal in deals:
                (commodityId, profit, supply) = deal
                nodeset.append((currentStationId, neighborId, profit, 0,
                                int(commodityId), supply))

        # TODO mission commodity is missing in deals......

        # Apply missiongoals modifier to nodeset
        clone = []
        for node in nodeset:
            (nodeSource, nodeTarget, nodeProfit, nodeModifier, nodeCommodityId,
             nodeSupply) = node
            for missiongoal in missiongoals:
                (missionSource, missionTarget, missionCommodityId,
                 missionVolume, missionReward, missionType) = missiongoal
                # if missionType in ['Deliver', 'Intel'] and missionTarget == nodeSource:
                #    nodeModifier = 10000
                #    break
                if missionType in [
                        "Source"
                ] and missionCommodityId == nodeCommodityId and nodeTarget == missionTarget:
                    nodeModifier = 10000
                    break
            clone.append((nodeSource, nodeTarget, nodeProfit, nodeModifier,
                          nodeCommodityId, nodeSupply))
        nodeset = clone

        # Select next target
        if len(nodeset) > 0:
            nodeset.sort(key=lambda (s, t, profit, modifier, c, a):
                         (profit + modifier +
                          (100000 if s == currentStationId else 0)),
                         reverse=True)
            (s, targetStationId, r, d, c, a) = nodeset[0]
        elif len(cargohold) > 0:
            (newTarget, c, a) = cargohold[0]
            targetStationId = newTarget
        else:
            targetStationId = 0

        if len(missiongoals) > 0:
            # Load cargohold
            clone = []
            for node in nodeset:
                (nodeSource, nodeTarget, nodeProfit, nodeModifier,
                 nodeCommodityId, nodeSupply) = node

                if nodeSource != currentStationId or cargospace == 0:
                    clone.append(node)
                    continue

                if nodeSupply >= cargospace:
                    loading = cargospace
                else:
                    loading = nodeSupply

                transfer = (nodeTarget, nodeCommodityId, loading)

                cargohold.append(transfer)
                cargospace -= loading

                instructions.append(('collect', transfer))

                if nodeSupply - loading > 0:
                    clone.append(
                        (nodeSource, nodeTarget, nodeProfit, nodeModifier,
                         nodeCommodityId, nodeSupply - loading))
            nodeset = clone

        # Continue the journey
        steps.append((currentStationId, instructions))
        currentStationId = targetStationId

        if currentStationId == 0:
            break

    return steps