wesnoth/data/ai/formula/lib/util.fai
2017-10-01 13:43:27 -07:00

52 lines
No EOL
1 KiB
Text

wfl 'ai/formula/lib/util.fai'
def sumarize_values( input_map )
sum(
values(input_map)
);
def average( input_list )
sum( input_list ) / input_list.size;
def lowest_value( input_map )
choose( input_map, -value ).value;
def highest_value( input_map )
choose( input_map, value ).value;
#
this function takes map with numerical values, and converts it to %:
[ 'a' -> 3, 'b' -> 12, 'c' -> 15 ] becomes [ 'a' -> 10, 'b' -> 40, 'c' -> 50 ]
#
def change_numbers_to_percents( input_map )
map( input_map,
(value*100) / sum
) where sum = sumarize_values(input_map);
def add_number_to_values( input_map, number )
map( input_map,
value + number
);
def multiply_values( input_map, number )
map( input_map,
value * number
);
#make sure we have only positive values in a map #
def make_positive_only( input_map )
if( lowest < 0,
add_number_to_values(
input_map,
-lowest
),
input_map
)
where lowest = lowest_value( input_map );
def sumarize_maps_values( map_A, map_B )
map( map_A + map_B,
value + map_A[key]
);
wflend