Commit graph

774 commits

Author SHA1 Message Date
mattsc
81ef9ea390
Merge pull request #3506 from mattsc/lua_ai_cleanup
Lua AI Cleanup
2018-09-22 06:18:33 -07:00
Severin Glöckner
c5cabd960b Micro AI Demos: use Cme instead of Chw for lurkers map
[ci skip]
2018-09-14 22:50:31 +02:00
Severin Glöckner
c5d3539880 Micro AI Demos: save maps in new format
[ci skip]
2018-09-14 22:50:31 +02:00
mattsc
a781139536 generic_recruit_engine: remove unnecessary variable assignment 2018-09-07 09:50:51 -07:00
mattsc
dcadab91a4 Lua AIs: use ai_helper.get_locations_no_borders() 2018-09-07 09:50:42 -07:00
mattsc
10463fdf60 ai_helper: new function get_locations_no_borders() 2018-09-07 09:50:23 -07:00
mattsc
75843541bc Lua AIs: use ai_helper get_unit functions where applicable
The ai_helper functions are optimized for speed (as much as possible in a general setting) and do all the necessary tests.  For example, get_units_with_attacks() checks both whether the unit has attacks left, and whether it has any attacks in the first place.
2018-09-05 19:38:28 -07:00
mattsc
a7d80240f2 ai_helper: get_unit functions should only return live units
Live beiing defined as in get_live_units(), that is, non-petrified units
2018-09-05 19:34:44 -07:00
mattsc
fdc3249496 Lua AIs: use ai_helper.robust_move_and_attack()
ai_helper.robust_move_and_attack() does the stop_unit_moves automatically if the unit is at the destination hex.
2018-09-04 07:16:56 -07:00
mattsc
23f35546fc Lua AIs: remove commented-out debug code 2018-09-03 14:48:10 -07:00
mattsc
ec45b53fe2 Experimental AI: rename config file
This stopped being a rush AI long ago.
2018-09-03 12:01:41 -07:00
mattsc
35ba820509 Experimental AI: adjustments to candidate action scores
The relative ranking of the CA scores is not changed, except for one case when two CAs had the same score.

Reasons:
- All scores should be lower than the scores of the default Goto CA (200,000) and the default scores of most Micro AIs (300,000).
- Break tie, resulting in uncertain order of execution, of place_healers and retreat_injured CA. Healers should be placed first, to allow retreating injured units to adjacent hexes.
- Set default for generic_recruit_engine to slightly above default AI recruiting score. That way it takes effect even if the default CA is not removed.
- Increase move_to_any_enemy CA score from 1 to 1,000. It is still the lowest score that way, but allows for setting up custom CAs with even lower scores (even if it is just for end-of-turn statistics or the like).
2018-09-03 11:05:49 -07:00
mattsc
b92d8e8226 recruit_rushers CA: don't reserve village for passive leader 2018-09-03 08:01:28 -07:00
mattsc
0bcb98cf50 recruit_rushers CA: check if castle_switch CA is present
So that it is possible to use the recruit_rushers CA without the castle_switch CA.
2018-09-03 07:40:27 -07:00
mattsc
45a3bf9363 Lua AIs: replace tabs with spaces 2018-09-02 15:08:24 -07:00
mattsc
3bfd59f28b Lua AIs: do not use engine's 'data' variable unless necessary
Now that all the AIs use external CAs, there is no need to use the persistent 'data' variable any more, unless information is to be exchanged between different CAs or is supposed to be persistent across save/load cycles.
2018-09-02 13:20:34 -07:00
mattsc
62625fd5e2 Protect Unit MAI: remove unused configuration variables
They cannot be set for the MAI, and they would have to be set through 'cfg' not 'data' anyway.
2018-09-02 08:54:31 -07:00
mattsc
42b4430841 Lua AIs: avoid calling wesnoth.get_terrain() more than needed
It probably doen't make a noticeable difference for these AIs, but in general we should not call the slow functions more than necessary.
2018-09-01 14:29:51 -07:00
mattsc
5474785718 Experimental AI: convert to using external CAs 2018-08-31 18:31:29 -07:00
mattsc
c2635abde1 Experimental AI: fix eval/exec debug output
This involves making the output independent of the stats CA (which is not used any more) and adding missing output to some CAs.
2018-08-31 07:04:58 -07:00
mattsc
35d257f8fd Lua AIs: don't compare variables with nil
... unless there is a difference between nil and false. Done mostly for consistency with all the other uses.
2018-08-30 17:37:12 -07:00
mattsc
a23f06dc20 Lua AIs: don't initiate variables as empty tables
... if they might not be needed.
2018-08-30 17:27:18 -07:00
mattsc
0e7c09f7b5 Lua AIs: no need to set variables to nil explicitely
This is mostly done for consistency across the Lua AI code
2018-08-30 07:35:57 -07:00
mattsc
80ae232935 Herding Micro AI: fix variabls not being local 2018-08-30 07:23:41 -07:00
mattsc
cb423b2fbd Lua AIs: use math.huge to initialize extrema variables 2018-08-30 07:18:04 -07:00
mattsc
f4f2a441e4 Fast Micro AI: code cleanup
Most of the Fast MAI attack utils had been taken from a more general codebase and included things not needed here. This AI is supposed to be a slimmed down version doing only the absolutely necessary in as fast as possible a fashion.
2018-08-29 19:26:49 -07:00
mattsc
1680436f72 Lua AIs: remove another unused library inclusion 2018-08-29 08:48:30 -07:00
mattsc
8a996c55b9 Lua AIs: remove inclusions of unused libraries 2018-08-29 08:00:32 -07:00
mattsc
5335a2af33 Lua AI utility functions: fix for chance-to-hit specials without id
All mainline chance-to-hit weapon specials have ids, but it is not required for UMC specials.
2018-08-29 07:27:24 -07:00
mattsc
aa59ac5455 Lua AIs: avoid using __cfg for accessing weapon specials 2018-08-28 19:07:42 -07:00
mattsc
133568efe6 Micro AIs: simplify unit variable handling functions
The main reason for doing this, besides simplifying the code, is to avoid using the WML table dump __cfg, which is slow. This includes a change of the format in which the variables are stored, but since these are internal Micro AI utility functions, that does not matter.
2018-08-27 18:39:41 -07:00
mattsc
8af988c697 Lua AIs: get unit cost/level directly from proxy unit
These used to be accessible only through unit.__cfg or wesnoth.unit_types.  The Fast Micro AI is not included here as it requires a larger clean-up.
2018-08-27 12:34:29 -07:00
mattsc
3f54908b0b Lua AIs: replace print() by std_print() 2018-08-27 07:30:24 -07:00
mattsc
83c4ef2418 Lua AIs: remove unused debug output 2018-08-27 07:29:24 -07:00
mattsc
b3058e8e8e Messenger MAI Lua code: change proxy unit location directly 2018-08-27 07:13:18 -07:00
mattsc
a6866390df Lua AIs: use unit methods instead of wesnoth functions 2018-08-27 07:05:43 -07:00
mattsc
d4213371b1 Fast Micro AI: fix for chance-to-hit specials without id
All mainline chance-to-hit weapon specials have ids, but it is not required for UMC specials.
2018-08-15 12:13:55 -07:00
Martin Hrubý (hrubymar10)
bc4d22dc72 Migrate links to https if available - Fwd c18537edc0 2018-07-16 19:07:08 +11:00
mattsc
6c38b8ce93 Goto Micro AI: add [and] to a filter
Another efficiency improvement.  This ensures that the side of the unit
is checked first before the potentially complex rest of the filter is
evaluated.
2018-06-07 06:45:30 -07:00
mattsc
0dcbe1d0d0 Goto Micro AI: change order of SLF and SUF evaluation
This is for efficiency reasons, as location filters do not necessarily
change throughout a side’s turn, while fewer and fewer units have moves
left.
2018-06-07 06:45:14 -07:00
mattsc
972ecc2f56 AI helper: improve efficiency of get_unit functions
The old method is very slightly faster in some circumstances (e.g. for
simple filters and when all units have moves/attacks/etc. left), but we
are talking fractions of micro seconds. By contrast, depending on the
filter used, the new method can save large amounts of evaluation time
once some units have move or attacked.
2018-06-07 06:44:55 -07:00
mattsc
a6c0012689 Experimental AI recruiting: use math.huge instead of 9e99 2018-05-20 14:55:17 -07:00
mattsc
f810504306 Experimental AI: clear recruit cache when no recruit action found 2018-05-20 14:55:01 -07:00
mattsc
a65605c547 Fix Experimental AI not working without enemy units
An example are the first two turns of Dark Forecast.
2018-05-20 14:54:45 -07:00
mattsc
4b6681a300 Do not load helper.lua where it is not used any more 2018-05-13 20:53:01 -07:00
mattsc
1684e2f5da Remove unnecessary inclusions of helper.set_wml_action_metatable {} 2018-05-13 20:52:51 -07:00
mattsc
08a000a7da Lua code: remove deprecated helper.set_wml_var_metatable() call
It’s not needed here.
2018-05-13 20:52:40 -07:00
mattsc
3c792fc7d7 Lua code: replace deprecated helper.[gs]et_variable_array() calls 2018-05-13 20:52:17 -07:00
mattsc
7c137e1a33 Lua code: replace deprecated helper.child_range() calls 2018-05-13 20:52:08 -07:00
mattsc
f0bb40590f Lua code: replace deprecated helper.get_child() calls 2018-05-13 20:51:56 -07:00