Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tetov committed Aug 6, 2024
1 parent 9a0274e commit c56d218
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
25 changes: 14 additions & 11 deletions bdm_voxel_builder/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
26 changes: 15 additions & 11 deletions bdm_voxel_builder/agent_algorithms/algo_8_e_build_ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ####################################################
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion bdm_voxel_builder/helpers/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c56d218

Please sign in to comment.