From dc825fb3b542cc90de35589cfc9638d21bead6f8 Mon Sep 17 00:00:00 2001 From: Douglas Hains Date: Mon, 18 Aug 2008 07:00:02 +0000 Subject: [PATCH] added level up attack candidate move registered move in scenario-formula.cfg and added units to test functionality --- data/ai/formula/level_up_attack_eval.fai | 22 +++++++++++++++++++ data/ai/formula/level_up_attack_move.fai | 16 ++++++++++++++ data/scenario-formula.cfg | 28 ++++++++++++++++++++---- 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 data/ai/formula/level_up_attack_eval.fai create mode 100644 data/ai/formula/level_up_attack_move.fai diff --git a/data/ai/formula/level_up_attack_eval.fai b/data/ai/formula/level_up_attack_eval.fai new file mode 100644 index 00000000000..60bbc1de32a --- /dev/null +++ b/data/ai/formula/level_up_attack_eval.fai @@ -0,0 +1,22 @@ +faifile 'level_up_attack_move.fat' + +# Score will be the probability * 100 of attacker unit (me) killing target unit # +# (target) if attacker can level up and if the highest probable outcome # +# is attacker killing target. # + +# function calc_exp returns exp gain for a kill of unit with level# +def calc_exp(level) + if(level = 0, 4, level * 8); + +if(calc_exp(target.level) > (me.max_experience - me.experience), + if(battle_outcome[1].hitpoints_left[0] = 0, + if(battle_outcome[0].hitpoints_left[0] > 0, + if(max(battle_outcome[1].probability) = battle_outcome[1].probability[0], + battle_outcome[1].probability[0] / 100, + -5), + -5), + -5), + -5) +where battle_outcome = calculate_outcome(me.loc, get_best_defense_loc(my_moves.moves, me, target), target.loc) + +faiend diff --git a/data/ai/formula/level_up_attack_move.fai b/data/ai/formula/level_up_attack_move.fai new file mode 100644 index 00000000000..c7c8d7006ad --- /dev/null +++ b/data/ai/formula/level_up_attack_move.fai @@ -0,0 +1,16 @@ +faifile 'level_up_attack_move.fat' + +# If move is chosen, attacker (me) will attack enemy unit (target) from the hex # +# with highest defensive value. This move will only be chosen if the attacker # +# can level up with a kill of target and has a high probability of killing in # +# a single round # + +# 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), + defense_on(attacker.loc, self)); + +attack(me.loc, get_best_defense_loc(my_moves.moves, me, target), target.loc) + +faiend diff --git a/data/scenario-formula.cfg b/data/scenario-formula.cfg index 0dfb66a98cb..2c82b0f111a 100644 --- a/data/scenario-formula.cfg +++ b/data/scenario-formula.cfg @@ -47,8 +47,15 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd recruit=Dwarvish Guardsman,Dwarvish Fighter,Dwarvish Thunderer,Thief,Poacher,Footpad gold=100 controller=human + [unit] + x,y=10,8 + type="Elvish Archer" + hitpoints=1 + generate_description=yes + [/unit] + [/side] - + [side] #controller=human name=FormulaAI @@ -91,17 +98,30 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd type="Ghost" generate_description=yes [/unit] - + [unit] + x,y=10,6 + type="Lich" + experience=149 + generate_description=yes + [/unit] + ai_algorithm=formula_ai [ai] eval_list=yes [register_candidate_move] - name=test - type=test + name=scouting + type=movement action="{ai/formula/scouting_move.fai}" evaluation="{ai/formula/scouting_eval.fai}" [/register_candidate_move] + [register_candidate_move] + name=level_up_attack + type=attack + action="{ai/formula/level_up_attack_move.fai}" + evaluation="{ai/formula/level_up_attack_eval.fai}" + [/register_candidate_move] + [team_formula] rulebase="{ai/formula/opening.fai}" [/team_formula]