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 matchSingleWall(wallLength, wallModules,wallIndex): print("wallLength",wallLength) print("wallModules",wallModules) print("wallIndex",wallIndex) pass 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,1,1])