sc2simulator/setup/mapLocations.py
def progressiveSquares(pt, idx=1):
            """locate a point as close as possible to idx"""
            validLocs = []
            uRad = techUnit.radius # assumed sc2techTree is available if sc2maps is as well
            cx, cy = pt
            minX = cx - idx # create bounding box outline
            maxX = cx + idx
            minY = cy - idx
            maxY = cy + idx
            for x in range(minX, maxX+1):
                pt1 = (x, minY, 0) # bottom row
                pt2 = (x, maxY, 0) # top row
                if field.canSet(pt1, uRad, goodVal=1): validLocs.append(pt1)
                if field.canSet(pt2, uRad, goodVal=1): validLocs.append(pt2)
            for y in range(minY+1, maxY+2): # exclude bottom/top rows
                pt1 = (minX, y, 0) # left side
                pt2 = (maxX, y, 0) # right side
                if field.canSet(pt1, uRad, goodVal=1): validLocs.append(pt1)
                if field.canSet(pt2, uRad, goodVal=1): validLocs.append(pt2)
            if validLocs: # found at least one valid location; pick one
                  pick = random.choice(validLocs)
                  newPt = [term / 2.0 for term in pick] # convert from 2x grid size field (for half points) back to normal grid coordinates
                  field.setValues(pick[:2], radius=[uRad]*2, newVal=0,
                      shape=c.cs.SQUARE) # don't overlap these coordinates anymore
                  #field.display()
                  return newPt
            else: return progressiveSquares(pt, idx=idx+1) # consider next square
locate a point as close as possible to idx
locate a point as close as possible to idx
locate a point as close as possible to idx
def progressiveSquares(pt, idx=1):
            validLocs = []
            uRad = techUnit.radius 
            cx, cy = pt
            minX = cx - idx 
            maxX = cx + idx
            minY = cy - idx
            maxY = cy + idx
            for x in range(minX, maxX+1):
                pt1 = (x, minY, 0) 
                pt2 = (x, maxY, 0) 
                if field.canSet(pt1, uRad, goodVal=1): validLocs.append(pt1)
                if field.canSet(pt2, uRad, goodVal=1): validLocs.append(pt2)
            for y in range(minY+1, maxY+2): 
                pt1 = (minX, y, 0) 
                pt2 = (maxX, y, 0) 
                if field.canSet(pt1, uRad, goodVal=1): validLocs.append(pt1)
                if field.canSet(pt2, uRad, goodVal=1): validLocs.append(pt2)
            if validLocs: 
                  pick = random.choice(validLocs)
                  newPt = [term / 2.0 for term in pick] 
                  field.setValues(pick[:2], radius=[uRad]*2, newVal=0,
                      shape=c.cs.SQUARE) 
                  return newPt
            else: return progressiveSquares(pt, idx=idx+1) 
def progressiveSquares ( pt , idx = 1 ) : validLocs = [ ] uRad = techUnit . radius cx , cy = pt minX = cx - idx maxX = cx + idx minY = cy - idx maxY = cy + idx for x in range ( minX , maxX + 1 ) : pt1 = ( x , minY , 0 ) pt2 = ( x , maxY , 0 ) if field . canSet ( pt1 , uRad , goodVal = 1 ) : validLocs . append ( pt1 ) if field . canSet ( pt2 , uRad , goodVal = 1 ) : validLocs . append ( pt2 ) for y in range ( minY + 1 , maxY + 2 ) : pt1 = ( minX , y , 0 ) pt2 = ( maxX , y , 0 ) if field . canSet ( pt1 , uRad , goodVal = 1 ) : validLocs . append ( pt1 ) if field . canSet ( pt2 , uRad , goodVal = 1 ) : validLocs . append ( pt2 ) if validLocs : pick = random . choice ( validLocs ) newPt = [ term / 2.0 for term in pick ] field . setValues ( pick [ : 2 ] , radius = [ uRad ] * 2 , newVal = 0 , shape = c . cs . SQUARE ) return newPt else : return progressiveSquares ( pt , idx = idx + 1 )
locate a point as close as possible to idx
locate a point as close as possible to idx
"""locate a point as close as possible to idx""" # assumed sc2techTree is available if sc2maps is as well # create bounding box outline # bottom row # top row # exclude bottom/top rows # left side # right side # found at least one valid location; pick one # convert from 2x grid size field (for half points) back to normal grid coordinates # don't overlap these coordinates anymore #field.display() # consider next square
pt
idx