Skip to content

Commit

Permalink
rule_file_validator update
Browse files Browse the repository at this point in the history
rule_file_validator.py now will display both the changes in affect and any time an affect or modifier is changed along A*'s path

some fixes to csv file printouts to have them display more information
  • Loading branch information
njunius committed Apr 18, 2023
1 parent 8d77a53 commit d631e1c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
9 changes: 9 additions & 0 deletions tools/response_curve.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
count,init_affect,prev_affect,curr_affect,curr_action,curr_modifier
0,joy,joy,joy,resting,neutral
180,joy,joy,joy,closed_flow,tempo_up
360,joy,joy,sadness,closed_flow,tempo_up
540,joy,sadness,sadness,open_flow,tempo_down
720,joy,sadness,sadness,closed_flow,tempo_up
900,joy,sadness,sadness,open_flow,tempo_down
1080,joy,sadness,fear,resting,tempo_down
1260,joy,fear,fear,resting,tempo_down
24 changes: 19 additions & 5 deletions tools/rule_file_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,34 @@ def main():
response_curve = th.find_all_affect_changes(action_path)
with open('response_curve.csv', 'w', newline = '') as csvfile:
response_writer = csv.writer(csvfile, delimiter = ',', quotechar = '|', quoting = csv.QUOTE_MINIMAL)

start_state, start_action, start_mod, start_affect = action_path[len(action_path) - 1]

response_writer.writerow(['count', 'init_affect', 'prev_affect', 'curr_affect', 'curr_action', 'curr_modifier'])
response_writer.writerow([0, start_affect, start_affect, start_affect, start_action, start_mod]) # add initial state to file

response_writer.writerow(['count', 'init_affect', 'prev_affect', 'curr_affect'])
response_writer.writerow([0, response_curve[0].init_affect, response_curve[0].init_affect, response_curve[0].init_affect]) # add initial state to file
affect_step_cache = 0

for i, node in enumerate(response_curve):
step_diff = node.count
if i > 0:
step_diff = node.count - response_curve[i - 1].count

print('\nnumber of steps to display a new affect: ', step_diff, '\nprevious affect: ', node.prev_affect, '\nnew affect: ', node.curr_affect, '\nit will take ', step_diff / 60, ' seconds for the player to see a new expression in a 60hz update loop')
if node.prev_affect != node.curr_affect:
if affect_step_cache == 0:
step_diff = node.count
else:
step_diff = node.count - affect_step_cache

print('\nnumber of steps to display a new affect: ', step_diff, '\nprevious affect: ', node.prev_affect, '\nnew affect: ', node.curr_affect, '\nit will take ', step_diff / 60, ' seconds for the player to see a new expression in a 60hz update loop', '\naction: ', node.curr_action, '\nmodifier: ', node.curr_mod)
affect_step_cache = node.count
else:
print('\nnumber of steps for a new action or modifier to be used: ', step_diff, '\naction: ', node.curr_action, '\nmodifier: ', node.curr_mod)

response_writer.writerow([node.count, node.init_affect, node.prev_affect, node.curr_affect])
response_writer.writerow([node.count, node.init_affect, node.prev_affect, node.curr_affect, node.curr_action, node.curr_mod])
last_index = len(response_curve) - 1
response_writer.writerow([len(action_path), response_curve[last_index].init_affect, response_curve[last_index].curr_affect, response_curve[last_index].curr_affect]) # add the last step to the file
end = response_curve[last_index]
response_writer.writerow([len(action_path), end.init_affect, end.curr_affect, end.curr_affect, end.curr_action, end.curr_mod]) # add the last step to the file

th.apply_print_path(action_path, character_test, character_av, step_value, verbose)
print('\nfinal affect vector: ', character_av)
Expand Down
17 changes: 15 additions & 2 deletions tools/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,35 @@ def find_first_affect_change(path):
# - the previous expressed affect
# - the currently expressed affect
def find_all_affect_changes(path):
delta_info = collections.namedtuple('delta_info', ['count', 'init_affect', 'prev_affect', 'curr_affect'])
delta_info = collections.namedtuple('delta_info', ['count', 'init_affect', 'prev_affect', 'curr_affect', 'curr_action', 'curr_mod'])

start_node = path[len(path) - 1]
init_affect = start_node[3]
prev_affect = init_affect
prev_action = start_node[1]
prev_mod = start_node[2]
count = 0
curr_affect = None

affect_changes = []

for node in reversed(path):
curr_action = node[1]
curr_mod = node[2]
curr_affect = node[3]
if curr_affect != prev_affect:
temp_node = delta_info._make((count, init_affect, prev_affect, curr_affect))
temp_node = delta_info._make((count, init_affect, prev_affect, curr_affect, curr_action, curr_mod))
affect_changes.append(temp_node)
prev_affect = curr_affect
prev_action = curr_action
prev_mod = curr_mod

elif curr_action != prev_action or curr_mod != prev_mod:
temp_node = delta_info._make((count, init_affect, prev_affect, curr_affect, curr_action, curr_mod))
affect_changes.append(temp_node)
prev_affect = curr_affect
prev_action = curr_action
prev_mod = curr_mod

count += 1

Expand Down

0 comments on commit d631e1c

Please sign in to comment.