diff --git a/bdm_voxel_builder/agent.py b/bdm_voxel_builder/agent.py index f3cd29e..a04096b 100644 --- a/bdm_voxel_builder/agent.py +++ b/bdm_voxel_builder/agent.py @@ -114,7 +114,6 @@ def analyze_relative_position(self, grid: Grid): self.relative_booleans_bottom_up = [below, aside, above] return below, aside, above - def direction_preference_6_pheromones(self, x=0.5, up=True): """up = 1 side = x @@ -579,7 +578,7 @@ def move_on_ground_by_ph_cube( # print('choice:', choice) new_pose = cube[choice] # print('new_pose:', new_pose) - + if self.save_move_history: v = new_pose - self.pose self.move_history.append(v) @@ -802,25 +801,29 @@ def get_chance_by_pheromone_strength( return v * strength else: return 0 - + def match_vertical_move_history_string( - self, last_moves_pattern = ['up', 'up', 'side'], value = 1 + self, last_moves_pattern=("up", "up", "side"), value=1 ): "chance is returned based on the direction values and chance_weight" n = len(last_moves_pattern) for i in range(n): x, y, z = self.move_history[-i] pattern = last_moves_pattern[-i] - if pattern == 'up' and z > 0: - flag = True - elif pattern == 'side' and z == 0: + if ( + pattern == "up" + and z > 0 + or pattern == "side" + and z == 0 + or pattern == "down" + and z < 0 + ): flag = True - elif pattern == 'down' and z < 0: - flag = True - else: flag = False + else: + flag = False if flag: return value - else: + else: return 0 # BUILD/ERASE FUNCTIONS diff --git a/bdm_voxel_builder/agent_algorithms/algo_8_e_build_ridge.py b/bdm_voxel_builder/agent_algorithms/algo_8_e_build_ridge.py index 423dcbe..d5c8db8 100644 --- a/bdm_voxel_builder/agent_algorithms/algo_8_e_build_ridge.py +++ b/bdm_voxel_builder/agent_algorithms/algo_8_e_build_ridge.py @@ -244,8 +244,12 @@ def move_agent(self, agent: Agent, state: Environment): move_pheromon_cube = agent.get_direction_cube_values_for_grid( pheromon_grid_move, 1 ) - directional_bias_cube_up = agent.direction_preference_26_pheromones_v2(1, 0.5, 0.1) - directional_bias_cube_side = agent.direction_preference_26_pheromones_v2(0.1, 1, 0.5) + directional_bias_cube_up = agent.direction_preference_26_pheromones_v2( + 1, 0.5, 0.1 + ) + directional_bias_cube_side = agent.direction_preference_26_pheromones_v2( + 0.1, 1, 0.5 + ) ############################################################################ # CHANGE MOVE BEHAVIOUR #################################################### @@ -302,27 +306,25 @@ def calculate_build_chances(self, agent: Agent, state: Environment): ########################################################################## # build probability settings ############################################# ########################################################################## - low_density__build_reward = 0 #0.1 + low_density__build_reward = 0 # 0.1 low_density__erase_reward = 0 - normal_density__build_reward = 0 #0.3 + normal_density__build_reward = 0 # 0.3 normal_density__erase_reward = 0 high_density__build_reward = 0 high_density__erase_reward = 1.5 step_on_ridge_reward = 1.5 - step_on_ridge_moves_pattern = ['side', 'up', 'up'] + step_on_ridge_moves_pattern = ["side", "up", "up"] ########################################################################## - - # get clay density clay_density = agent.get_grid_density(grid) dense_mod = clay_density + 0.2 clay_density_filled = agent.get_grid_density(grid, nonzero=True) - + # set chances based on clay density if 1 / 26 <= clay_density_filled < 3 / 26: build_chance += low_density__build_reward * dense_mod @@ -333,10 +335,12 @@ def calculate_build_chances(self, agent: Agent, state: Environment): elif clay_density_filled >= 4 / 5: build_chance += high_density__build_reward * dense_mod erase_chance += high_density__erase_reward - + # set chances based on movement pattern __ - movement_pattern_gain = agent.match_vertical_move_history_string(step_on_ridge_moves_pattern, step_on_ridge_reward) - if 1/26 <= clay_density_filled: + movement_pattern_gain = agent.match_vertical_move_history_string( + step_on_ridge_moves_pattern, step_on_ridge_reward + ) + if clay_density_filled >= 1 / 26: build_chance += movement_pattern_gain # update probabilities diff --git a/bdm_voxel_builder/helpers/geometry.py b/bdm_voxel_builder/helpers/geometry.py index 7fa0b0b..7887d5a 100644 --- a/bdm_voxel_builder/helpers/geometry.py +++ b/bdm_voxel_builder/helpers/geometry.py @@ -61,7 +61,6 @@ def _get_xform_box2grid( return Sc, R, Tl - def get_translation_box2grid( box: cg.Box, grid_size: tuple[int, int, int] ) -> cg.Translation: