FAI files: remove trailing whitespaces

This commit is contained in:
mattsc 2017-10-01 13:43:27 -07:00
parent 6751172282
commit a673e64d44
11 changed files with 170 additions and 170 deletions

View file

@ -5,13 +5,13 @@ wfl 'level_up_attack_move.fai'
# is attacker killing target. #
# function calc_exp returns exp gain for a kill of unit with level#
def calc_exp(level)
def calc_exp(level)
if(level = 0, 4, level * 8);
# function returns best defensive loc reachable by attacker to attack enemy #
def get_best_defense_loc(moves, attacker, enemy)
choose(filter(map(filter(moves, src=attacker.loc), dst),
distance_between(self, enemy.loc) = 1),
choose(filter(map(filter(moves, src=attacker.loc), dst),
distance_between(self, enemy.loc) = 1),
defense_on(attacker, self));
if(calc_exp(target.level) > (me.max_experience - me.experience),

View file

@ -13,8 +13,8 @@ def id_to_location_map(ai*)
#this function returns all input hexes and hexes within some radius of them#
def get_locations_surroundings(ai*, input_locs, range)
sum(
map(input_locs,
locations_in_radius( self, range)
map(input_locs,
locations_in_radius( self, range)
)
);
@ -28,40 +28,40 @@ def get_keeps_with_surroundings(ai*, range)
# evaluate average defense #
#gives map where key is id of terrain, and value is number of hexes of that terrain on a gamemap#
def locations_map(ai*)
tomap(
map(
map.terrain,
id
)
def locations_map(ai*)
tomap(
map(
map.terrain,
id
)
);
#
filters terrain map,
filters terrain map,
min_percent it minimal % of map that terrain has to occupy to be considered in later evaluations
#
def filtered_locations_map(ai*, min_percent)
filter(
locations_map(ai) ,
value > (map.w * map.h) / ( 100 / min_percent )
filter(
locations_map(ai) ,
value > (map.w * map.h) / ( 100 / min_percent )
);
#returns average defense of the unit #
def unit_average_defense(ai*, unit, terrain_min_percent )
sum(
values(
sum(
values(
map(
filtered_locations_map(ai,terrain_min_percent),
defense_on(
unit,
filtered_locations_map(ai,terrain_min_percent),
defense_on(
unit,
find(map.terrain,id=key).loc
) *
value
)
)
) /
)
)
) /
sum(
values(
filtered_locations_map(
@ -73,32 +73,32 @@ def unit_average_defense(ai*, unit, terrain_min_percent )
#returns map of units from units_list and their average defense (more -> better) #
def map_units_average_defense(ai*, units_list, terrain_min_percent)
def map_units_average_defense(ai*, units_list, terrain_min_percent)
tomap(
map(
units_list,
id
),
map(
units_list, 'unit',
map(
units_list,
id
),
map(
units_list, 'unit',
unit_average_defense(
ai,
unit,
terrain_min_percent
)
)
ai,
unit,
terrain_min_percent
)
)
);
def units_average_defense(ai*, units_list, terrain_min_percent)
sum(
map(
units_list, 'unit',
map(
units_list, 'unit',
unit_average_defense(
ai,
unit,
terrain_min_percent
)
)
ai,
unit,
terrain_min_percent
)
)
) /
size(
units_list

View file

@ -11,21 +11,21 @@ def recruit_army(ai*,unit_map)
unit_map[unit_type] -
(
(
100 *
100 *
size(
filter(
my_units,
my_units,
type = unit_type
)
)
) /
) /
size(my_units)
)
) >= 0
),
value
);

View file

@ -24,23 +24,23 @@ def change_numbers_to_percents( input_map )
) where sum = sumarize_values(input_map);
def add_number_to_values( input_map, number )
map( input_map,
value + number
map( input_map,
value + number
);
def multiply_values( input_map, number )
map( input_map,
value * 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,
if( lowest < 0,
add_number_to_values(
input_map,
-lowest
),
input_map
),
input_map
)
where lowest = lowest_value( input_map );

View file

@ -14,9 +14,9 @@ def get_villages_on_terrain_map( ai*, locations_map )
# Returns location_map with the area around important villages set to 1000 (radius 1) #
def mark_important_locations(ai*, location_map )
map( location_map,
if( tmp_villages[key],
1000,
map( location_map,
if( tmp_villages[key],
1000,
value
)
)
@ -26,8 +26,8 @@ def mark_important_locations(ai*, location_map )
# Returns a list of ALL keys(locs) of side_terrain #
def get_important_locations(ai* )
keys(
map( ai.vars.side_terrain,
value >= 1000
map( ai.vars.side_terrain,
value >= 1000
)
);
@ -144,9 +144,9 @@ def current_enemies(ai*)
# Returns a integer. #
# Returns the sum of 12 times the maximum attack damage for all enemy_units #
def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
sum(
map(
enemy_units, 'enemy_unit',
sum(
map(
enemy_units, 'enemy_unit',
sum( # sum over all 4 elements (which are the same). 3 * 4 = 12. #
map(
[
@ -159,7 +159,7 @@ def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
self[1]
]
)*3 # Replaces all 4 elements in the list with 3 times the maximum of self[0] and self[1]. #
)
)
)
)
);
@ -169,9 +169,9 @@ def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
# This time the atacker can defend himself. The defender will chose the attack with the best #
# damage difference #
def evaluate_defender_against_opponents(ai*, unit, enemy_units)
sum(
map(
enemy_units, 'enemy_unit',
sum(
map(
enemy_units, 'enemy_unit',
sum(
map(
[
@ -183,7 +183,7 @@ def evaluate_defender_against_opponents(ai*, unit, enemy_units)
self[1] - self[3]
]
)*5
)
)
)
)
);
@ -297,13 +297,13 @@ def calculate_recruits(ai*)
change_numbers_to_percents(
combine_maps_sub(
combine_maps_add(
combine_maps_add(
combine_maps_add(
debug_print('defense_hp_eval ', defense_hp_eval(ai, recruits_id_map ) ),
debug_print('movement_eval ', movement_eval(ai, recruits_id_map) )
),
debug_print('fighting_eval ', multiply_values(
fighting_eval(ai,recruits_id_map), 5
)
)
)
),
combine_maps_add(
@ -315,7 +315,7 @@ def calculate_recruits(ai*)
def do_recruitment( ai* )
if( unit_to_recruit,
safe_call(
safe_call(
recruit( unit_to_recruit ),
end
),

View file

@ -1,12 +1,12 @@
def opening(ai*)
if(turn = 1, [
def opening(ai*)
if(turn = 1, [
recruit('Skeleton Archer', loc(11,21)),
recruit('Dark Adept', loc(11,22)),
recruit('Dark Adept', loc(10,22)),
recruit('Skeleton Archer', loc(9,22)),
recruit('Ghost', loc(11,24)),
move(loc(11,23), loc(14,22)) ],
if(turn = 2, [
if(turn = 2, [
move(loc(11,21),loc(13,17)),
if(unit_at(loc(11,22)).max_moves = 6,
move(loc(11,22),loc(13,18)),
@ -26,89 +26,89 @@ def opening(ai*)
recruit('Skeleton Archer', loc(11,21)) ],
[]))));
def rate_position_defensiveness(ai*,src,dst)
units_can_reach(ai.my_moves, dst).size - units_can_reach(ai.enemy_moves, dst).size;
def rate_position_defensiveness(ai*,src,dst)
units_can_reach(ai.my_moves, dst).size - units_can_reach(ai.enemy_moves, dst).size;
def rate_position_danger(ai*,unit,dst)
(100*sum(map(units_can_reach(ai.enemy_moves, dst), 'enemy', max_possible_damage(enemy, unit)*defense_on(unit, dst)))) / unit.hitpoints;
def rate_position_danger(ai*,unit,dst)
(100*sum(map(units_can_reach(ai.enemy_moves, dst), 'enemy', max_possible_damage(enemy, unit)*defense_on(unit, dst)))) / unit.hitpoints;
def build_attacks(attack_move)
if(attack_move,
map(attack_move.movements, attack(src, dst, attack_move.target)),
[]); def targets(ai)
ai.enemy_and_unowned_villages;
def build_attacks(attack_move)
if(attack_move,
map(attack_move.movements, attack(src, dst, attack_move.target)),
[]); def targets(ai)
ai.enemy_and_unowned_villages;
def distance_to_target(ai,dst)
min(map(targets(ai), distance_between(dst, self)));
def distance_to_target(ai,dst)
min(map(targets(ai), distance_between(dst, self)));
def move_to_targets(ai*)
def move_to_targets(ai*)
find(moves, src != my_leader.loc and rate_position_defensiveness(ai, src, dst) > 0)
where moves = sort(my_moves.moves, distance_to_target(ai, a.dst) < distance_to_target(ai, b.dst));
where moves = sort(my_moves.moves, distance_to_target(ai, a.dst) < distance_to_target(ai, b.dst));
def get_village_captures(ai)
sum(map(ai.enemy_and_unowned_villages, 'village', map(units_can_reach(ai.my_moves, village), move(loc, village))), []);
def get_village_captures(ai)
sum(map(ai.enemy_and_unowned_villages, 'village', map(units_can_reach(ai.my_moves, village), move(loc, village))), []);
def get_village_garrisons(ai*)
sum(map(my_villages, 'village', map(units_can_reach(ai.my_moves, village), move(loc, village))), []);
def get_village_garrisons(ai*)
sum(map(my_villages, 'village', map(units_can_reach(ai.my_moves, village), move(loc, village))), []);
def uncontended_captures(ai)
filter(get_village_captures(ai), (src != ai.my_leader.loc) and (units_can_reach(ai.enemy_moves, dst).empty));
def uncontended_captures(ai)
filter(get_village_captures(ai), (src != ai.my_leader.loc) and (units_can_reach(ai.enemy_moves, dst).empty));
def move_to_keep(ai*)
if(keep_in_range,
move(my_leader.loc, keep_in_range),
def move_to_keep(ai*)
if(keep_in_range,
move(my_leader.loc, keep_in_range),
null())
where keep_in_range = find(unit_moves(my_leader.loc), 'moveto', find(keeps, moveto = self));
where keep_in_range = find(unit_moves(my_leader.loc), 'moveto', find(keeps, moveto = self));
def village_value(ai*) 400;
def village_value(ai*) 400;
def rate_healing(unit*)
value * ((min(max_hitpoints - hitpoints, 8)*100)/max_hitpoints);
def rate_healing(unit*)
value * ((min(max_hitpoints - hitpoints, 8)*100)/max_hitpoints);
def rate_village_garrison(ai*, move_from, village)
if(find(enemy_moves, dst = village),
village_value(ai),
def rate_village_garrison(ai*, move_from, village)
if(find(enemy_moves, dst = village),
village_value(ai),
0);
def rate_village_capture(ai*,src,dst) village_value(ai);
def rate_village_capture(ai*,src,dst) village_value(ai);
def rate_village_proximity(ai*, unit, dst)
if(distance = 1,
0,
def rate_village_proximity(ai*, unit, dst)
if(distance = 1,
0,
village_value(ai)/(distance/unit.max_moves + 1))
where distance = distance_to_nearest_unowned_village(dst);
where distance = distance_to_nearest_unowned_village(dst);
def rate_move(ai*,src,dst)
if(is_village(map, dst),
rate_healing(u) + if(find(my_villages, self = dst),
rate_village_garrison(ai, src, dst),
rate_village_capture(ai, src, dst)),
def rate_move(ai*,src,dst)
if(is_village(map, dst),
rate_healing(u) + if(find(my_villages, self = dst),
rate_village_garrison(ai, src, dst),
rate_village_capture(ai, src, dst)),
rate_village_proximity(ai, u, dst)) - (danger*u.value)/2
where u = unit_at(src), danger = rate_position_danger(ai, unit_at(src), dst);
where u = unit_at(src), danger = rate_position_danger(ai, unit_at(src), dst);
def rate_attack(ai*,attack)
if(attack,
(attack.chance_to_kill*attack.target_value + (((attack.avg_damage_inflicted*100)/unit_at(attack.target).max_hitpoints)*attack.target_value) + sum(map(attack.movements, rate_move(ai, src, dst))))/attack.movements.size,
null());
def rate_attack(ai*,attack)
if(attack,
(attack.chance_to_kill*attack.target_value + (((attack.avg_damage_inflicted*100)/unit_at(attack.target).max_hitpoints)*attack.target_value) + sum(map(attack.movements, rate_move(ai, src, dst))))/attack.movements.size,
null());
def get_best_move(ai*, candidate_moves)
if(rate_attack(ai, best_attack) >
if(best_move, rate_move(ai, best_move.src,
best_move.dst),
def get_best_move(ai*, candidate_moves)
if(rate_attack(ai, best_attack) >
if(best_move, rate_move(ai, best_move.src,
best_move.dst),
0),
build_attacks(best_attack),
build_attacks(best_attack),
[best_move])
where best_attack = choose(attacks, rate_attack(ai, self)),
best_move = choose(candidate_moves, rate_move(ai, src, dst));
best_move = choose(candidate_moves, rate_move(ai, src, dst));
def move_leader_to_keep(ai*)
if(dest,
[move(my_leader.loc, dest)],
def move_leader_to_keep(ai*)
if(dest,
[move(my_leader.loc, dest)],
[])
where dest = find(unit_moves(my_leader.loc), 'dst', find(keeps, 'keep', keep = dst));
where dest = find(unit_moves(my_leader.loc), 'dst', find(keeps, 'keep', keep = dst));
if(vars.turn_opening != turn,
if(vars.turn_opening != turn,
[set_var('turn_opening', turn)] + opening(self),
if(my_leader.loc and find(keeps, self = my_leader.loc) = null(),
move_leader_to_keep(self),
if(my_leader.loc and find(keeps, self = my_leader.loc) = null(),
move_leader_to_keep(self),
[]) + get_best_move(self, filter(my_moves.moves, src != my_leader.loc)) + [ recruit('Skeleton Archer', loc(11,21)), recruit('Dark Adept', loc(11,22)) ])

View file

@ -21,7 +21,7 @@ def step_move(me)
)
)
where desired_path = shortest_path( me.loc, me.vars.next_step );
where desired_path = shortest_path( me.loc, me.vars.next_step );
def move_ahead(ai*, me)
if( enemy_units,
@ -46,7 +46,7 @@ def patrol_move(ai*, me)
me.vars.waypoints[ me.vars.next_step ],
me.loc
),
move_ahead(ai,me)
);
@ -58,15 +58,15 @@ if( me.moves = 0,
)
)
where attack = if( path_to,
if(path_to.size <= me.vars.guard_radius,
attack( me.loc, path_to.last, closest_unit(self, me).loc ),
0
where attack = if( path_to,
if(path_to.size <= me.vars.guard_radius,
attack( me.loc, path_to.last, closest_unit(self, me).loc ),
0
),
0
)
where path_to = if( enemy_units,
where path_to = if( enemy_units,
shortest_path( me.loc, closest_unit(self, me).loc ),
[]
)

View file

@ -4,11 +4,11 @@ wfl 'poisoner_eval.fai'
#rate units with regeneration as worse targets #
if( find( villages, self = target.loc ), -10, 0 ) +
# units next to healers/curers are also bad targets #
min( map(
filter(
map( adjacent_locs(target.loc),
unit_at(self)
),
min( map(
filter(
map( adjacent_locs(target.loc),
unit_at(self)
),
'unit', index_of(unit.side, enemies) != -1 and unit.abilities
), 'unit_with_sp',
if( index_of('healing',unit_with_sp.abilities) != -1, -5, 0 ) +

View file

@ -14,9 +14,9 @@ def get_villages_on_terrain_map( ai*, locations_map )
for now important locations are villages only
#
def mark_important_locations(ai*, location_map )
map( location_map,
if( tmp_villages[key],
1000,
map( location_map,
if( tmp_villages[key],
1000,
value
)
)
@ -24,8 +24,8 @@ def mark_important_locations(ai*, location_map )
def get_important_locations(ai* )
keys(
map( ai.vars.side_terrain,
value >= 1000
map( ai.vars.side_terrain,
value >= 1000
)
);
@ -141,9 +141,9 @@ def current_enemies(ai*)
def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
sum(
map(
enemy_units, 'enemy_unit',
sum(
map(
enemy_units, 'enemy_unit',
sum(
map(
[
@ -155,15 +155,15 @@ def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
self[1]
]
)*3
)
)
)
)
);
def evaluate_defender_against_opponents(ai*, unit, enemy_units)
sum(
map(
enemy_units, 'enemy_unit',
sum(
map(
enemy_units, 'enemy_unit',
sum(
map(
[
@ -175,7 +175,7 @@ def evaluate_defender_against_opponents(ai*, unit, enemy_units)
self[1] - self[3]
]
)*5
)
)
)
)
);
@ -270,13 +270,13 @@ def calculate_recruits(ai*)
change_numbers_to_percents(
combine_maps_sub(
combine_maps_add(
combine_maps_add(
combine_maps_add(
defense_hp_eval(ai, recruits_id_map ),
movement_eval(ai, recruits_id_map)
),
multiply_values(
fighting_eval(ai,recruits_id_map), 5
)
)
),
combine_maps_add(
consider_unit_cost(ai),
@ -285,20 +285,20 @@ def calculate_recruits(ai*)
)
) where recruits_id_map = map(my_recruits, id);
def unit_chooser(ai*,unit_map)
def unit_chooser(ai*,unit_map)
choose(
keys(unit_map), 'unit_type',
unit_map[unit_type] -
unit_map[unit_type] -
(
(
100 *
100 *
size(
filter(
my_units,
my_units,
type = unit_type
)
)
) /
) /
size(my_units)
)
);
@ -306,11 +306,11 @@ def unit_chooser(ai*,unit_map)
if( vars.side_terrain,
if(vars.direct_enemies,
if(vars.turn_initialized = turn,
safe_call( recruit(unit_chooser(self, vars.recruits_map)),
end
),
[
set_var(debug_print('turn_initialized'), turn) ,
set_var(debug_print('recruits_map'), calculate_recruits(self))

View file

@ -2,12 +2,12 @@ wfl 'scouting_eval.fai'
if(me.loc = my_leader.loc,
-5,
if( size(shroud) = 0,
if( size(shroud) = 0,
-5,
if( size(enemies_in_range) != 0,
-5,
if( me.max_moves > 5,
50,
if( me.max_moves > 5,
50,
-5))))
where enemies_in_range = filter( enemy_units, 'enemy', distance_between( me.loc, enemy.loc ) < me.max_moves),
shroud = find_shroud()

View file

@ -1,6 +1,6 @@
wfl 'scouting_move.fai'
if(size(villages) != 0,
if(size(villages) != 0,
move(me.loc, nearest_loc(nearest_loc(me.loc,villages),unit_moves(me.loc))),
move(me.loc, nearest_loc(nearest_loc(me.loc,shroud),unit_moves(me.loc))))
where villages = filter(unit_moves(me.loc),is_unowned_village(map,x,y)),