fixed problems with formula AI which caused it to fail to work

This commit is contained in:
David White 2008-03-19 02:45:58 +00:00
parent 717253b40c
commit 4487376499
3 changed files with 37 additions and 7 deletions

View file

@ -46,11 +46,11 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd
canrecruit=1
recruit=Dwarvish Guardsman,Dwarvish Fighter,Dwarvish Thunderer,Thief,Poacher,Footpad
gold=100
controller=human
#controller=human
[/side]
[side]
controller=human
#controller=human
type=Dark Sorcerer
side=2
canrecruit=1
@ -94,6 +94,8 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd
[]))))"
[/function]
#this function is not used; is just an example of a stub function
#that might be expanded to have a full table of good unit matchups
[function]
name=rate_unit_matchup
inputs="unit,against"
@ -246,8 +248,9 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd
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="
# The AI entry point. Currently we just do our hard-wired opening moves and then fallback to the
# default C++ AI.
move="if(vars.done_opening != 1, [set_var('done_opening', 1)] + opening(self),
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)) ]

View file

@ -203,8 +203,9 @@ public:
{}
private:
variant execute(const formula_callable& variables) const {
const gamemap::location& src = convert_variant<location_callable>(args()[0]->evaluate(variables))->loc();
const gamemap::location& dst = convert_variant<location_callable>(args()[1]->evaluate(variables))->loc();
const gamemap::location src = convert_variant<location_callable>(args()[0]->evaluate(variables))->loc();
const gamemap::location dst = convert_variant<location_callable>(args()[1]->evaluate(variables))->loc();
std::cerr << "move(): " << src << ", " << dst << ")\n";
return variant(new move_callable(src, dst));
}
};
@ -683,7 +684,7 @@ bool formula_ai::make_move()
}
return false;
} else {
std::cerr << "UNRECOGNIZED MOVE\n";
std::cerr << "UNRECOGNIZED MOVE: " << i->to_debug_string() << "\n";
}
}

View file

@ -61,6 +61,30 @@ private:
}
};
class switch_function : public function_expression {
public:
explicit switch_function(const args_list& args)
: function_expression("switch", args, 4, -1)
{}
private:
variant execute(const formula_callable& variables) const {
variant var = args()[0]->evaluate(variables);
for(int n = 0; n < args().size()-1; n += 2) {
variant val = args()[n]->evaluate(variables);
if(val == var) {
return args()[n+1]->evaluate(variables);
}
}
if((args().size()%2) == 0) {
return args().back()->evaluate(variables);
} else {
return variant();
}
}
};
class rgb_function : public function_expression {
public:
explicit rgb_function(const args_list& args)
@ -572,6 +596,8 @@ expression_ptr create_function(const std::string& fn,
return expression_ptr(new dir_function(args));
} else if(fn == "if") {
return expression_ptr(new if_function(args));
} else if(fn == "switch") {
return expression_ptr(new switch_function(args));
} else if(fn == "abs") {
return expression_ptr(new abs_function(args));
} else if(fn == "min") {