import utils.conf import utils.getarray # 判断能否摆下组件的贴墙边 from utils import getarray # 判断当前边能否放下指定模块 def canMatch(wallLength, moduleLengths): moduleTotalLength = 0; for item in moduleLengths: moduleTotalLength = moduleTotalLength + item return (moduleTotalLength <= wallLength) # matchResult = canMatch(3,(1,1,2)) # print(matchResult) # 获取当前位置的所有摆法 def matchWalls(roomLengths, moduleLengths): m = len(roomLengths) n = len(moduleLengths) a = getarray.getAllPosition(m, n) canMatchTop = canMatch(roomLengths[2], moduleLengths) if(canMatchTop): print("begin to calc top") matchTopWall(roomLengths[2],moduleLengths) else: for item in a: matchWall(roomLengths,moduleLengths,a[item]) # 获取单边墙的模块摆放顺序 def changeModuleIndex(wallModules, param): newIndexModules = [] print("before changeModuleIndex:",wallModules) for index in range(len(param)): newIndexModules.append(wallModules[param[index]-1]) print("after changeModuleIndex:",newIndexModules) # 摆放带顺序的单边墙 def matchSingleWallWithIndex(wallLength, wallModules): for item in wallModules: pass # 摆放单边墙 def matchSingleWall(wallLength, wallModules,wallIndex): print("wallLength",wallLength) print("wallModules",wallModules) print("wallIndex",wallIndex) if(canMatch(wallLength,wallModules)): a = getarray.jiechenarray(len(wallModules)) for item in a: changeModuleIndex(wallModules,a[item]) matchSingleWallWithIndex(wallLength, wallModules) else: print("this array not match") # 摆放所有墙 def matchWall(roomLengths, moduleLengths, positions): m = len(roomLengths) n = len(moduleLengths) a = getarray.getitemIndexAndPositionArray(positions,m,n) for item in a: if(a[item][0] == 1): position = a[item][1][0] wallModules = {}; wallModules[0] = moduleLengths[position] matchSingleWall(roomLengths[position],wallModules,position) if(a[item][0] > 1): wallModules = {}; for modulePosition in a[item][1]: moduleIndex = a[item][1][modulePosition] wallModules[modulePosition] = moduleLengths[moduleIndex] matchSingleWall(roomLengths[item],wallModules,a[item][1][0]) pass #一字摆法 def matchTopWall(roomLengths,moduleLengths): matchSingleWall(roomLengths, moduleLengths, "012") matchWalls([1,2,3,4],[1,2,1]) # changeModuleIndex([100,200,313],[2,1,3])