You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3nar/spaceAround.py

80 lines
2.6 KiB

from sympy.utilities.iterables import multiset_permutations
def findCoordAround(center, nbAround):
find = []
for i in range(len(center)):
find = getNCoordDiff(center,find,i,nbAround)
return find
def getNCoordDiff(center,find,nbDiffValue, nbAround):
coord = []
if (-nbAround+nbAround >= nbDiffValue):
return find
for i in range(nbDiffValue):
coord.append(-nbAround+i)
while True:
modified = False
cursor = len(coord)-1
while(not modified):
if (cursor<0):
return find
if (coord[cursor]+len(coord)-1-cursor<nbAround):
modified = True
coord[cursor] += 1
val = coord[cursor] +1
cursor += 1
while(cursor<len(coord)):
coord[cursor] = val
cursor +=1
val += 1
else:
cursor -= 1
find = getCompletVariationOfCoord(center,find,coord)
return find
def getCompletVariationOfCoord(center,find,partialCoord):
coord = []
for i in range(len(partialCoord)):
coord.append(partialCoord[i])
while len(coord) != len(center):
coord.append(partialCoord[0])
find = getPermutationOfCoord(center,find,coord)
while True:
cursor = len(coord)-1
modified = False
while not modified:
if (cursor == len(partialCoord)-1):
return find
if (coord[cursor]!=partialCoord[len(partialCoord)-1]):
modified = True
afterCursor = 0
while afterCursor<len(partialCoord) and coord[cursor] != partialCoord[afterCursor]:
afterCursor +=1
afterCursor += 1
while(cursor<len(coord)):
coord[cursor] = partialCoord[afterCursor]
cursor += 1
else:
cursor -= 1
find = getPermutationOfCoord(center,find,coord)
return find
def getPermutationOfCoord(center,find,coord):
find.append(coord)
for perm in multiset_permutations(coord):
find.append(perm)
return find
def applySapceAroundToCase(center,spaceAround,space):
reelSpaceAround = []
for y in range(len(spaceAround)):
estBon = True
for i in range(len(spaceAround[y])):
if not estBon:
continue
spaceAround[y][i] += center[i]
estBon = estBon and space.minCoord < spaceAround[y][i] < space.maxCoord
if estBon:
reelSpaceAround.append(spaceAround[y])
print(reelSpaceAround)
return reelSpaceAround