How to Write Your Own AI

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

Moderator: Forum Moderators

Post Reply
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

How to Write Your Own AI

Post by Dave »

I have written a guide on how to write your own Wesnoth AI in C++.

You can read it at http://wesnoth.slack.it/?WritingYourOwnAI

(fairly strong knowledge of C++ is likely required).

I look forward to seeing other people's AI's!

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
mlangsdorf
Posts: 129
Joined: April 27th, 2004, 4:24 pm

Post by mlangsdorf »

I can't get the AI vs AI multiplayer battle to work. (I haven't written the AI yet, but I thought I would start by making sure I could run the tests).

I'm running Wesnoth 0.7.5 and trying the command:

wesnoth --nogui --multiplayer --controller1=ai --controller2=ai --algorithm1=z_ai --algorithm2=z_ai

It parses the command line normally but then says "cannot find side" and quits out.

I tried passing --side1=orc --side2=elf as additional arguments, but that didn't help.

How do I get this to work?
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Post by Dave »

mlangsdorf wrote: It parses the command line normally but then says "cannot find side" and quits out.
Oops. It looks for data for the sides in a multiplayer game (the [multiplayer_side] tags), but since 0.7.5 they are encapsulated in [era] tags. Workaround for 0.7.5: edit your data/multiplayer.cfg file and find the 'default' era and make copies of all the [multiplayer_side] tags and put them outside of the [era] tag.

I have committed a fix to this problem to the CVS.

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
mlangsdorf
Posts: 129
Joined: April 27th, 2004, 4:24 pm

Post by mlangsdorf »

Thanks for that suggestion, it seems to have fixed the problem.

How does it decide what two races are in the fight? It looks like human versus human, but with the default AI, the first player wins 80% of the time (20 out of 25 games).

I'm going to do a longer analysis run tonight and see if that changes
anything.

Also, is there any possibility of restructuring choose_weapon so that it is part of the ai_interface class, and changing attack_analysis() to use ai_interface instead of ai? As it is now, every AI writer has to write a new attack_analysis(), even if they're happy with the standard attack routines.
I could do it for my local copy, but it seems like it'd be a useful change in general.
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Post by Dave »

mlangsdorf wrote: How does it decide what two races are in the fight? It looks like human versus human,
You can run without the --nogui option to see for sure.

To set which sides are fighting use e.g. "--side1=Elvish Lord" to set side1 to be rebels. "--side2=Lich" to set side 2 to Undead, and so forth.
mlangsdorf wrote: but with the default AI, the first player wins 80% of the time (20 out of 25 games).
Probably the default map with Loyalists favors side 1.

You can use --scenario=scenario-id to change the multiplayer scenario used.
mlangsdorf wrote: Also, is there any possibility of restructuring choose_weapon so that it is part of the ai_interface class, and changing attack_analysis() to use ai_interface instead of ai? As it is now, every AI writer has to write a new attack_analysis(), even if they're happy with the standard attack routines.
I could do it for my local copy, but it seems like it'd be a useful change in general.
What I'm considering doing is making most of the functions in 'ai' virtual, so if people want, they can derive their new AI from the default AI and just override the behavior they want to change.

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
mlangsdorf
Posts: 129
Joined: April 27th, 2004, 4:24 pm

Post by mlangsdorf »

[quote="Dave"]What I'm considering doing is making most of the functions in 'ai' virtual, so if people want, they can derive their new AI from the default AI and just override the behavior they want to change.
[/quote]

Please do. It'd make it a lot easier to "tweak" the current AI and simplify writing new ones.
Ummu
Posts: 17
Joined: August 18th, 2004, 3:40 am

Post by Ummu »

Maybe sometime in the future you could implement an AI-Script thing, so everybody can write their own bots... And script maps and stuff.
miyo
Posts: 2201
Joined: August 19th, 2003, 4:28 pm
Location: Finland

Post by miyo »

ryn
Posts: 196
Joined: August 23rd, 2004, 4:01 am
Location: Israel

Working on a new AI

Post by ryn »

I've begun serious work on a new learning AI for the Battle For Wesnoth. It's based on a new idea I've been playing with for a while - a decision tree that has action scripts at the bottom of every branch and observes player action to create new actions and branches. Anyone interested is welcome to email me at geva_yashfe@sbcglobal.net
Questions are welcome, ideas even more so. There is no working code atm but there is a bunch of written information and a few functions/algorithms.
2B |! 2B = 3F
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Post by Dave »

ryn: sounds cool! I look forward to seeing what you come up with. Let us know if you have any trouble with technical issues implementing it!

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
MadMax
Posts: 1792
Joined: June 6th, 2004, 3:29 pm
Location: Weldyn, Wesnoth

Re: Working on a new AI

Post by MadMax »

ryn wrote:I've begun serious work on a new learning AI for the Battle For Wesnoth. It's based on a new idea I've been playing with for a while - a decision tree that has action scripts at the bottom of every branch and observes player action to create new actions and branches. Anyone interested is welcome to email me at geva_yashfe@sbcglobal.net
Questions are welcome, ideas even more so. There is no working code atm but there is a bunch of written information and a few functions/algorithms.
I'm still concerned about the processor power this would require, and all the other points I made when I played you. But that was before 0.8.3, which doesn't work on 10.2.8...
"ILLEGITIMIS NON CARBORUNDUM"

Father of Flight to Freedom
http://www.wesnoth.org/wiki/FlightToFreedom
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Re: Working on a new AI

Post by Dave »

MadMax wrote:I'm still concerned about the processor power this would require
Sure this is a concern. Just like the concerns that the AI will be too dumb, or too complex, or too limited in scope, or unimplementable.

We can only wait and see how well it can be done :)

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
Post Reply