def test_post_process_absolute_loc(self): loc = Absolute('room') move = Move(Speed.NORMAL, loc, None) expected = Composite( [move, ThroughDoor(ObjectRelativeDirection.VICINITY)]) self.assertEqual(move.post_processed(), expected)
def game_input(key, mouse_x, mouse_y, player, current_map, camera, fov, under_mouse, widgets, animations, animation_data, game_state): if key == terminal.TK_MOUSE_LEFT: mouse_x, mouse_y = mouse_to_camera(mouse_x, mouse_y, camera) if game_state == game_state.players_turn: if under_mouse in current_map.actors: if under_mouse.alive: if player.distance_to( under_mouse) < player.alive.get_range(): return Attack(player, under_mouse, is_player=True) elif under_mouse in current_map.items: return Move(player, under_mouse, current_map, fov, True, pickup_item=under_mouse) # Default to move if no other option is approiate. if under_mouse and under_mouse != player: return Move(player, under_mouse, current_map, fov, True) elif key == terminal.TK_SPACE: return 'end-turn' elif key == terminal.TK_I: return 'toggle-inventory' elif key == terminal.TK_TAB: return 'toggle-map' elif key == terminal.TK_R: return 'restart' elif key == terminal.TK_T: return 'debug' elif key == terminal.TK_CLOSE or key == terminal.TK_ESCAPE: exit()
def giant_spider(actor, target, current_map, fov): # A basic ai that chases the target until close enough to attack. if actor.distance_to(target) < 2: # Within range to attack if actor.alive.get_ap(False) >= actor.alive.get_attack_cost(): return Attack(actor, target) else: # Not in range so chase. if actor.alive.get_ap(False) >= actor.alive.get_movement_cost(): return Move(actor, target, current_map, fov) # If no action was taken, recover ap as its the end of the actors turn. actor.alive.recover_ap() return None
def actions_for_recipe(recipe): """Returns the actions necessary to make the given recipe. recipe: manual_db.Recipe """ logging.info("Enqueuing actions for recipe %s", recipe) actions = [] for ingredient in recipe.ingredients: valve = ingredients.INGREDIENTS_ORDERED.index(ingredient.name.lower()) actions.append(Move(valve_position(valve))) if hasattr(ingredient.qty, 'drops'): actions.append( MeterBitters(valve_to_actuate=valve, drops_to_meter=ingredient.qty.drops)) elif hasattr(ingredient.qty, 'oz'): actions.append( Meter(valve_to_actuate=valve, oz_to_meter=ingredient.qty.oz)) else: raise Exception("Ingredient %s has no quantity for recipe %s:\n%s", ingredient.name, recipe.name, recipe) actions.append(Move(0.0)) actions.append(Home(carefully=False)) return actions
def __init__(self): """ init """ rospy.init_node('Robot') super(Robot, self).__init__() ''' actions ''' self.actions.add_action('face', Face(self)) self.actions.add_action('goto', Goto(self)) self.actions.add_action('gotopose', GotoPose(self)) self.actions.add_action('hear', Hear(self)) self.actions.add_action('move', Move(self)) self.actions.add_action('pose', Pose(self)) self.actions.add_action('talk', Talk(self)) # self.actions.add_action('follow', Follow(self)) self.actions.add_action('savelocal', SaveLocal(self)) self.actions.add_action('head', Head(self)) ''' services ''' s = rospy.Service('question', question, self.handle_question)
def test_post_process_no_change(self): loc = Directional(MoveDirection.FORWARDS, Distance.MEDIUM) move = Move(Speed.NORMAL, loc, None) self.assertEqual(move.post_processed(), move)
def test_post_processed_basement(self): loc = Absolute('basement') move = Move(Speed.NORMAL, loc, None) self.assertEqual(move.post_processed(), move)
def test_post_processed_ground_floor(self): loc = Absolute('ground') move = Move(Speed.NORMAL, loc, None) self.assertEqual(move.post_processed(), move)
def post(self): print self.request controller.EnqueueGroup([Move(float(self.request.get('text')))])