matchWall.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import utils.conf
  2. import utils.getarray
  3. # 判断能否摆下组件的贴墙边
  4. from utils import getarray
  5. # 判断当前边能否放下指定模块
  6. def canMatch(wallLength, moduleLengths):
  7. moduleTotalLength = 0;
  8. for item in moduleLengths:
  9. moduleTotalLength = moduleTotalLength + item
  10. return (moduleTotalLength <= wallLength)
  11. # matchResult = canMatch(3,(1,1,2))
  12. # print(matchResult)
  13. # 获取当前位置的所有摆法
  14. def matchWalls(roomLengths, moduleLengths):
  15. m = len(roomLengths)
  16. n = len(moduleLengths)
  17. a = getarray.getAllPosition(m, n)
  18. canMatchTop = canMatch(roomLengths[2], moduleLengths)
  19. if(canMatchTop):
  20. print("begin to calc top")
  21. matchTopWall(roomLengths[2],moduleLengths)
  22. else:
  23. for item in a:
  24. matchWall(roomLengths,moduleLengths,a[item])
  25. def matchSingleWall(wallLength, wallModules,wallIndex):
  26. print("wallLength",wallLength)
  27. print("wallModules",wallModules)
  28. print("wallIndex",wallIndex)
  29. pass
  30. def matchWall(roomLengths, moduleLengths, positions):
  31. m = len(roomLengths)
  32. n = len(moduleLengths)
  33. a = getarray.getitemIndexAndPositionArray(positions,m,n)
  34. for item in a:
  35. if(a[item][0] == 1):
  36. position = a[item][1][0]
  37. wallModules = {};
  38. wallModules[0] = moduleLengths[position]
  39. matchSingleWall(roomLengths[position],wallModules,position)
  40. if(a[item][0] > 1):
  41. wallModules = {};
  42. for modulePosition in a[item][1]:
  43. moduleIndex = a[item][1][modulePosition]
  44. wallModules[modulePosition] = moduleLengths[moduleIndex]
  45. matchSingleWall(roomLengths[item],wallModules,a[item][1][0])
  46. pass
  47. #一字摆法
  48. def matchTopWall(roomLengths,moduleLengths):
  49. matchSingleWall(roomLengths, moduleLengths, "012")
  50. matchWalls([1,2,3,4],[1,1,1])