129 Commits

Author SHA1 Message Date
Celtic Minstrel
c79874086d MicroAIs: Update all to use the new [args] syntax
Except for Protect Unit, all of them seem to still work correctly.
2016-03-27 15:13:21 -04:00
Celtic Minstrel
d48060bc00 Fix external Lua CA example for new syntax 2016-03-24 17:49:02 -04:00
mattsc
c04f406bd8 Old patrol.lua: fix indenting and add deprecation message 2016-03-24 12:57:35 -07:00
mattsc
961d134ee2 Fix and simplify Lua AI test scenario 2016-03-24 08:07:01 -07:00
Celtic Minstrel
1d7c1c74f6 Improve backwards compatibility for Lua AI
This changes the following:
- Fixes the experimental AI, without changing any of its code except for that in the [engine] tag
- Returns a dummy self from the dummy Lua engine, so that external CAs are more easily switched to using [params]
- Changes the order in which parameters are passed to AI component code. The order is now:
        state/self,    params,    data
2016-03-22 07:22:22 -07:00
Celtic Minstrel
f8f5557eb0 Huge refactor of Lua AI engine
This commit potentially breaks any Lua AI customization, except for external Lua candidate actions.
In practice, though, Lua aspects and goals will probably continue to work for the most part.

- The ai table now has a read_only attribute.
  If true, functions that change the game state will be missing from the table.
  The read_only attribute is false in CA execution and in stages.
  It is true everywhere else.
- Every Lua AI component now supports a [args] subtag.
  The contents of this tag are passed as parameters to the component code.
  This data is immutable; components cannot alter its contents.
  (External Lua candidate actions do not receive this data.)
- Accessing the persistent engine data is now supported in all Lua components.

When calling a Lua component, the Lua engine now passes two parameters:
1. The contents of the [args] tag in the specific component.
2. The contents of the [data] tag in the Lua [engine].

The return value of the [engine] code, if any, is stored for later used.
It will be passed as the third parameter to any other Lua component.
This data can be changed, but will not be saved.
The default engine does not return any such data.
2016-03-22 07:22:22 -07:00
mattsc
05eb2d7620 Lua AI helper functions: modify a comment 2015-05-20 07:13:11 -07:00
mattsc
25e10121f5 Lua AIs: fix bug occurring when number= in an attack is set to zero
Apparently, when this is the case, the number key is not included at
all, rather than set to zero, when the Lua table containing the attack
information is retrieved.
2015-05-19 19:54:41 -07:00
aquileia
504fd44747 Fixup and expand cc8ec3a934bd
[skip ci]
2015-01-29 01:36:34 +01:00
mattsc
ada80cfd34 Micro AIs: only display on-screen error messages when in debug mode 2014-11-01 07:45:15 -07:00
mattsc
156726a6a4 ai_helper.move_unit_out_of_way: fix direction rating
This is supposed to be a minor rating, secondary to the main rating.
2014-06-16 08:08:01 -07:00
mattsc
9e8ee00ad0 battle_calcs: provide default value for resistance modifiers
This is done for cases when the value cannot be read from the unit_info
table, which might happen in some UMC.  This fixes a rare bug affecting
the Fast Micro AI attack evaluation
2014-06-15 19:34:25 -07:00
mattsc
faeaf5e47c ai_helper.get_attacks: improve check for units in the way
Check whether the unit in the way has an unoccupied hex to move to.
Previously, it was only checked whether its reach was >1, which
sometimes can include only hexes occupied by units on its own side,
making the actual move impossible.
2014-06-15 14:22:18 -07:00
mattsc
03c1b97802 next_hop(): bug fix for ignoring units when ignore_units=true is set
A bug in the previous version let to them not being ignored when  the
were on the last hex of the next hop.
2014-05-02 19:29:37 -07:00
mattsc
82e4ccad4d battle_calcs.attack_rating(): overhaul attack rating system
This was long overdue.  The return value is now much closer to
something describing the actual gain/loss (roughly) in units of gold.
2014-04-30 19:09:28 -07:00
mattsc
7623c5513a battle_calcs: do not use variance of attack in attack rating
This was an idea we tried so that we’d start with the most uncertain
attack first, but it did not work very well.
Keep the code for now, just comment it out.
2014-04-30 19:06:57 -07:00
mattsc
0218b88180 attack_combo_stats(): also cache intermediate battle outcomes
Speeds up some calculations significantly.
2014-04-30 19:05:08 -07:00
mattsc
2336921a81 simulate_combat_fake(): don't fill empty HP chances with zeros
That’s what wesnoth.simulate_combat() does, but is different from the
other functions in battle_calcs.  Only hp_chance[0] needs to be set,
even if it is zero.
2014-04-30 19:02:08 -07:00
mattsc
f0c7ddcab1 ai_helper: make AI move error messages more descriptive 2014-04-30 18:59:25 -07:00
mattsc
bbffa5e88a ai_helper: remove a debug message
It’s served its purpose and is not needed any more.
2014-04-26 18:26:45 -07:00
mattsc
e99423bad9 Lua AIs: do not use empty tables as filters
It’s faster not to provide any argument to wesnoth.get_units() if all
units are to be found.
2014-04-26 07:18:23 -07:00
mattsc
8e9780d606 ai_helper.get_live_units: don't use filter_wml
It’s slow, the new method is between 10 and 20 times faster.
2014-04-26 06:46:32 -07:00
mattsc
664eeae888 battle_calcs.lua: fix bug in get_attack_map_unit() for enemy units
Own units with MP left need to be taken off the map before enemy path
finding, not just added to the table.
2014-04-23 18:48:46 -07:00
mattsc
ddfdae5e52 battle_calcs.lua: fix a variable name 2014-04-22 16:46:49 -07:00
mattsc
9701a724a8 ai_helper.lua: avoid using table.remove
It’s slow. The inverse logic using table.insert is much faster,
especially for large tables.
2014-04-17 21:03:38 -07:00
mattsc
e87240c67f battle_calcs.lua: avoid using formula= in SUFs
It’s slow for finding units with moves or attacks left. The alternative
method of getting all units and then looping over the table with a
condition is much faster.
2014-04-17 21:03:38 -07:00
mattsc
19eff08fd7 Fix a typo 2014-04-17 21:03:38 -07:00
mattsc
f6cdd85182 AI helper functions: code cleanup, first pass
These function libraries are still work in progress and change
frequently, so the code cleanup is mostly just to make sure the syntax
is consistent with that used in the Micro AIs.  Changes or improvements
to the algorithms might be made at a later time.
2014-04-17 21:03:38 -07:00
mattsc
f1faf1d6e3 Experimental AI: fix a parameter in call to healer support AI
This was an oversight from a change made in d4917d534e just two days
ago, so it was not in any released version.
2014-04-17 07:11:42 -07:00
mattsc
98509aa2bf Fix a typo
I had actually introduced this typo intentionally for testing purposes
and then forgotten to remove it.  :-P
2014-04-10 10:39:12 -07:00
mattsc
c4cb6168e4 Micro AIs: avoid using formula= in SUFs
It’s slow for finding units with moves or attacks left.  The
alternative method of getting all units and then looping over the table
with a condition is much faster.
2014-04-10 10:06:25 -07:00
mattsc
9e6b780306 ai_helper.get_closest_location(): fix bug with tags in SLF
The way how the Standard Location Filter was dealt with only worked
with keys, not tags.
2014-03-26 18:03:50 -07:00
mattsc
496a58d343 Experimental AI: use checked versions of the AI actions
So that only valid actions are executed and useful error messages are
produced if something goes wrong.
2014-02-28 07:04:54 -08:00
mattsc
0b6fa7ed19 Experimental AI: remove potential of causing errors through WML events
Events taking units off the map after the move could previously have
caused errors, and thus disabled the AI for the rest of the turn.
2014-02-28 07:03:02 -08:00
mattsc
b7bc394f95 Micro AIs: improve error reporting
Use error() instead of wesnoth.message(), as this also produces a stack
traceback.
2014-02-27 17:06:20 -08:00
mattsc
d3e9cb3957 Micro AIs: add check for valid recruiting and error message
This now checks whether the recruiting intended to be done with
ai.recruit is possible and displays an error message if it is not.
2014-02-27 17:06:19 -08:00
mattsc
835194eee4 Micro AIs: add check for valid stopunit execution and error message
This now checks whether the stopunit execution intended to be done with
ai.stopunit_all, ai.stopunit_attacks or ai.stopunit_moves is possible
and displays an error message if it is not.
2014-02-27 17:06:19 -08:00
mattsc
f0506b2d31 Micro AIs: add check for valid move and error message
This now checks whether the move intended to be done with ai.move is
possible and display an error message if it is not.
2014-02-27 17:06:19 -08:00
mattsc
c06529aa18 Micro AIs: add check for valid full move and error message
This now checks whether the move intended to be done with ai.move_full
is possible and display an error message if it is not.
2014-02-27 17:06:19 -08:00
mattsc
70e3fc58bd Micro AIs: add check for valid attacks and error message
This will now check whether the attack intended to be done with
ai.attack is possible and display an error message if it is not.
2014-02-27 17:06:18 -08:00
mattsc
e78462c395 Remove function ai_helper.random()
This was using the synced RNG which is exactly the wrong thing to do
within the AI evaluation/execution functions.
2014-02-20 11:33:05 -08:00
mattsc
21c8c5c860 ai_helper: add functions to get direction indices and strings
These consist of a number of supplementary functions, plus three
function get_cardinal_directions, get_intercardinal_directions and
get_hex_facing which return strings for the directions (in cartesian or
hex coordinates) between two hexes.
2013-12-02 11:01:44 -08:00
mattsc
623036af16 ai_helper.put_labels: display content of strings rather than 'nan' 2013-12-02 10:58:49 -08:00
mattsc
ea915d36c2 battle_calcs.attack_rating: bug fix for when AI side has no leader
Check for AI side's leader's existence before trying to calculate
distance from leader.
2013-11-25 19:37:20 -08:00
mattsc
71f92aa05c ai_helper.get_dst_src(units): minor code simplification 2013-11-14 20:04:53 -08:00
mattsc
5f39a7d2dc ai_helper.get_enemy_dst_src: add optional parameter 'enemies'
If 'enemies' table is given, use it, otherwise use all enemy units.
2013-11-14 20:04:53 -08:00
mattsc
c46d8459d6 Retreat AI eval: poisoned units do not get resting healing bonus
... in evaluation of best retreat positions.
2013-11-14 20:04:52 -08:00
mattsc
24f10a37ef ai_helper: improve criterion for impassable terrain
Rather than checking whether the movement cost is <99, check whether it
is <= max_moves for the unit.
2013-11-14 20:04:52 -08:00
mattsc
c6db6cd8d5 Lua AIs: Remove unnecessary arguments in call to wesnoth.put_unit() 2013-11-14 20:04:52 -08:00
mattsc
9976eac873 Micro AI CA files: replace tabs by spaces
I had not realized that TextWrangler changes spaces to tabs when
shifting blocks of text to the left, which had been done for all CA
files when converting the engine files.
2013-11-14 10:54:14 -08:00