made it so one can have multiple test scenarios...

...and specify a test scenario as an option. Added formula test scenario as one such option.
This commit is contained in:
David White 2008-03-06 05:14:32 +00:00
parent 878f5a32a5
commit 21376e678b
3 changed files with 247 additions and 2 deletions

View file

@ -12,6 +12,7 @@
#else
{campaigns/}
{scenario-test.cfg}
{scenario-formula.cfg}
[textdomain]
name="wesnoth"
[/textdomain]

238
data/scenario-formula.cfg Normal file
View file

@ -0,0 +1,238 @@
# @file data/scenario-test.cfg
#textdomain wesnoth
[test]
name="Test scenario"
map_data="
border_size=1
usage=map
Hh , Hh , Gg , Wwf , Wwf , Gs^Fp , Mm , Hh , Gg , Gs^Fp , Gg , Hh , Gg , Mm , Hh , Mm , Wwf , Wwf , Hh , Gs^Fp , Hh , Mm , Mm
Hh , Hh , Gg^Ve , Wwf , Wwf , Gs^Fp , Mm , Hh , Gg , Gs^Fp , Gg , Hh , Gg , Mm , Hh , Mm , Wwf , Wwf , Hh , Gs^Fp , Hh , Mm , Mm
Wwf , Wwf , Wwf , Wwf , Gg , Wwf , Wwf , Hh , Gg , Gg , Wwf , Ch , Wwf , Gs^Fp , Wwf , Wwf , Re , Re , Hh , Mm , Wwf , Mm , Mm
Mm , Mm , Wwf , Gs^Fp , Gg^Vh , Wwf , Gg , Gg , Wwf , Wwf , Wwf , 1 Kh , Ch , Wwf , Re , Re , Rd , Rd , Wwf , Wwf , Gs^Fp , Wwf , Wwf
Wwf , Wwf , Mm , Wwf , Gs^Fp , Wwf , Wwf , Wwf , Gg^Vh , Gg , Wwf , Ch , Wwf , Ch , Rd , Rd , Wwf , Wwf , Gg^Vh , Gs^Fp , Re^Gvs , Hh , Hh
Hh , Hh , Wwf , Gs^Fp , Wwf , Wwf , Gg , Gg , Gg , Gg , Wwf , Ch , Gg , Wwf , Wwf , Wwf , Mm , Gs^Fp , Re , Re^Gvs , Gg^Wm , Re^Gvs , Re^Gvs
Wwf , Wwf , Mm , Wwf , Hh , Gs^Fp , Rd , Rd , Gg , Gg , Wwf , Wwf , Gs^Fp , Gg , Hh , Gg , Re , Re , Rd , Rd , Gg , Hh , Hh
Hh , Hh , Gs^Fp , Gg , Gg , Rd , Gg , Gg , Wwf , Wwf , Gs^Fp , Wwf , Gs^Fp , Mm , Re , Re , Rd , Rd , Gg , Ggf , Mm , Gs^Fp , Gs^Fp
Gs^Fp , Gs^Fp , Gg , Gg , Wwf , Gg , Wwf , Wwf , Mm , Hh , Wwf , Wwf , Re , Re , Rd , Rd , Rd , Gg , Gs^Fp , Gs^Fp , Gs^Fp , Hh , Hh
Hh , Hh , Wwf , Wwf , Hh , Wwf , Gg , Gg , Gg , Gg , Wwf , Re , Re , Rd , Gg , Gg , Gg , Gg^Vh , Hh , Gg , Wwf , Ggf , Ggf
Wwf , Wwf , Hh , Ggf , Gs^Fp , Hh^Vhh , Gg , Gg , Gg , Ss^Vhs , Hh , Ww , Gs^Fp , Gg , Gs^Fp , Hh , Wwf , Wwf , Wwf , Wwf , Gg , Wwf , Wwf
Hh , Hh , Gg , Gg , Re , Gg , Re , Re , Gg , Ss , Gs^Fp , Ww , Hh , Mm , Ww , Wwf , Gg , Gg , Ds , Gg , Gg , Gs^Fp , Gs^Fp
Gs^Fp , Gs^Fp , Gg , Rd , Rd , Re , Rd , Re , Hh , Mm , Wwf , Ww , Ww , Ww , Gg , Gg , Hh , Gs^Fp , Rd , Rd , Hh , Gg , Gg
Rd , Rd , Gs^Fp , Hh , Rd , Rd , Gs^Fp , Re , Gg , Gg , Wwf , Gg , Wwf , Gg , Gg , Re , Gs^Fp , Hh , Rd , Mm , Gs^Fp , Rd , Rd
Rd , Rd , Hh , Mm , Rd , Hh , Hh , Re , Gg , Gg , Ww , Gg , Wwf , Gg , Hh , Re , Rd , Rd , Rd , Hh , Gg , Rd , Rd
Gg , Gg , Gg , Rd , Ds , Gs^Fp , Gg , Gg , Ww , Ww , Hh , Ww , Gs^Fp , Mm , Gg , Re , Re , Re , Re , Rd , Gg , Gs^Fp , Gs^Fp
Gs^Fp , Gs^Fp , Gg , Gg , Wwf , Gg , Wwf , Wwf , Gs^Fp , Mm , Gs^Fp , Ww , Hh , Ss , Gg , Re , Gg , Gg , Gs^Fp , Gg , Hh , Hh , Hh
Wwf , Wwf , Wwf , Wwf , Hh , Wwf , Gg , Hh , Gg , Gg , Re , Ww , Wwf , Ss^Vhs , Gg , Gg , Gg , Hh^Vhh , Hh , Ggf , Wwf , Wwf , Wwf
Ggf , Ggf , Gs^Fp , Gg , Gs^Fp , Gg^Vh , Rd , Gg , Rd , Rd , Re , Re , Wwf , Gg , Mm , Gg , Wwf , Wwf , Wwf , Wwf , Gg , Mm , Mm
Hh , Hh , Mm , Gs^Fp , Gg , Gg , Rd , Rd , Re , Re , Gs^Fp , Wwf , Gs^Fp , Hh , Wwf , Wwf , Gg , Gg , Gg , Gg , Gs^Fp , Gs^Fp , Gs^Fp
Gs^Fp , Gs^Fp , Gg , Ggf , Rd , Rd , Re , Re , Hh , Mm , Gg , Wwf , Wwf , Wwf , Gg , Gg , Rd , Rd , Hh , Gg , Mm , Hh , Hh
Hh , Hh , Gg^Wm , Rd , Re , Re , Mm , Gg , Wwf , Wwf , Wwf , Ch , Gg , Gg , Gg , Rd , Gg , Gs^Fp , Wwf , Wwf , Wwf , Wwf , Wwf
Re^Gvs , Re^Gvs , Re^Gvs , Re^Gvs , Gg^Vh , Gs^Fp , Wwf , Wwf , Rd , Ch , Ch , Ch , Gg , Gg , Gg^Vh , Gg , Wwf , Wwf , Gs^Fp , Gs^Fp , Gg^Ve , Gg , Gg
Hh , Hh , Gs^Fp , Gs^Fp , Wwf , Wwf , Rd , Rd , Re , Re , Wwf , 2 Kh , Wwf , Gg , Wwf , Wwf , Gg , Wwf , Wwf , Wwf , Wwf , Gs^Fp , Gs^Fp
Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd , Gs^Fp , Hh , Wwf , Wwf , Gg , Ch , Gg , Wwf , Hh , Gg , Wwf , Wwf , Gg^Vh , Gg , Wwf , Mm , Mm
Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd , Gs^Fp , Wwf , Wwf , Gg , Gg , Gg , Gg , Gg , Hh , Gg , Wwf , Wwf , Gg , Gg , Wwf , Mm , Mm
"
turns=90
id=formula
{DEFAULT_SCHEDULE}
[side]
type=Dwarvish Steelclad
side=1
canrecruit=1
recruit=Dwarvish Guardsman,Dwarvish Fighter,Dwarvish Thunderer,Thief,Poacher,Footpad
gold=100
# controller=human
[/side]
[side]
# controller=human
type=Dark Sorcerer
side=2
canrecruit=1
recruit=Skeleton,Skeleton Archer,Walking Corpse,Ghost,Vampire Bat,Dark Adept,Ghoul
gold=100
ai_algorithm=formula_ai
[ai]
[function]
name=opening
inputs="ai"
formula="
if(ai.turn = 1,
#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(ai.turn = 2,
#turn 2
[ move(loc(11,21),loc(13,17)),
if(unit_at(loc(11,22)).total_movement = 6,
move(loc(11,22),loc(13,18)),
move(loc(11,22),loc(15,19))),
move(loc(10,22),loc(7,19)),
move(loc(9,22),loc(4,22)),
move(loc(11,24),loc(18,24)),
move(loc(14,22),loc(11,23)),
recruit('Dark Adept', loc(11,21)),
recruit('Dark Adept', loc(11,22)) ],
if(ai.turn = 3,
#turn 3
[ move(loc(18,24),loc(20,22)),
move(loc(15,19),loc(17,17)),
move(loc(4,22),loc(5,18)),
recruit('Skeleton Archer', loc(11,21)) ],
if(ai.turn = 4,
#turn 4
[ recruit('Skeleton Archer', loc(11,21)) ],
[]))))"
[/function]
[function]
name=rate_position_defensiveness
inputs="ai*,src,dst"
formula="units_can_reach(ai.my_moves, dst).size - units_can_reach(ai.enemy_moves, dst).size"
[/function]
[function]
name=rate_position_danger
inputs="ai*,unit,dst"
formula="(100*sum(map(units_can_reach(ai.enemy_moves, dst), 'enemy', max_possible_damage(enemy, unit)*defense_on(unit, dst)))) / unit.hitpoints"
[/function]
[function]
name=build_attacks
inputs=attack_move
formula="if(attack_move, map(attack_move.movements, attack(src, dst, attack_move.target)), [])"
[/function]
[function]
name=targets
inputs="ai"
formula="ai.enemy_and_unowned_villages"
[/function]
[function]
name=distance_to_target
inputs="ai,dst"
formula="min(map(targets(ai), distance_between(dst, self)))"
[/function]
[function]
name=move_to_targets
inputs=ai*
formula="
find(moves, src != my_leader 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))"
# if(moves, choose(moves, -distance_to_target(ai, dst)), null())
# where moves = filter(my_moves.moves, src != my_leader and rate_position_defensiveness(ai, src, dst) > 0)
[/function]
[function]
name=get_village_captures
inputs="ai"
formula="
sum(map(ai.enemy_and_unowned_villages, 'village', map(units_can_reach(ai.my_moves, village), move(loc, village))), [])"
[/function]
[function]
name=get_village_garrisons
inputs="ai*"
formula="
sum(map(my_villages, 'village', map(units_can_reach(ai.my_moves, village), move(loc, village))), [])"
[/function]
[function]
name=uncontended_captures
inputs=ai
formula="filter(get_village_captures(ai), (src != ai.my_leader) and (units_can_reach(ai.enemy_moves, dst).empty))"
[/function]
[function]
name=move_to_keep
inputs="ai*"
formula="if(keep_in_range, move(my_leader, keep_in_range), null())
where keep_in_range = find(unit_moves(my_leader), 'moveto', find(keeps, moveto = self))"
[/function]
[function]
name=village_value
inputs="ai*"
formula="400"
[/function]
[function]
name=rate_healing
inputs="unit*"
formula="value * ((min(max_hitpoints - hitpoints, 8)*100)/max_hitpoints)"
[/function]
[function]
name=rate_village_garrison
inputs="ai*,move_from,village"
formula="if(find(enemy_moves, dst = village), village_value(ai), 0)"
[/function]
[function]
name=rate_village_capture
inputs="ai*,src,dst"
formula="village_value(ai)"
[/function]
[function]
name=rate_village_proximity
inputs="ai*,unit,dst"
precondition="ai and unit and unit.total_movement and dst"
formula="if(distance = 1, 0, village_value(ai)/(distance/unit.total_movement + 1))
where distance = distance_to_nearest_unowned_village(dst)"
[/function]
[function]
name=rate_move
inputs="ai*,src,dst"
formula="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)"
[/function]
[function]
name=rate_attack
inputs="ai*,attack"
formula="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())"
[/function]
[function]
name=get_best_move
inputs="ai*,candidate_moves"
formula="if(rate_attack(ai, best_attack) > if(best_move, rate_move(ai, best_move.src, best_move.dst), 0),
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))"
[/function]
[function]
name=move_leader_to_keep
inputs="ai*"
formula="
if(dest, [move(my_leader, dest)], [])
where dest = find(unit_moves(my_leader), 'dst', find(keeps, 'keep', keep = dst))"
[/function]
move="if(vars.done_opening != 1, [set_var('done_opening', 1)] + opening(self), fallback('default'))"
blah="
if(my_leader and find(keeps, self = my_leader) = null(), move_leader_to_keep(self), []) +
get_best_move(self, filter(my_moves.moves, src != my_leader)) +
[ recruit('Skeleton Archer', loc(11,21)), recruit('Dark Adept', loc(11,22)) ]
)"
[/ai]
[/side]
[/test]
# vim: tabstop=4: shiftwidth=4: expandtab: softtabstop=4: autoindent:

View file

@ -161,6 +161,8 @@ private:
resize_monitor resize_monitor_;
binary_paths_manager paths_manager_;
std::string test_scenario_;
bool test_mode_, multiplayer_mode_, no_gui_;
bool use_caching_;
bool force_valid_cache_;
@ -181,7 +183,7 @@ private:
game_controller::game_controller(int argc, char** argv)
: argc_(argc), arg_(1), argv_(argv), thread_manager(),
test_mode_(false), multiplayer_mode_(false),
test_scenario_("test"), test_mode_(false), multiplayer_mode_(false),
no_gui_(false), use_caching_(true), force_valid_cache_(false),
force_bpp_(-1), disp_(NULL), loaded_game_show_replay_(false)
{
@ -248,6 +250,10 @@ game_controller::game_controller(int argc, char** argv)
break; //parse the rest of the arguments when we set up the game
} else if(val == "--test" || val == "-t") {
test_mode_ = true;
if(arg_ + 1 != argc_ && argv_[arg_ + 1][0] != '-') {
++arg_;
test_scenario_ = argv_[arg_];
}
} else if(val == "--debug" || val == "-d") {
game_config::debug = true;
game_config::mp_debug = true;
@ -479,7 +485,7 @@ bool game_controller::play_test()
first_time = false;
state_.campaign_type = "test";
state_.scenario = "test";
state_.scenario = test_scenario_;
try {
refresh_game_cfg();