def getAction(self): from pygame.locals import K_LEFT, K_RIGHT, K_UP, K_DOWN from pygame.locals import K_ESCAPE, QUIT from ontology import RIGHT, LEFT, UP, DOWN pygame.event.pump() keystate = pygame.key.get_pressed() res = None if keystate[K_RIGHT]: res = BASEDIRS.index(RIGHT) elif keystate[K_LEFT]: res = BASEDIRS.index(LEFT) elif keystate[K_UP]: res = BASEDIRS.index(UP) elif keystate[K_DOWN]: res = BASEDIRS.index(DOWN) if keystate[K_ESCAPE] or pygame.event.peek(QUIT): raise UserTiredException('Pressed ESC') return res
def _nearTileIncrements(self): p0, p1, orient = self.getState()[:3] o0, o1 = orient l0, l1 = BASEDIRS[(BASEDIRS.index(orient) + 1) % len(BASEDIRS)] r0, r1 = BASEDIRS[(BASEDIRS.index(orient) - 1) % len(BASEDIRS)] res = [(True, 1, (p0 + 2 * l0, p1 + 2 * l1)), (True, 2, (p0 + o0 + 2 * l0, p1 + o1 + 2 * l1)), (True, 3, (p0 + 2 * o0 + l0, p1 + 2 * o1 + l1)), (True, 4, (p0 + 2 * o0, p1 + 2 * o1)), (True, 5, (p0 + 2 * o0 + r0, p1 + 2 * o1 + r1)), (True, 6, (p0 + o0 + 2 * r0, p1 + o1 + 2 * r1)), (True, 7, (p0 + 2 * r0, p1 + 2 * r1)), (False, 2, (p0 + o0 + l0, p1 + o1 + l1)), (False, 4, (p0 + o0 + r0, p1 + o1 + r1)), (False, 3, (p0 + o0, p1 + o1)), (False, 1, (p0 + l0, p1 + l1)), (False, 5, (p0 + r0, p1 + r1)), (False, 6, (p0, p1)), ] return res
def _stateNeighbors(self, state): """ Can be different in subclasses... By default: current position and four neighbors. """ pos = (state[0], state[1]) ns = [(a[0] + pos[0], a[1] + pos[1]) for a in BASEDIRS] if self.orientedAvatar: # subjective perspective, so we rotate the view according to the current orientation ns = listRotate(ns, BASEDIRS.index(state[2])) return ns else: return ns
def _nearTileIncrements(self): p0, p1, orient = self.getState()[:3] o0, o1 = orient l0, l1 = BASEDIRS[(BASEDIRS.index(orient) + 1) % len(BASEDIRS)] r0, r1 = BASEDIRS[(BASEDIRS.index(orient) - 1) % len(BASEDIRS)] res = [ (True, 1, (p0 + 2 * l0, p1 + 2 * l1)), (True, 2, (p0 + o0 + 2 * l0, p1 + o1 + 2 * l1)), (True, 3, (p0 + 2 * o0 + l0, p1 + 2 * o1 + l1)), (True, 4, (p0 + 2 * o0, p1 + 2 * o1)), (True, 5, (p0 + 2 * o0 + r0, p1 + 2 * o1 + r1)), (True, 6, (p0 + o0 + 2 * r0, p1 + o1 + 2 * r1)), (True, 7, (p0 + 2 * r0, p1 + 2 * r1)), (False, 2, (p0 + o0 + l0, p1 + o1 + l1)), (False, 4, (p0 + o0 + r0, p1 + o1 + r1)), (False, 3, (p0 + o0, p1 + o1)), (False, 1, (p0 + l0, p1 + l1)), (False, 5, (p0 + r0, p1 + r1)), (False, 6, (p0, p1)), ] return res