Exemple #1
0
    def __init__(self):
        g = game.get()
        self.path = g.path
        self.camera = camera.Camera()
        self.tree = g.pine_p
        self.zoom = 0.1
        self.scroll = 0
        self.camera.center_on(64, 75)
        self.camera.rotate(vector.x, 1.3 * pi)

        self.river = mesh.read_frames(self.path + "/data/title.mesh.gz")
        self.river1 = mesh.read_frames(self.path + "/data/title1.mesh.gz")
        self.river2 = mesh.read_frames(self.path + "/data/title2.mesh.gz")
        self.raft_p = mesh.read_frames(self.path + "/data/raft0.mesh.gz")
        self.elephant_p = mesh.read_frames(self.path +
                                           "/data/elefant_yellow.mesh.gz")
        self.landscape = landscape.Landscape(self.river)
        self.actors = actor.Actors(self.landscape)
        self.pos = 0
        self.died = 0

        self.parse_text(story)

        self.mages = []
        for i in range(7):
            a = self.actors.new(g.mage_p[i], 64 + (i - 3.5) * 10, 64)
            a.cam.rotate(vector.z, pi)
            self.mages.append(a)

        self.t = 0
        render.resize(1280, 720)
        self.special = 0
 def initiateSim(self):
     if self.landscape == None:
         self.landscape = L.Landscape()
     self.theWorld = W.World(size=L.width,
                             numagents=W.starting_agents,
                             landscape=self.landscape)
     self.time = 0
     self.max_prestige = []
     self.avg_prestige = []
def init():
    global time, theWorld, cmap, plots, dirName, num_households, times
    l = L.Landscape()
    theWorld = W.World(size=L.width, numagents=W.starting_agents, landscape=l)

    time = 0
    num_households = [len(theWorld.households)]
    times = [0]

    cmap = matplotlib.colors.LinearSegmentedColormap(name='G',
                                                     segmentdata=cdict,
                                                     N=256)
    plots = None
    if MOVIES:
        openFolder()
Exemple #4
0
 def __init__(self, screen):
     self.timeout = 0
     self.freeze = False
     self.screen = screen
     self.next_player = 0
     self.player1 = tk.Tank1(0, 0, self)
     self.player2 = tk.Tank2(screen_width - 50, 0, self)
     self.skybox = sb.Skybox()
     self.terrain = ld.Landscape(0, 600, 1600)
     self.terrain.generate()
     self.terrain.update_texture()
     self.clock = pg.time.Clock()
     self.running = True
     self.players = []
     self.players.append(self.player1)
     self.players.append(self.player2)
     self.bullets = []
     self.anim = []
     self.texts = []
     self.drawable_objects = []
     self.drawable_objects.append(self.skybox)
     self.drawable_objects.append(self.terrain)
     self.drawable_objects.append(self.player1)
     self.drawable_objects.append(self.player2)
Exemple #5
0
    def __init__(self, path):
        self.path = path
        global _game
        _game = self

        self.show_title(True)

        self.input = controls.Input()

        self.font = al_load_font(self.path + "/data/JosefinSans-Regular.ttf",
                                 -12, 0)
        if not self.font:
            print("Cannot find data")
            sys.exit(1)
        self.font_big = al_load_font(
            self.path + "/data/JosefinSans-Regular.ttf", -48, 0)

        colors = ["red", "green", "blue", "black", "white", "yellow", "purple"]
        self.mage_p = []
        self.raft_p = []
        for i in range(7):
            self.raft_p.append(
                mesh.read_frames(self.path + "/data/raft%d.mesh.gz" % (1 + i)))
            self.mage_p.append(
                mesh.read_frames(self.path +
                                 "/data/%s mage_fire_outfit.mesh.gz" %
                                 colors[i]))
        self.river = mesh.read_frames(self.path + "/data/perlin.mesh.gz")
        self.dragon_p = mesh.read_frames(self.path + "/data/dragon.mesh.gz")
        self.pine_p = mesh.read_frames(self.path + "/data/pine.mesh.gz")
        self.finish_p = mesh.read_frames(self.path + "/data/finish.mesh.gz")
        self.wolf_p = mesh.read_frames(self.path + "/data/wolf.mesh.gz")

        self.roar = audio.load(self.path + "/data/wumpus dines.ogg")
        self.swoosh = audio.load(self.path + "/data/swoosh.ogg")
        self.yelp = audio.load(self.path + "/data/yelp.ogg")
        self.jingle = audio.load(self.path + "/data/jingle.ogg")
        self.rubber = audio.load(self.path + "/data/rubber.ogg")
        self.growl = audio.load(self.path + "/data/growl.ogg")
        self.chew = audio.load(self.path + "/data/chew.ogg")
        self.dogyelp = audio.load(self.path + "/data/dogyelp.ogg")

        self.zoom = 0
        self.rotation = pi / 4
        self.scroll = 20
        self.camera = camera.Camera()
        self.rotate_camera(0)
        self.paused = False
        self.title = title.Title()
        self.silver = al_color_name("silver")

        self.t = 0
        self.spawn = [(128 * 9 - 30, 10), (128 * 10 + 40, 10),
                      (128 * 11 + 30, 110), (128 * 12 + 0, 10),
                      (128 * 13 + 0, 10), (128 * 13 + 64, 110),
                      (128 * 14 + 0, 10), (128 * 14 + 64, 110),
                      (128 * 15 + 0, 10)]

        self.fps = [0, 0, 0, 0, 0, 0]
        self.fps_t = 0

        self.landscape = landscape.Landscape(self.river)

        self.actors = actor.Actors(self.landscape)

        with open(self.path + "/data/objects.json", "r") as j:
            self.objects = json.load(j)
            for o in self.objects:
                t = self.actors.new(self.pine_p,
                                    o["x"],
                                    o["y"],
                                    radius=8,
                                    scale=8,
                                    static=True)
                t.cam.rotate(vector.z, random.uniform(-pi, pi))
                t.cam.rotate(vector.y, pi / 8)

        t = self.actors.new(self.finish_p,
                            128 * 16 - 32,
                            48,
                            z=20,
                            scale=20,
                            static=True)
        t.cam.rotate(vector.z, -pi / 2)
        t.cam.rotate(vector.y, pi / 8)

        self.picked = None

        self.resize(1280, 720)

        self.raft = []
        self.raft_and_wolf = []
        for i in range(7):
            x = 16 + skip
            y = 64
            r = self.actors.new(self.raft_p[i], x, y)
            r.color = al_color_name(colors[i])
            r.color_index = i
            self.raft.append(r)
            self.raft_and_wolf.append(r)

        self.dragon = self.actors.new(self.dragon_p,
                                      -100,
                                      64,
                                      flying=True,
                                      scale=5,
                                      z=20)

        self.scroll_camera(self.scroll)
        self.red = al_color_name("crimson")
    def __init__(self,
                 size=DEFAULT_SIZE,
                 numagents=starting_agents,
                 landscape=L.Landscape()):
        HH.HHAgent.reset()
        F.Forager.reset()
        HH.world = self
        F.world = self

        self.foraging_resources = landscape.normalizeTo(
            max_resource, min_resource)
        self.max_foraging_resources = self.foraging_resources.copy()

        self.hh_locations = {}
        self.avg_hh_x = []
        self.avh_hh_y = []
        self.houses_by_loc = {}
        self.regrowth_rate = {}
        self.lineages = [i for i in range(numagents)]
        self.kinship_spans = []
        self.hh_food_stored = []
        self.pop_expertise = []
        self.max_prestige = []
        for x in range(L.width):
            for y in range(L.width):
                self.houses_by_loc[x, y] = []
                resource = self.max_foraging_resources[x, y]
                self.regrowth_rate[x, y] = math.exp(
                    (math.log(resource) - math.log(resource_zero)) /
                    regrowth_steps)

        self.households = [HH.HHAgent() for i in range(numagents)]
        avg_x = 0
        avg_y = 0
        span_interval = (max_founder_kin_span -
                         min_founder_kin_span) / numagents
        for hh in self.households:
            location = (rnd.randrange(L.width), rnd.randrange(L.width))
            x, y = location
            avg_x += x
            avg_y += y
            self.hh_locations[hh] = location
            self.houses_by_loc[location].append(hh)
            lineage_kinship_span = min_founder_kin_span + span_interval * hh.lineage
            founder = F.Forager(-1, kinship_span=lineage_kinship_span
                                )  # create a new forager with random adult age
            hh.addParent(founder)
            self.kinship_spans.append(lineage_kinship_span)
            self.pop_expertise.append(founder.innate_foraging_expertise)
            spouse = F.Forager(founder.age, kinship_span=lineage_kinship_span)
            founder.marry(spouse)
            self.kinship_spans.append(lineage_kinship_span)
            self.pop_expertise.append(spouse.innate_foraging_expertise)
            self.hh_food_stored.append(0)

        # metrics initializations
        avg_x /= numagents
        avg_y /= numagents
        self.population = sum([hh.size() for hh in self.households])
        self.populations = [self.population]
        self.avg_pop = [self.population]
        self.avg_pop_100 = [self.population]
        self.avg_hh_size = [2]
        self.avg_hh_age = [0]
        self.tot_hh_age = 0
        self.dead_houses = 1
        self.food_shared = [0]
        self.food_shared_total = 0
        self.food_shared_totals = [0]
        self.com_sharing = []  #communal sharing
        self.brn_sharing = []
        self.grn_sharing = []
        self.ages_at_death = []
        self.avg_ages = [
        ]  # track average ages at death at each tick for plotting
        self.adult_ages_at_death = []
        self.avg_adult_ages = [
        ]  # track average adult ages at death at each tick for plotting
        self.hh_prestige = []
        self.median_storage = [0]
        self.max_hoover = []
        self.avg_hoover = []
        self.avg_food_stored = []
Exemple #7
0
def drop(c,
         restorationLandscape,
         N=None,
         loopParamOne=.85,
         loopScale=1,
         loopParam=1,
         connection=None,
         outputdata="outdata.csv",
         previewOnly=False,
         jobid=1,
         thumbFile=None):

    if not N:
        N = c.habitatL().len()

    if N == 0:
        raise ValueError("Error: empty habitat")

    # Make a copy of the input condatis object
    cl = c.habitatL()

    c2 = cne.CondatisCoreNE(cl)
    c2.addSource(c.sourceL())
    c2.addTarget(c.targetL())
    c2.setParams(c.R(), c.dispersal())

    # Make an empty landscape object
    result = ls.Landscape()
    result.attribs = c.attribs

    result.firstFlow = None
    result.lastFlow = None
    restorationLandscape.scalev(scaleVoltage)

    # Assume that where inputs are above 1, it must be a percentage
    maxVoltage = max(restorationLandscape.v)
    if maxVoltage > 1.1:
        restorationLandscape.scalev(1.0 / 100.0)

    restorationLandscape.removeDuplicates(c2.habitatL())
    c2.modifyHabitat(c2.habitatL().append(restorationLandscape))

    N = restorationLandscape.len()
    numCells = c2.x().size

    minx = min(c2.x())
    maxx = max(c2.x())
    miny = min(c2.y())
    maxy = max(c2.y())

    maxVal = max(c2.habitatL().v)
    sumVal = sum(c2.habitatL().v)
    if (maxVal > 1.1):
        maxVal = maxVal / 100.0
        sumVal = sumVal / 100.0
    sumVal = sumVal / numCells

    # a very loose estimate of time to process
    estimated_time = int(2 + (numCells * numCells) * (N) / 4e9)

    timeScale = "minutes"

    if estimated_time > 120:
        estimated_time = estimated_time / 60
        timeScale = "hours"
        if estimated_time > 48:
            estimated_time = estimated_time / 24
            timeScale = "days"

    img_tag = ""

    # html is created to make a nice 'preview' image
    # if present, a thumbnail file is encoded into the html
    if thumbFile is not None:
        data_uri = open(thumbFile,
                        'rb').read().encode('base64').replace('\n', '')
        img_tag = '<img src="data:image/png;base64,%s">' % data_uri


    previewText = "<table  cellpadding='6'><tr><td>Number of cells </td><td>  "+ str(N) + "</td> <td rowspan='8'>"\
    ""+img_tag+"</td></tr>" \
    "<tr><td> Source size </td><td>" + str(c2.sourceL().x.size)+" cells </td></tr>" \
    "<tr><td> Target size </td><td>" + str(c2.targetL().x.size)+" cells </td></tr>" \
    "<tr><td> Estimated time </td><td>" +str(estimated_time)+" "+timeScale+" </td></tr>" \
    "<tr><td> East-West Range </td><td>" + str(minx) +" - "+str(maxx)+ "</td></tr>" \
    "<tr><td> North-South Range </td><td>" +str(miny) + " - " + str(maxy) +  "</td></tr>" \
    "<tr><td> Greatest cell coverage </td><td>" + str(maxVal*100) +"% </td></tr>" \
    "<tr><td> Average cell coverage </td><td>" + str(sumVal * 100) +"% </td></tr></table>"

    if previewOnly:
        if connection is not None:
            if connection.previewReport is not None:
                connection.previewReport(previewText)
        return result

    restorationLandscapeSet = ls.Landscape.getKeySet(restorationLandscape)
    cpuIndex = multiprocessing.cpu_count() * 150

    if N > cpuIndex:
        loopParam = loopParam + (int)(math.sqrt(N - cpuIndex) / 20)

    loopParam = loopParam * loopScale + (1 * (1 - loopScale))

    outputDataFile = open(outputdata, 'w')
    outputDataFile.write("i,Speed,x,y,flow\n")

    # Dropping loop
    i = 1
    for k in range(N - 1):

        c2.calc()
        sp = c2.speed()
        # checks against the feasible habitat
        nodeFlow = c2.nodeFlowL()

        # storing the first flow for later reporting
        if i == 1:
            result.firstFlow = nodeFlow
        maxVoltage = max(c2.habitatL().v)
        if maxVoltage > 1.1:
            print "out of range"
            raise ValueError("Failed with an out of range voltage  " +
                             str(maxVoltage))

        # Get (feasible) node with smallest flow
        ignoreSet = set()
        smallestList = []

        if connection is not None:
            if connection.progressReport is not None:
                connection.progressReport((i * 100.0) / N)

# work out how many cells to drop in this iteration

        loopSize = int(((N - i * 1.0) / N) * loopParam) + 1

        # don't drop more than we have
        if loopSize > N - i:
            loopSize = N - i + 1

# e.g., only drop individually for most significant cells
        if i > (N * loopParamOne):
            loopSize = 1

        for j in range(loopSize):
            smallest = nodeFlow.argminBoth(restorationLandscapeSet, ignoreSet)
            smallestList.append(smallest)

            # Create landscape object from the smallest flow
            # set value to i and append to result
            l = c2.habitatL()[smallest]
            ignoreSet.add(ls.Landscape.make_location_key(l.x, l.y))

            l.v = i
            result = result.append(l)

        land = c2.habitatL()

        smallestList.sort(reverse=True)

        # Remove the nodes with the smallest flow

        for smallest in smallestList:
            l = c2.habitatL()[smallest]
            nodeFlow = c2.nodeFlow()[smallest]
            log_all.log(
                "%i out of %i, Speed: %e  x,y = %f,%f, i= %e, %i" %
                (i, N, sp, l.x, l.y, c2.nodeFlow()[smallest], smallest))
            logging.info(
                "%i out of %i, Speed: %e  x,y = %f,%f, i= %e, %i" %
                (i, N, sp, l.x, l.y, c2.nodeFlow()[smallest], smallest))
            outputDataFile.write("%i,%e,%f,%f,%e,%i\n" %
                                 (i, sp, l.x, l.y, nodeFlow, smallest))
            c2.modifyHabitat(land.delete(smallest))
            i = i + 1
            if connection is not None:
                if connection.progressReport is not None:
                    connection.progressReport((i * 100.0) / N)

        if i > N:
            break

    outputDataFile.close()
    if connection is not None:
        if connection.progressReport is not None:
            connection.progressReport(100)

    c2.calc()
    result.lastFlow = c2.nodeFlowL()
    return result
Exemple #8
0
def flow(c,
         restorationLandscape,
         N=None,
         loopParamOne=.85,
         loopScale=1,
         loopParam=1,
         connection=None,
         outputdata="outdata.csv",
         previewOnly=False,
         normalise=None,
         jobid=0,
         thumbFile=None):

    if not N:
        N = c.habitatL().len()

    # Make a copy of the input condatis object
    cl = c.habitatL()

    c2 = cne.CondatisCoreNE(cl)
    if N == 0:
        raise ValueError("Error: empty habitat")

    c2.addSource(c.sourceL())
    c2.addTarget(c.targetL())
    c2.setParams(c.R(), c.dispersal())

    # Make an empty landscape object
    result = ls.Landscape()
    result.attribs = c.attribs

    N = c2.habitatL().len()
    numCells = c2.x().size

    minx = min(c2.x())
    maxx = max(c2.x())
    miny = min(c2.y())
    maxy = max(c2.y())

    estimated_time = int(2 + (numCells) * (N) / 4e8)
    maxVal = max(c2.habitatL().v)
    sumVal = sum(c2.habitatL().v)
    if (maxVal > 1.1):
        maxVal = maxVal / 100.0
        sumVal = sumVal / 100.0
    sumVal = sumVal / numCells

    img_tag = ""
    if thumbFile is not None:
        data_uri = open(thumbFile,
                        'rb').read().encode('base64').replace('\n', '')
        img_tag = '<img src="data:image/png;base64,%s">' % data_uri


    previewText = "<table  cellpadding='6'><tr><td>Number of cells </td><td>  "+ str(N) + "</td> <td rowspan='8'>"\
    ""+img_tag+"</td></tr>" \
    "<tr><td> Source size </td><td>" + str(c2.sourceL().x.size)+" cells </td></tr>" \
    "<tr><td> Target size </td><td>" + str(c2.targetL().x.size)+" cells </td></tr>" \
    "<tr><td> Estimated time </td><td>" +str(estimated_time)+" minutes </td></tr>" \
    "<tr><td> East-West Range </td><td>" + str(minx) +" - "+str(maxx)+ "</td></tr>" \
    "<tr><td> North-South Range </td><td>" +str(miny) + " - " + str(maxy) +  "</td></tr>" \
    "<tr><td> Greatest cell coverage </td><td>" + str(maxVal*100) +"% </td></tr>" \
    "<tr><td> Average cell coverage </td><td>" + str(sumVal * 100) +"% </td></tr></table>"

    if previewOnly:
        if connection is not None:
            if connection.previewReport is not None:
                connection.previewReport(previewText)
        return result

    c2.calc()
    sp = c2.speed()

    nodeFlow = c2.nodeFlowL()
    outputDataFile = open(outputdata, 'w')

    outputDataFile.write("Speed =, %f\n" % sp)
    outputDataFile.write("x,y,flow\n")

    for l in nodeFlow:
        outputDataFile.write("%f,%f,%e\n" % (l.x, l.y, l.v))

    if normalise is not None:
        maxVal = max(nodeFlow.v)
        nodeFlow.v = nodeFlow.v * normalise / maxVal

    outputDataFile.close()

    return nodeFlow