User:Flixx/Recruitment Algorithm Collection

From The Battle for Wesnoth Wiki
< User:Flixx
Revision as of 11:17, 31 May 2013 by Flixx (talk | contribs) (Formula AI dev)

Formula AI dev

Written in: FormulaAI, C++
By: Dragonking 2008
Files: data/ai/formula/new_recruitment.fai,
src/ai/formula/function_table.cpp


  • In a first step the AI uses a ready-to-use function calculate_map_ownership() which is located inside function_table.cpp to calculate important hexes on the map. The important hexes are basically the border area between me and the enemies. (It will consider allies to).
  • Villages with a radius of 1 which are near to me are added as important locations.
  • Inside calculate_recruits() a score map is created. 5 evaluation functions are called to fill this map:
    • + defense_hp_eval(): Score is the summed defense on the important hexes multiplied by hp. Normalized so the minimum is 0 and the maximum is 100.
    • + movement_eval(): Score indicates how fast a unit can move through the important hexes. Normalized so the minimum is 0 and the maximum is 100.
    • + 5* fighting_eval(): Score indicates how good a unit is against those units on the map whose leader is near. It takes own attacks, defender attacks but not chances to hit under consideration. It uses the enemies recruitment lists if the number of units on the map is below 5. Note that there is no normalization here and the scored tend to be rather high so fighting_eval() will have a huge weight.
    • - consider_unit_costs(): Score is 80 * the difference between unit-cost and cheapest unit-cost. High value means high cost
    • - level_zero_malus(): Score is 40 if unit is level 0. 0 otherwise.
  • Then the AI will recruit according to those scores.

Things I could use

The algorithm in calculate_map_ownership() to find the borders between enemies is quite good. It works by creating for each side a move_map. This map contains for each hex the average movement costs for all units starting from the leaders position. Then the borders are those hexes where the values of the enemies move_map and mine are similar.

I could improve this by trying to make the algorithm dynamic (according to the units positions on the map) and cancelling out hexes which are near to the maps border (fights near the maps border are rather rare)