SoC Ideas AI Recruitment 2012

From The Battle for Wesnoth Wiki
Revision as of 12:04, 5 April 2012 by Crab (talk | contribs) (Description)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This page is related to Summer of Code 2012
See the list of Summer of Code 2012 Ideas

This is a Summer of Code 2012 Idea


AI: Refactor recruitment algorithm [5]

Page for the idea: SoC_Ideas_AI_Recruitment_2012

We need to refactor existing wesnoth's recruitment algorithm to:

  1. support recruiting with multiple leaders.
  2. support per-leader recruit/recall lists.
  3. support easy limiting of recruitable units.
  4. analyze map terrain better
  5. recruit units that are more useful
  6. improve counter-recruiting strategies.
  7. improve recruiting for AI-playable campaigns where AI has to not spend all the gold.

There are 4 submitted student proposals for this idea

Aline Riss Recruitment Proposal

For the moment, AI recognize only one leader even if he has more. Moreover, the recruitment algorithm is very basic. So we can set the list of possible amelioration below:

  • support recruiting with multiple leaders
  • support per-leader recruit/recall lists.
  • support easy limiting of recruitable units.
  • analyze map terrain better
  • recruit units that are more useful
  • improve counter-recruiting strategies.
  • improve recruiting for AI-playable campaigns where AI has to not spend all the gold.

In order to treat these problematic, I have highlight two points which will be my principals axes for this project and will be treat separately :

  • The placement of leaders
  • The recruitment algorithm

Each point are, at begin, independent for each other.

First, I will treat the recruitment algorithm which is the principal problem of this project. It's only in a second part that I will treat the placement problem.
See GSoC Akihara Proposal for more information.

Kseniya Buraya - Refactoring AI Recruitment

The project is to improve current AI recruiting system. I will develop and implement these options:

  • To recruit with a lot of leaders instead of one
  • To consider the terrain type where the possible battle will be
  • To consider enemy and allied units together as to create great counter-unit mix
  • To provide the scenario editor an option to choose recruiting strategy ("defensive", "agressive", etc.) and to set limits on particular units

See SoC 2012 HappyKsuh AI Recruitment for more information.

Talbot Pierre - Refactor Recruitment Algorithm

The current recruitment algorithm is based on a WML recruitment pattern which specify the recruitable units. Apart for scout, no real strategy is established because most of the units are chosen randomly from this pattern list.

I'll dedicate my summer around three axes:

  • Multiple leaders: We must manage a list of leaders and free keeps, to affect each leader to a keep and change it if needed (because it's too far from the battle...). AI should choose where an unit (on which castle) will be recruited to be more efficient, taking into account the number of enemy units and their weaknesses.
  • Recruiting better units: The units must be chosen for a specific purpose such as getting a village, fighting a specific unit, protecting another... AI should be able to keep in mind the original purpose of an unit to take further decisions. By the way, this design should be discuss with the community and the other GSoC participants because it has a large impact on the entire AI.
  • WML parameterisation: The recruitment pattern will be improved to allow scenario editors to be more specific on which units should be recruited.

See Soc2012 Talbot Pierre Refactor Recruitment Algorithm for more information.

Paolo De Luca - Refactoring recruitment algorithm

Refactoring recruitment algorithm as stated in the proposed ideas. I think those points are quite enough yet. However I would consider to detail what I've intended for "recruit units that are more useful" for I suppose it's highly connected with the rest of AI playstyle. Different behaviour based on

  • current map;
  • AI mission objetives: chase, retire, kill specific units;
  • initial Time of Day;
  • distance from enemy;
  • allies (which will repeat the above points if it's an AI);
  • current and future gamestyle ( aggressive/defensive) MUST include the fact that AI have to switch between them;

See Soc2012 Teugon Refactor Recruitment Algorithm for more information.

Additional Information

Recruiting is important for both player and AI. Units are recruited each turn.

We now have an implementation of recruiting routine, which tries to recruit units which are good in combat against units already in the field, taking into account the entire map. But, there are a number of issues, and we want to solve them.

1) AI only uses first leader to recruit - but, if there are multiple leaders, it might be useful to recruit with all of them.

2) AI cannot use per-leader recruit lists - but, leaders can have unique recruit lists (ask fendin about this feature).

3) Scenario editors want the AI recruit all units or most of the units, even if some of them might seem suboptimal from 'combat' point of view, but, as AI only considers combat/movement 'for the entire map', it might miss units which seem suboptimal. An example situation is where a unit has a specific role in the strategy, serving as auxiliary unit or as a hard counter to some specific opponent unit.

4) One of the tool that scenario editors usually use to make the AI recruit more diverse units (and also for limiting difficulty), is limiting the number of concurrent recruits of specific type in the field. Now they are doing it via a WML macro - it's better if recruiting would allow parameterization, allowing scenario creators to easily specify some 'what to recruit' hints and limitations. An example would be 'consider recruiting water-based because I want this leader to control the waterways' or 'recruit enough scouts in the first three turns because I want the AI to start capturing more villages early'. The optimal number of scouts varies with the map, of course.

5) This leads to another problem - if AI recruits some units thinking of particular purpose, it must use them properly - i.e., if a fish is recruited, it should not be used to move it to land to fight - otherwise, it makes little sense to recruit the fish in the first place'

6) Several years ago we tried an approach where the AI was finding 'most important' hexes on map and using the terrain on those hexes to affect it's recruitment patterns (instead of using the entire map)

7) Recruiting first is a huge disadvantage, because of possibility to recruit counters to enemy units. So, if the AI recruits first, it should recruit to minimize the potential for counter-recruiting (i.e., by making a balanced army which can't be hard countered by enemy potential recruits)

8) Sometimes it makes sense to hold back and not recruit even if gold is available - for example, if you're playing a campaign and current scenario is already 'beaten', or if you're waiting for the enemy to recruit units to counter them. This makes sense for the AI which usually defends and which usually wins if time runs out - so, the AI can afford to let the player come to it's position, so, it can afford to recruit some scouts and wait for the human to approach before committing to specific types of units. Also, AI has problems with grouping units so if units are recruited one-by-one, they would be would not be sent in a group.

More info (irc transcript)

ok, " recruiting with multiple leaders." by definition, leader is unit which can recruit. each leader can have his own recruit list in additional to side's recruits (it's a new feature added recently). now, AI only uses the first leader to recruit (so, if 1st leader is not on keep, it might not recruit even if 2nd leader is on keep and can recruit) 14:07 we need a way for the AI to figure out the fastest way to spend it's gold for example, if there are two leaders on different keeps, they can both recruit and, if those leaders are not on keep, AI should figure out a good keep for each leader, and move them to keeps for now, it doesn't matter if the AI is not splitting the recruits intelligently enough (but it'd be a plus) - i.e. if AI would recruit half of units with leader 1 and half of units with leader 2, that would be better than today. but, of course, it's possible to figure out a way to recruit units closer to where they'll be needed.

next, "2. support per-leader recruit/recall lists. " - that is the extension of the previous problem - if we have multiple leaders, they can have their own limitations on what they can recruit/recall. next, "3. support easy limiting of recruitable units. " - we might want to limit AI to 'up to 3 units of levels 2+' or 'up to 5 Trolls' currently scenario creators do that by modifying AIs recruit lists on the fly when units recruited or die. but, it would be much better if they would be simply able to provide values/formula about units which can be recruited now. for example, before recruiting, AI would be able to check what units are available to recruit, and how many of units of particular type can be now recruited. note that the desire to limit the recruits is, sometimes, to set the difficulty level - but, sometimes, it is to make the AI recruit more varied units. generally, usually scenario creators want each unit that the AI is able to recruit, to be recruited even if it is bad - they want player to see a variety of opponents. moreover, currently AI is overestimating the value of high-level recruits - they cost more, they are good in combat, but they die easily because 3 1st-level units usually survive for longer than 1 3rd-level unit. so, they would be glad if the AI would recruit a good mix of units. such mix arises naturally from math in some formulas - for example, if AI would recruit 10 woses, an enemy would be able to counter it with units like fire archers or skeletons, which are effective against them. but, currently-used formulas don't provide a good mix of units.

next, "4. Analyze map terrain better". basically, on each map, the terrain is varied, but some terrain is not interesting because it's far away from where the combats will be. generally, on a 2-player map, the area between the combatants is the most interesting, and the corners of the map are not that important so, it makes sense to recruit units which are better in the middle of the map, where most of the combats would happen also, sometimes, it's important to recruit some specific units to get villages or to get to targets which are over water - but it's important to recruit only the amount needed to do so i.e., on starting the game, it makes sense to recruit some fast 'scouts' to get the villages faster - but the AI should determine the correct number of scouts (or let the scenario editor tell it)

next, "5. recruit units that are more useful " - currently, AIs recruitment and AIs usage of units are independent. so, AI can happily recruit a merman (fish) and then send it to fight over land. so, if AI is recruiting a unit, it'd be good to recruit units for some particular purpose (so, later, AI would remember that and use them for their purpose) i.e., we should be able to store somewhere in the unit that 'this unit was recruited because we want to get some villages with it', or 'this unit was recruited because we have a target in a forest, and this unit is good there' this would help both in debugging, and in teaching the AI to send those units where they make most sense the reverse is also true - we might want to tell the recruitment about our priorities and targets, so it'd recruit units which are useful there for example ,if we have 3 leaders, in the west, in the east, and in the center, and our target is in the west, it would make sense to recruit with the western leader first and most.

Next, "6. improve counter-recruiting strategies. " - if human would recruit a unit which is vulnerable to cold, the ai would like to recruit a unit with a cold attack , such as dark adept. this makes sense. But, if the AI would recruit 10 dark adepts, putting all the money there, it's a problem because, on next turn, human would be able to recruit some units which are useful against dark adepts but the AI won't have any more money to respond.. so, the AI should recruit a mix of units which can't be countered easily, and which are good both against units human currently has, and against units human can recruit/recall this is especially bad in campaigns, where human player might have a horde of high-level recalls - so, if AI spends all the gold on 1-2 unit types, human player would be able to recall proper counters

and the AI is supposed to cheat a little and know what human can recruit. basically, even a simple minmax calculation would allow the AI to recruit some kind of mix of units - for example, "recruit units which are best in combat over all possible human counters next turn" if AI recruits a mixed set, it's hard to find a hard counter to it. i.e., if the AI recruits a dark adept and a skeleton, it can't be countered by berserker easily (since berserker would die to the skeleton) while, if the AI would recruit two skeletons, they can be countered by dwarven infantry with hammers and, if the AI would recruit two dark adepts, they can be easily countered by berserker so, 'mixed recruiting' arises naturally here. and, last from that list, "7. improve recruiting for AI-playable campaigns where AI has to not spend all the gold." sometimes, the scenario is already almost won, but the gold would be useful in the next scenarios - it makes sense to stop recruiting or only recruit a handful of units in this case. so, there should be a way to switch recruitment into 'conserve resources' mode (and back, if necessary) that's all for the basic list of ideas it's ok if not all of them are implemented, or if you add some of your own ideas but, the resulting recruitment should be better than the one we have now.

Whom to ask about this

Crab_ on irc.

This page was last edited on 5 April 2012, at 12:04.