Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def addPlacement(ships,hitListLength,start = None, mainList = None,countingList = None):
- if start == None:
- start=0
- if mainList == None:
- mainList = []
- if countingList == None:
- countingList = []
- #pop ship from array for use on this recusion level
- ship = ships.pop()
- #loop through each hit
- for x in range(start,hitListLength):
- #add this rotation to the counting list
- countingList.append(x)
- #if we don't need to go any deeper add the counting array as an element of the main list
- if len(ships) == 0:
- mainList.append(countingList)
- print "MainList: " + str(mainList)
- else:
- #otherwise recure deeper updating mainlist
- mainList += addPlacement(ships,hitListLength,(start+1),mainList,countinglist)
- #remove this loops countingList contribution so next loop can take its place
- countingList.pop()
- #return the mainlist
- ships.append(ship)
- print "MainList: " + str(mainList)
- return mainList
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement