how difficult is creating an artificial intelligence interface that is agnostic to a specific programming language?

Discussion of all aspects of the game engine, including development of new and existing features.

Moderator: Forum Moderators

Post Reply
MrMonteiro
Posts: 3
Joined: May 31st, 2014, 10:24 pm

how difficult is creating an artificial intelligence interface that is agnostic to a specific programming language?

Post by MrMonteiro »

Hi,

How difficult is creating an artificial intelligence interface that is agnostic to a specific programming language?

I've read some on how the AI works and the supported interfaces ([C++ and Lua and WML](https://wiki.wesnoth.org/Wesnoth_AI)).

I was (humbly) expecting that a given round is defined by a state given by the map and the units seen (plus a few other details). These seem fairly platform independent, and could thus be exposed in a programming language agnostic way. To be very explicit:

```
{
"map": "Twin Rivers",
"player_01": "ally",
"player_01_race": "rebels",
"player_01_units": [
{
"type": "elvish_fighter"

}
```

That and a few rules being written in a platform independent format (e.g. ini file) could be exposed over an HTTP server that could then reply with the movements and actions and so on. I'm just mentioning these format/protocols to illustrate the point.

So, how difficult is migrating that?
User avatar
Pentarctagon
Project Manager
Posts: 5566
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: how difficult is creating an artificial intelligence interface that is agnostic to a specific programming language?

Post by Pentarctagon »

Are you asking how difficult it would be to expose the current state of the game to an external client, and then have that client send commands back into the game?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
MrMonteiro
Posts: 3
Joined: May 31st, 2014, 10:24 pm

Re: how difficult is creating an artificial intelligence interface that is agnostic to a specific programming language?

Post by MrMonteiro »

Pentarctagon wrote: August 29th, 2023, 3:06 am Are you asking how difficult it would be to expose the current state of the game to an external client, and then have that client send commands back into the game?
Hi, thanks for your answer. In short, yes.

The way things are right now is that you have to know one of a few programming languages to tinker with Wesnoth's artificial intelligence and, from an outsider perspective, a few contributions or experiments are left out due to that. Whereas if you agree with the reasoning above, maybe more people from the community could contribute to this part of the game experience.

I know it's easy to pop in a forum and ask for things but maybe there's a significant benefit to the game in case this suggestion takes off.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: how difficult is creating an artificial intelligence interface that is agnostic to a specific programming language?

Post by gfgtdf »

MrMonteiro wrote: August 29th, 2023, 2:23 am Hi,

How difficult is creating an artificial intelligence interface that is agnostic to a specific programming language?

I've read some on how the AI works and the supported interfaces ([C++ and Lua and WML](https://wiki.wesnoth.org/Wesnoth_AI)).

I was (humbly) expecting that a given round is defined by a state given by the map and the units seen (plus a few other details). These seem fairly platform independent, and could thus be exposed in a programming language agnostic way. To be very explicit:

```
{
"map": "Twin Rivers",
"player_01": "ally",
"player_01_race": "rebels",
"player_01_units": [
{
"type": "elvish_fighter"

}
```

That and a few rules being written in a platform independent format (e.g. ini file) could be exposed over an HTTP server that could then reply with the movements and actions and so on. I'm just mentioning these format/protocols to illustrate the point.

So, how difficult is migrating that?
First off, exporting the state is quite easy, if you just want a raw state you can use the code that creates the savefiles wml (if you don't like wml then convert to something else, still not that hard). However:
1) When creating such an ai you probably only want to expose that part of the gamestate that the ai side should know (in particular when you play with fog/shroud or when hidden units like woses are involved.)
2) The normal lua ai api already provides multiple useful helper functions like "Is an ability active on a certain tile" , "Can a unit move on a certain tile", "simulate combat between two units" etc. , which probably wouldn't be so easy to reimplement independently (in particular since they usually just call the c++ functions that the actual game uses aswell for example when a unit moves)
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: how difficult is creating an artificial intelligence interface that is agnostic to a specific programming language?

Post by gfgtdf »

and 3: we sandbox our addons, which in particular means we explicitly block them from directly accessing network/filesystem/other process communication, so whatever you intend to write, it will only work on your own computer (so there is no point in uploading them to the addon server)
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
max_torch
Inactive Developer
Posts: 414
Joined: July 31st, 2011, 5:54 pm

Re: how difficult is creating an artificial intelligence interface that is agnostic to a specific programming language?

Post by max_torch »

gfgtdf wrote: August 30th, 2023, 1:17 pm First off, exporting the state is quite easy, if you just want a raw state you can use the code that creates the savefiles wml (if you don't like wml then convert to something else, still not that hard)
In reference to this comment, I would like to bring attention to a wmlparser python file that currently exists in the wesnoth repository. It can be a starting point to convert WML in a savefile to a conventional format, such as JSON.

Functions that you might want to look at first here would be jsonify() and xmlify().

Also the command line arguments for the script.

You should also note that different versions of Wesnoth may have changes to how the data in the savefiles are structured and is something you should take into account.
Post Reply