Ejemplo n.º 1
0
	def load(self):
		tiles = []
		tree = ET.parse('Basic Level.tmx')
		root = tree.getroot()
		tileProperties = []
		for layer in root.iter('tile'):
			tileProperty = {'tileNum' : layer.attrib['id']}
#			print layer.tag, layer.attrib
			for g in layer:
				tileProperty[g[0].attrib['name']] = g[0].attrib['value']
			tileProperties.append(tileProperty)
#		print tileProperties
		for layer in root.iter('layer'):
#			print layer.tag, layer.attrib['name']
#			print "\t" + layer[0].tag, layer[0].attrib
			data = layer[0].text.encode('ascii')
			encoding = layer[0].attrib.pop('encoding')
			if encoding == 'base64':
				data = base64.b64decode(data)
			data = zlib.decompress(data)
			tlayer = array.array('L', [(ord(a) +(ord(b) << 8) + (ord(c) << 16) + (ord(d) << 24)) for a, b, c, d in zip(*(data[x::4] for x in range(4)))])
			for y in range(0,15):
				for x in range(0,23):
					if layer.attrib['name'] == "Background Tiles" and not tlayer[y*23+x] == 1:
						tileNum = tlayer[y*23+x]
						tileType = 0
						for tileProperty in tileProperties:
							if tileProperty['tileNum'] == str(tileNum): tileType = int(tileProperty['type'])
#						print tileNum, tileType
						tiles.append(Tile((32*x, 32*y), tileType, tileNum, self.tileSet))
		entities = []
		levelArray = [
					  "OOOOOOOOOOOOOOOOOOOOOOO",
					  "O                     O",
					  "O                     O",
					  "O  0                  O",
					  "O  OOOOO  WWW  L   L  O",
					  "O    O   W   W L  L   O",
					  "O    O   W   W L L    O",
					  "O    O    WWW  LL     O",
					  "O    O       W L L    O",
					  "O    O       W L  L   O",
					  "O    O    WWW  L   L  O",
					  "O                     O",
					  "O                     O",
					  "O  2  2   2  2      2 O",
					  "OOOOOOOOOOOOOOOOOOOOOOO",]
		x = y = 0
		for row in levelArray:
			for column in row:
				if column == "0": entities.append(entity((x,y),0))
				elif column == "2": entities.append(entity((x,y),2))
				x += 32
			y += 32
			x = 0
Ejemplo n.º 2
0
def inst_LK_rmw_DV(Eid, state, num_wg, **useless):
    decode = z3.And(
        [ readyRMW( state , Eid, entity = entity(Eid.d, wgId) )  \
            for wgId in range(num_wg)  ]  )

    inst = Instruction('LK_rmw_DV', decode)
    inst.setEntity(Eid)
    for wgId in range(num_wg):
        lockRMW(inst, state, entity=entity(Eid.d, wgId))  # not including w
    #forallWg( d, lambda w2: inst.setUpdateToState( state(d,w2).rmw , lock(d,w,t) ) )
    return inst
Ejemplo n.º 3
0
def inst_FLU_L1_DV(Eid, state, num_wg, **useless):
    inst = Instruction('FLU_L1_DV', True)
    inst.setEntity(Eid)

    for wgId in range(num_wg):
        inst.setUpdateToState('L1fifohead',
                              state('L1fifohead', entity=entity(Eid.d, wgId)) +
                              1,
                              entity=entity(Eid.d, wgId))
        # for all wg in the same device, enqueue a flush marker

    return inst
Ejemplo n.º 4
0
def inst_INV_L1_DV(Eid, state, num_wg, **useless):
    inst = Instruction('INV_L1_DV', True)
    inst.setEntity(Eid)
    for wgId in range(num_wg):
        inst.setUpdateToState('L1fr',
                              INVALID,
                              addr=None,
                              entity=entity(Eid.d,
                                            wgId))  # will not set addr = x
    return inst
Ejemplo n.º 5
0
 def reset(self, grid_file=None):
     # Set file the system uses to reset itself
     self.grid_file = grid_file if grid_file else self.grid_file
     # Initialize dictionary of entities
     self.entities = {"agent": None, "uav": [], "goal": None, "entity": []}
     # Open grid file to initialize dimension and objects
     with open(self.grid_file, 'r') as f:
         # Initialize square dimension of grid
         self.dim = int(f.readline().strip('\n'))
         # Initialize objects
         for line in f:
             object_type, row, col = (line.strip('\n')).split(' ')
             row = int(row)
             col = int(col)
             if object_type == "agent":
                 self.entities["agent"] = agent([row, col])
             elif object_type == "goal":
                 self.entities["goal"] = entity([row, col])
             elif object_type == "uav":
                 self.entities["uav"].append(uav([row, col]))
             elif object_type == "entity":
                 self.entities["entity"].append(entity([row, col]))
Ejemplo n.º 6
0
def ev_FLUSH_L1(x, Eid, state, num_dev, **useless):
    inst = Instruction(
        'FLUSH_L1',
        z3.And(state('L1hy', addr=x) == DIRTY, readylockfile(x, state, Eid)))
    inst.setEntity(Eid)
    for devIdx in range(num_dev):
        if devIdx == Eid.d: continue
        inst.setUpdateToState(
            'L2fr', INVALID, addr=x,
            entity=entity(devIdx))  # write to all device at x
    #forallDev(lambda d2: if d2 != d : inst.setUpdateToState( state(d2).L2(x).fr , INVALID ) )
    storeL2(x, state('L1val', addr=x), inst, state=state)
    #store( state(d).L2, x, state(d,w).L1(x).value , inst )  # but one for L2fr
    inst.setUpdateToState('L1hy', CLEAN, addr=x)
    #inst.setUpdateToState( state(d,w).L1(x).hy , CLEAN )    #
    inst.recordAddr(x)
    inst.tp = 'gpuEnvTrans'
    return inst
Ejemplo n.º 7
0
def inst_INC_L2(x, r, Eid, state, num_dev,
                **useless):  # will need to  give a function

    decode = z3.And([ \
        readyRMW(state, Eid),
        state('L1hy', addr = x) != DIRTY,
        readylockfile(x, state, Eid),
        state('L2fr', addr = x) == VALID
    ])

    inst = Instruction('INC_L2', decode)
    inst.setEntity(Eid)

    inst.setUpdateToState('L1fr', INVALID,
                          addr=x)  #invalidate( state(d,w).L1, inst  )
    inst.setUpdateToState('r', state('L2val', addr=x), addr=x)
    for devIdx in range(num_dev):
        if devIdx == Eid.d: continue
        inst.setUpdateToState('L2fr', INVALID, addr=x, entity=entity(devIdx))
    storeL2(x, state('L2val', addr=x) + 1, inst, state=state)  # contains L2fr

    inst.recordAddr(x)
    return inst
Ejemplo n.º 8
0
    def generate(self, eidos, aa):#1:treasure room,2:room,3: starting room
        pos = []
        entities = []
        triggerables=[]
        units = []
        
        if eidos==3:
            width=random.randint(8,10)
            height=random.randint(8,10)
            exits=4
            monster_cap=0
            trap_cap=random.randint(0,self.level/5)
            obstacle_cap=random.randint(4,8)
        else:
            width=random.randint(8,16)
            height=random.randint(8,16)
            area=width*height
            if (area<=81):
                exits=random.randint(1,4)
                monster_cap=random.randint(2,3)
                trap_cap=random.randint(0,2)
                obstacle_cap=random.randint(4,8)
            elif (area<121):
                exits=random.randint(1,5)
                monster_cap=random.randint(2,4)
                trap_cap=random.randint(0,3)
                obstacle_cap=random.randint(5,10)
            elif (area<169):
                exits=random.randint(1,6)
                monster_cap=random.randint(3,6)
                trap_cap=random.randint(0,4)
                obstacle_cap=random.randint(8,14)
            else:
                exits=random.randint(1,8)
                monster_cap=random.randint(4,8)
                trap_cap=random.randint(1,6)
                obstacle_cap=random.randint(10,18)
            if eidos==1:
                chest_cap=random.randint(self.level-2,self.level-1)
                
        i=1
        while(i<width-1):
                j=1
                while(j<height-1):
                    pos.append((i,j))
                    j=j+1
                i=i+1
                
        exits_list=[]
        exlist=[]
        exposx=[]
        exposy=[]
        
        i=2
        while(i<width-2):
            exposx.append(i)
            i=i+2
        i=1
        while(i<height-1):
            exposy.append(i)
            i=i+2
        i=0

        wall=0
        walll=[1,2,3,4]
        while (i<exits):
            if (eidos==3):
                wall=wall+1
            else:
                wall=random.choice(walll)
            if wall==1:
                x=0
                if len(exposy)==0:
                    walll.pop(walll.index(1))
                    continue
                y=random.choice(exposy)
                exposy.pop(exposy.index(y))
            elif wall==2:
                x=width-1
                if len(exposy)==0:
                    walll.pop(walll.index(2))
                    continue
                y=random.choice(exposy)
                exposy.pop(exposy.index(y))
            elif wall==3:
                if len(exposx)==0:
                    walll.pop(walll.index(3))
                    continue
                x=random.choice(exposx)
                y=0
                exposx.pop(exposx.index(x))
            elif wall==4:
                if len(exposx)==0:
                    walll.pop(walll.index(4))
                    continue
                x=random.choice(exposx)
                y=height-1
                exposx.pop(exposx.index(x))
            exits_list.append(door(aa,None,wall,x*self.size[0],y*self.size[1],self.doortext))
            exlist.append((x*self.size[0],y*self.size[1]))
            
            i=i+1
        test_map=[]
        i=0
        while(i<width):
            j=0
            tempidi=[]
            while(j<height):
                tempidi.append(True)
                j=j+1
            test_map.append(tempidi)
            i=i+1
        i=0
        while(i<obstacle_cap):
            (x,y)=random.choice(pos)
            test_map[x][y]=False
           
            j=1
            p=0
            while j<exits:
                if Astar((exits_list[0].x/self.size[0],exits_list[0].y/self.size[1]),(exits_list[j].x/self.size[0],exits_list[j].y/self.size[1]),test_map):
                    j=j+1
                    continue
                p=p+1
                test_map[x][y]=True
                if(p==5):
                    break
                (x,y)=random.choice(pos)
                test_map[x][y]=False
                j=1
            if(p==5):
                i=i+1
                continue
            pos.pop(pos.index((x,y)))
            entities.append(entity(x*self.size[0],y*self.size[1],self.walltext))
            i=i+1
        i=0
        while(i<trap_cap):
            (x,y)=random.choice(pos)
            pos.pop(pos.index((x,y)))
            triggerables.append(triggerable(x*self.size[0],y*self.size[1],self.traptext))
            i=i+1
        i=0
        ref=['head','torso','legs','feet','arms']
        while(i<monster_cap):
            (x,y)=random.choice(pos)
            pos.pop(pos.index((x,y)))

            j=random.randint(0,len(enemies)-1)                
            units.append(enemies[j].create(x*self.size[0],y*self.size[1]))
            k=0
            while(k<2):
                k=k+1
            while(k<7):
                if(units[-1].items[k]):
                    units[-1].equip(self.armorer.generate_a(units[-1].items[k]),units[-1].items[k])
                k=k+1
            i=i+1
        if eidos==1:
            i=0
            while(i<chest_cap):
                (x,y)=random.choice(pos)
                pos.pop(pos.index((x,y)))
                units.append(triggerable(x*self.size[0],y*self.size[1],self.chesttext))
                i=i+1

        temp = room(units,entities,exits_list,triggerables,eidos,width,height,exlist,aa)
        for i in range(len(temp.exits)):
            temp.exits[i].room = temp
            
        return temp
Ejemplo n.º 9
0
def inst_UL_rmw_DV(Eid, state, num_wg, **useless):
    inst = Instruction('UL_rmw_DV', True)
    inst.setEntity(Eid)
    for wgId in range(num_wg):
        unlockRMW(inst, state, entity=entity(Eid.d, wgId))
    return inst
Ejemplo n.º 10
0
    def load(self):
        tiles = []
        tree = ET.parse('Basic Level.tmx')
        root = tree.getroot()
        tileProperties = []
        for layer in root.iter('tile'):
            tileProperty = {'tileNum': layer.attrib['id']}
            #			print layer.tag, layer.attrib
            for g in layer:
                tileProperty[g[0].attrib['name']] = g[0].attrib['value']
            tileProperties.append(tileProperty)
#		print tileProperties
        for layer in root.iter('layer'):
            #			print layer.tag, layer.attrib['name']
            #			print "\t" + layer[0].tag, layer[0].attrib
            data = layer[0].text.encode('ascii')
            encoding = layer[0].attrib.pop('encoding')
            if encoding == 'base64':
                data = base64.b64decode(data)
            data = zlib.decompress(data)
            tlayer = array.array(
                'L',
                [(ord(a) + (ord(b) << 8) + (ord(c) << 16) + (ord(d) << 24))
                 for a, b, c, d in zip(*(data[x::4] for x in range(4)))])
            for y in range(0, 15):
                for x in range(0, 23):
                    if layer.attrib[
                            'name'] == "Background Tiles" and not tlayer[
                                y * 23 + x] == 1:
                        tileNum = tlayer[y * 23 + x]
                        tileType = 0
                        for tileProperty in tileProperties:
                            if tileProperty['tileNum'] == str(tileNum):
                                tileType = int(tileProperty['type'])
#						print tileNum, tileType
                        tiles.append(
                            Tile((32 * x, 32 * y), tileType, tileNum,
                                 self.tileSet))
        entities = []
        levelArray = [
            "OOOOOOOOOOOOOOOOOOOOOOO",
            "O                     O",
            "O                     O",
            "O  0                  O",
            "O  OOOOO  WWW  L   L  O",
            "O    O   W   W L  L   O",
            "O    O   W   W L L    O",
            "O    O    WWW  LL     O",
            "O    O       W L L    O",
            "O    O       W L  L   O",
            "O    O    WWW  L   L  O",
            "O                     O",
            "O                     O",
            "O  2  2   2  2      2 O",
            "OOOOOOOOOOOOOOOOOOOOOOO",
        ]
        x = y = 0
        for row in levelArray:
            for column in row:
                if column == "0": entities.append(entity((x, y), 0))
                elif column == "2": entities.append(entity((x, y), 2))
                x += 32
            y += 32
            x = 0