Need assistance with Formula AI

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

Moderator: Forum Moderators

AI
Developer
Posts: 2396
Joined: January 31st, 2008, 8:38 pm

Re: Need assistance with Formula AI

Post by AI »

-(-1,-1) would probably be a better return value (though unlikely, a path with the length of 100 is possible)
-I'm assuming you mean distance in movement points?
-I'd commit it, but I'm not a developer ;)
ckarai
Posts: 35
Joined: March 26th, 2008, 3:57 pm

Re: Need assistance with Formula AI

Post by ckarai »

Then I think, I should ask the developers about it.

I don't know whether WML supports negative numbers.
AI
Developer
Posts: 2396
Joined: January 31st, 2008, 8:38 pm

Re: Need assistance with Formula AI

Post by AI »

Why wouldn't it?
ckarai
Posts: 35
Joined: March 26th, 2008, 3:57 pm

Re: Need assistance with Formula AI

Post by ckarai »

Yes, now I remember it supports.

But there's a problem with movement costs. For walls, it's 99.

1 wall = 99 steps, which is a reachable value. I have to take care of it.
I think your suggestion with -1 is better. I think, that I'll write a patch and submit to the tracker and the developers may commit it.

It won't be a big patch.
ckarai
Posts: 35
Joined: March 26th, 2008, 3:57 pm

Re: Need assistance with Formula AI

Post by ckarai »

I thought it over.

The distance in steps has no meaning at all. The distance in turns is the only value that has meaning.
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Re: Need assistance with Formula AI

Post by Dave »

ckarai wrote: The AI should find the nearest forest-like terrain, and go there to chop the wood.

Can it be made with formula_ai?
This will be doable with the formula AI. It's not easily doable currently because we haven't exposed all the details of the map (such as terrain etc) to the formula AI, but we do intend to do this relatively soon.

Thanks for your interest.

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Need assistance with Formula AI

Post by Sapient »

ckarai wrote:If I wrote a patch to WML, would you commit it?
No, because it would be far more useful to take a SLF for destination and store the shortest route to a location matching that SLF, then to check $route.length, $route.total_movement_cost... etc
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
ckarai
Posts: 35
Joined: March 26th, 2008, 3:57 pm

Re: Need assistance with Formula AI

Post by ckarai »

No, because it would be far more useful to take a SLF for destination and store the shortest route to a location matching that SLF, then to check $route.length, $route.total_movement_cost... etc
I could do it as well, if you need my help in coding. Can you please tell me more about SLF? I don't know what it means, and I didn't find any information about it on Google / the source code.

Storing the sortest route would be a good idea, and it wouldn't require much overwork.

But in that case we should also take care of teleporting / fog / shroud as well.

Thanks,

Csaba
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Need assistance with Formula AI

Post by Sapient »

http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
ckarai
Posts: 35
Joined: March 26th, 2008, 3:57 pm

Re: Need assistance with Formula AI

Post by ckarai »

[find_path]
StandardUnitFilter
StandardLocationFilter
variable=var
allow_teleport=yes/no // default: yes
1_1_mapping=yes // default: yes
[/find_path]

The return would be an array reverse ordered by total_movement_cost:

var.length = the number of paths found
var[ i ].id = the ID of the Unit
var[ i ].x,y = the destination cell's x and y coord
var[ i ].terrain = the destination cell's terrain
var[ i ].path = the full path to the unit
var[ i ].path.length = the length of the path (without start cell / with destination cell)
var[ i ].path[ k ].x,y = the coordinates of a path cell (without start cell / with destination cell)
var[ i ].path[ k ].terrain = the terrain of a path cell (without start cell / with destination cell)
var[ i ].total_movement_cost = the total movement cost to the location
var[ i ].required_turns = the turns required to reach the location
var[ i ].final_moves = the number of moves in the last turn

If there were no units or there were no valid locations or there were no paths between any locations and any units, then an empty array would be returned.

The 1_1_mapping parameter would be important to allocate resources (such as villages) to units.
If you have 10 units for 53 villages, the best 10 paths should be returned in this function.
rende
Posts: 10
Joined: May 26th, 2005, 5:59 am

Re: Need assistance with Formula AI

Post by rende »

Hi Ckarai,

I've added some functionality to Formula AI which should allow you at least get the units to move to the closest forest. Enable FormulaAI on the side you wish the 'woodchoppers' to be on by adding ai_algorithm=formula_ai to the appropriate side as described above. A sample unit can then be created by adding the following WML:

Code: Select all

      [unit]
            x,y=16,7
            type="Walking Corpse"
            generate_description=yes
            formula="move(me.loc, nearest_loc(me.loc, map(filter(map.terrain,id=me.vars.terrain_type),loc)))"
            [ai_vars]
                terrain_type='forest'
            [/ai_vars]
        [/unit]
This only implements the behavior for moving to the closest terrain_type, forest in this case...I'm not sure if you can do the rest of what you wanted in WML or if further FormulaAI is needed, (i.e. to change the terrain type once moved and to give gold to the AI for harvested wood).

Hope this helps! :)

Barbarianhero
ckarai
Posts: 35
Joined: March 26th, 2008, 3:57 pm

Re: Need assistance with Formula AI

Post by ckarai »

Thanks, I'll try it.
rende
Posts: 10
Joined: May 26th, 2005, 5:59 am

Re: Need assistance with Formula AI

Post by rende »

FYI- There is a working example you can run after building SVN HEAD from the command line, use

Code: Select all

src/wesnoth --test formula --debug 
assuming you are in the root build directory. The walking dead unit is a woodchopper, or at least a woodfinder. I might have selected a more appropriate unit (one with an Axe) but at 3 am I felt a certain affinity for the walking dead :)

You can check out the WML in data/scenario-formula.cfg (it's pretty much the same example as I posted)

barbarianhero
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Need assistance with Formula AI

Post by Sapient »

ckarai... there are a number of problems with that design; it is really over-complicating the problem. I'll offer a counter-proposal which I hope you'll agree is much simpler (and therefore, more useable).

Code: Select all

[find_path]
  [traveler]
#   StandardUnitFilter
  [/traveler]
  [destination]
#  StandardLocationFilter
  [/destination]
  variable=path   
         #(default)
  allow_multiple_turns=no   
         #(default)
  ignore_ambush=no   
         #(default)
[/find_path]
The return would be an array of steps in the order that the unit would take them.
note: the first unit matching the unit filter would be used.

path.length = 0 --> path not found (remaining values are invalid)

path.x, path.y --> starting point
path[1..n].x, path[1..n].y --> steps to destination

path.movement_cost --> total movement cost
path[1..n].movement_cost --> movement cost per step

path[n].terrain = the terrain of a step

path.required_turns = the turns required to reach the final destination
path[1..n].required_turns = the turns required to reach a particular step
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
ckarai
Posts: 35
Joined: March 26th, 2008, 3:57 pm

Re: Need assistance with Formula AI

Post by ckarai »

I've added some functionality to Formula AI which should allow you at least get the units to move to the closest forest.
Thanks, it works well, but there's a little bug in the implementation.
The undead just jumps to the nearest location, instead of walking.

I mean the closest forest requires 15 steps, the unit can move 5, but it simply jumps to the nearest forest in 1 turn.

ckarai... there are a number of problems with that design; it is really over-complicating the problem. I'll offer a counter-proposal which I hope you'll agree is much simpler (and therefore, more useable).
I accept your offer. I think path finding is important even if Formula AI solves my woodchopper problem.
Post Reply