git @ Cat's Eye Technologies Nhohnhehr / 9a00e5c
Use integer division to compute which room it is. All tests pass. Chris Pressey 7 months ago
1 changed file(s) with 6 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
187187 room = self.rooms[self.roomCoords((x, y))]
188188 roomX = x % self.roomsize
189189 roomY = y % self.roomsize
190 if DEBUG:
191 sys.stdout.write('XY {}: room {}, roomXY {}\n'.format(
192 (x, y), self.roomCoords((x, y)), (roomX, roomY)
193 ))
190194 return room[roomX, roomY]
191195
192196 def __init__(self, room, io_system):
218222
219223 def roomCoords(self, v):
220224 (x, y) = v
221 return (int(x / self.roomsize), int(y / self.roomsize))
225 return (x // self.roomsize, y // self.roomsize)
222226
223227 def advanceIP(self):
224228 newIP = addvec(self.ip, self.dir)
248252 def step(self):
249253 command = self[self.ip]
250254 if DEBUG:
251 sys.stderr.write('({}) @ {}\n'.format(command, self.ip))
255 sys.stdout.write('({}) @ {}\n'.format(command, self.ip))
252256 ccwrot = {
253257 self.LEFT: self.DOWN,
254258 self.RIGHT: self.UP,