Exemple #1
0
 def init_locations(self):
     with open("internals/loc_descriptions.json") as f_obj:
         loc_iterator = json.load(f_obj)
     loc_list = list()
     for next_loc in loc_iterator:
         loc_list.append(loc.Location(next_loc))
     return loc_list
Exemple #2
0
def findCheapestOrder(origin, list_of_locations):
    list_of_orders = generatePermutations(list_of_locations)
    minprice = sys.float_info.max
    minorder = []
    for i in list_of_orders:

        destinations = list(i) + [origin]
        originloc = locations.Location(origin[0], userinput.origin_date)
        daysfromorigin = 0
        destinationlocs = []
        for j in destinations:
            destinationlocs += [locations.Location(destinations[0], userinput.origin_date)]
            daysfromorigin += destinations[1] + 1
            destinationlocs[j].locations.setDate(daysfromorigin)

        flight_itinerary = flexibook.getMultipleDestinationFlights(originloc, destinationlocs)

        if flight_itinerary.price < minprice:
            minorder = flight_itinerary
            minprice = flight_itinerary.price

    return minorder
Exemple #3
0
def load_instance(name):
    inst = Instance(name)
    paths = ["items/", "locations/"]

    data = None
    for i, path in enumerate(paths):
        with open(path + name + ".json", "r", encoding="utf-8") as rf:
            data = json.load(rf)
        if i == 0:
            for n in data:
                if n["id"][0] == "a":
                    inst.armor.append(items.Armor(*n.values()))
                elif n["id"][0] == "w":
                    inst.weapons.append(items.Weapon(*n.values()))
        elif i == 1:
            for n in data:
                tmp_items = []
                for loc_item in n["items"]:
                    tmp_items.append(inst.get_item(loc_item))
                n["items"] = tmp_items
                inst.locations.append(locations.Location(*n.values()))

    return inst
def interface(location):
    for char in location.inhabList() + [location.getPlayer()]:
        if not char.isAlive(): continue
        char.startThread()
    #Game.startThread(location.inhabList()+[location.getPlayer()]) #allows for rudimentary Display - buggy
    while location.getPlayer().isAlive() and any(location.inhabList()):
        pass

    for char in location.inhabList() + [location.getPlayer()]:
        char._alive = False

    print("Done!")


if __name__ == "__main__":
    location = locations.Location()
    character = npc.NPC("Steve", location)
    char2 = npc.NPC("Mitch", location)
    player = player.Player("Jim", location)
    location.addPlayer(player)
    location.addInhab(character)
    location.addInhab(char2)
    #stick = weapons.Weapon(name="stick", damage={'sides':4,'num':2})
    jerkin = armour.Armour(name="jerkin", aRating=20, armClass="torso")
    #roboArm = augments.Augment(name="Robotic Arm", mod={'str': 500, 'agi':500, 'con': 0}, augClass='muscle')
    #player.equip(stick)
    player.equip(jerkin)
    #player.equip(roboArm)
    interface(location)
Exemple #5
0
    totalPrice = 0
    orig = origin
    for d in destinations:
        f = getFlights(orig, d)
        fly = flights.Flights(f.text, 0)
        totalPrice += fly.price
        flightArray.append(fly)
        orig = d
    totalPriceOfLastTripCalculated = totalPrice
    return flightArray

    #getFlights(locations.Location("BOS",'2017-09-17'), locations.Location("SEA",'0000-00-00'))


dest = []
dest.append(locations.Location("SFO", '2017-09-22'))
dest.append(locations.Location("SEA", '2017-09-28'))
dest[0].setDate(2)
a = getMultipleDestinationFlights(locations.Location("BOS", '2017-09-17'),
                                  dest)

#print()
#print()
#print()
#for f in a:
#print(f)
#print("---------------" + "origin: " + str(f.origin) + ", destination: " + str(f.destination) + ", departs_at: " + str(f.departs_at) + ", arrives_at: " + str(f.arrives_at) + ", airline: " + str(f.airline) + ", price: " + str(f.price) + ", stops: " + str(f.stops))


#takes the current flight index and current Location originlocation and
#finds next possible flight to arrive at the destination earlier