Parses the user input, starting with the number of blocks
()
| 213 | print self.box.pos |
| 214 | |
| 215 | def parse(): |
| 216 | """Parses the user input, starting with the number of blocks""" |
| 217 | # Get the number of blocks |
| 218 | while 1: |
| 219 | num = sys.stdin.readline() |
| 220 | try: |
| 221 | num = int(num[:-1]) |
| 222 | except Exception, e: |
| 223 | if num.lower() == 'quit\n': return |
| 224 | else: continue |
| 225 | else: break |
| 226 | # Create the objects |
| 227 | stacks = Stacks(num) |
| 228 | arm = Arm(stacks) |
| 229 | # Now parse each line of input ignoring dumb commands |
| 230 | while 1: |
| 231 | line = sys.stdin.readline().lower()[:-1] # Remove the enter at the end and convert to lowercase |
| 232 | if line == 'quit': |
| 233 | arm.quit() |
| 234 | break |
| 235 | else: |
| 236 | words = line.split() |
| 237 | if len(words) != 4: continue |
| 238 | if words[0] not in ('move', 'pile'): continue |
| 239 | try: |
| 240 | a = int(words[1]) |
| 241 | b = int(words[3]) |
| 242 | except: |
| 243 | continue |
| 244 | if words[2] not in ('onto', 'over'): continue |
| 245 | command = words[0] + words[2].capitalize() |
| 246 | func = getattr(arm, command) |
| 247 | func(a,b) |
| 248 | |
| 249 | def test1(): |
| 250 | s = RealStacks(10) |