MCPcopy Create free account
hub / github.com/ActiveState/code / pileOnto

Method pileOnto

recipes/Python/361168_Vpython_example/recipe-361168.py:59–87  ·  view source on GitHub ↗

Pile a onto b Where a and b are block numbers, moves the pile of blocks consisting of block a, and any blocks that are stacked above block a, onto block b. All blocks on top of block b are moved to their initial positions prior to the pile taking place. T

(self, a, b)

Source from the content-addressed store, hash-verified

57 a.moveTo(b.position)
58
59 def pileOnto(self, a, b):
60 """
61 Pile a onto b
62
63 Where a and b are block numbers, moves the pile of blocks consisting of
64 block a, and any blocks that are stacked above block a, onto block b.
65 All blocks on top of block b are moved to their initial positions prior
66 to the pile taking place. The blocks stacked above block a retain their
67 order when moved.
68 """
69 a, b = self._getBlocks(a, b)
70 if not a: return # Ignore bad indexes
71 # Remove the blocks on top of block b
72 b.removeBlocksFromAbove()
73 # Remove all the blocks on top of a and including onto b's stack
74 blocksToMove = [a] + a.above
75 for bl in blocksToMove:
76 bl.moveTo(b.position)
77 # All the below code would have reversed the order of the blocks
78 ##blocks = a.stack[a.stack.index(a):]
79 ##while blocks:
80 ## blocks.pop().moveTo(b.position)
81 # Shorter loop for python 2.3
82 ## [bl.moveTo(b.position) for bl in blocks[::-1]]
83 # Or for python 2.4
84 ## [bl.moveTo(b.position) for bl in reversed(blocks)]
85 # Or even this, but not very readable:
86 ##for block in a.stack[:a.stack.index(a):-1]:
87 ## block.moveTo(b.position)
88
89 def pileOver(self, a, b):
90 """

Callers

nothing calls this directly

Calls 3

_getBlocksMethod · 0.95
removeBlocksFromAboveMethod · 0.80
moveToMethod · 0.45

Tested by

no test coverage detected