SoC Ideas LuaAI 2011

From The Battle for Wesnoth Wiki

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

This is a Summer of Code 2011 Idea


Extend Wesnoth's Lua AI support and improve Wesnoth's AI

More info at SoC_Ideas_LuaAI_2011

It is very important for Wesnoth to have a way of scripting AI without modifying the c++ source code. Some time ago, it was possible to use Python to code AIs, but it was removed due to security issues. Now, we have added Lua as a new way to script AI. The core capabilities were already added, but we need to integrate Lua AI scripts better.

Wesnoth AI consists of different components. Each component is a c++ object, which provides an interface to allow the ai to delegate part of the turn sequence to that c++ object. But, that c++ object can be a proxy for code written in different language, such as formula_ai or lua. So, we have a lua engine - a c++ class which is responsible with creating c++ proxies for lua code snippets. This lua engine must provide access to all the information that the c++ AI knows - caches like 'attacks' and 'possible moves', values of aspects such as 'aggression' and 'caution', etc. So, there's a large number of AI support functions which we need to expose to lua code.

There are 7 submitted student proposals for this idea

Mark Goodenough - Improvements to the Lua AI

I propose to first extend the capabilities of the current system for using Lua scripts to dictate AI behaviour, which is the main part of what the Wesnoth team have said they want from this project. After that I intend to program some specific behaviours that scenario designers might find useful, like 'focus on this unit' for situations where the players looses if a unit dies. Finally I intend to try to improve on the current Wesnoth AI creating an AI that performs better against human opponents, hopefully by joining the Wesnoth project and working with Crab on the AI. This last goal is the hardest part, as I've never written an AI before although our course at uni does cover the theory side of possible AI implementations, and I may not succeed.
See MGoods for more information.

Qbunia - AI implementation guy

Hi my name is Jakub Ozga. I like to work on Ai exposing from c++ to lua. First of all i will do pregsoc work to get know which parts of AI are missing. Then I would do through plan which is written here [1].

See Qboo for more information.

FishbaitHarry - Extending Lua AI support and implementing additional AI techniques

As the first part of my work I would like to design and implement the extension to the Lua script interface, providing it with all of the AI support functions that might be needed. If that task is completed swiftly, I would like to move on to implementing some additional support functions, including interfaces to customizing and using some advanced AI algorithms, like Reinforcement Learning.

The extent of work with additional support functions and the exact algorithms to be implemented would be based on research done during the first part of work, as I familliarise myself more with the whole ai used in Wesnoth. In the final product, I hope to make the Lua AI scripting both advanced and easy to use tool for both scenario developers and students who would like to use Wesnoth to test and compare AI techniques from scientific standpoint.
See SoC2011 FishbaitHarry for more information.

Afan - LuaAI

My idea is to improve the AI by allowing to to have more context of what is going on in each game. This means giving both the AI, and users knowledge in how good a move is, show suggested moves. To implement this, I plan to create an influence map for each AI player which will calculate roughly how strong each unit on the field is. Based off this the influence map will be able to tell the AI roughly how safe or unsafe a tile is.
See SummerOfCodeProposal 2011 LuaAI Afan for more information.

champ - Implement Multi-player Lua AI scripting security

I plan to implement a secure mechanism on Lua AI scripting system.
The mechanism will be implement on C++ level and transparent to Lua AI scripts.
Make player-unaccessible resource also unaccessible for Lua AI scripts. (For example: If fog is on, units covered by fog for current player should not accessible to Lua scripts initiated by current player.)
Make player-read-only resource also read-only for Lua AI scripts. (For example: Lua scripts should be able to access the coordinate for a player-owned unit, but should not be able to modify it directly.)

See SummerOfCodeProposal 2011 LuaAI champ for more information.

Jody Northup - Improve and extend Lua AI scripting facilities

This is the Lua AI improvement idea.
If I am accepted for this project, I will bring the Lua AI scripting functionality up to par with the current C++ AI programming functionality by first exposing all of the C++ AI support functions to Wesnoth's Lua API, and then adding WML utilities to include and handle custom Lua AI code in WML modules.
I expect the first step to involve an in-depth analysis of the C++ AI functions and an inventory of the gaps in the currently-implemented Lua AI API, followed by tedious Lua API programming to expose each of those functions. I expect that the second step will involve communication with the development community to determine good WML specifications for the use of Lua AI code in UMC modules.
See SummerOfCodeProposal 2011 LuaAI JodyNorthup for more information.

Nephro - Improving and extending LuaAI

The artificial intelligence module of Battle for Wesnoth is written in C++ and is pretty complicated for scenario developers to configure. That's why Wesnoth developers decided to extend it and allow users to write AI configurations in Lua, which is not possible at the moment.
See SummerOfCodeProposal LuaAI Improvement Nephro for more information.

Required knowledge

The student has to know or learn:

  • Lua C++ api (src/scripting/lua.cpp is the example file)
  • Basic WML (Wesnoth Markup language)
  • Basic Lua
  • Wesnoth game concepts. Gameplay experience is very important to have or gain.

Implementation plan

To quote from Alpha Centauri, "Technological advance is an inherently iterative process. One does not simply take sand from the beach and produce a Dataprobe. We use crude tools to fashion better tools, and then our better tools to fashion more precise tools, and so on. Each minor refinement is a step in the process, and all of the steps must be taken. ".

  • So, we firstly want to expose existing c++ things to lua.
  • Then, we want to build a lua-based 'wesnoth lua ai standard library', a library of functions useful to an ai developer.
  • Then, we want to build a library of high-level functions which will be directly usable by scenario developer, with the level of complexity like 'drop this 1-line macro here, set this unit variable there, and voila - the unit is now controlled by lua ai according to your wishes'
  • example of such behavior are 'patrol', 'retreat', and 'guard' behaviors
  • then, we want to improve the ai directly, areas like recruiting with multiple leaders, actually defending something, handling concepts like leadership,skirmish, illuminate, and other, even, created-from-WML, concepts
  • then, we want to make sure that multiple ais can coordinate between themselves, and stick to a certain strategy in battle,as determined by situation and whims of scenario creator

First step: expose existing c++ things to lua

  • we need to expose AI aspects to lua
  • we need to expose AI movement maps to lua ( std::multimap<map_location, map_location> , four of them)
  • we need to expose AI target lists to lua (target is a marker on the game map)

when exposing things, we should make sure we provide a accessor which does the converted version and caches the converted version.

Second step: wesnoth lua ai standard library

  • we need to check and document ways for the AI author to include lua ai code in the scenario. for that, we should provide ways for the code to be injected by scenario, by era, by race, etc.
  • we need to ensure that our .lua library code can be easily loaded by the AI engine. preferably, ensure that each library is only loaded once.

Useful links

Definition of Done

All information that is possible to use in c++ AI, is possible to use in Lua AI with relatively same level of complexity for AI author.

Whom to ask about this

Ask Crab_ on #wesnoth-dev

Possible pre-gsoc tasks

We want to make it easy to write Lua AI. The best way to ensure that is to try to write some AI components, and see what's easy, what's hard, and what's missing. So, here are a few things that can be done to get you started and to allow to code some useful lua/c++ code which can be included in wesnoth lua ai standard library.

  • Write the AI which can complete Scenario 1 of the Heir to the Throne campaign on easy difficulty.
  • Write the AI which can complete Scenario 1 of The Hammer of Thursagan campaign on easy difficulty.
  • Write a recruitment procedure for the AI which uses with multiple leaders intelligently
  • Write a system to attach 'behavior instructions written in lua' to specific units
  • Write a patrol formula in Lua (march 13, taken by vdaras)
  • Write a basic attack routine which allows to inject a Lua 'rate attack combination' function into it.
  • Write a peacefull mob AI (independant units that flee all other unit and graze peacefully when far enough)
  • Re-implement useful formula ai functions in lua.
This page was last edited on 28 March 2011, at 19:55.