Latest Posts

Topic: AI: init.lua blocks the game

Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-01-31, 22:08

I did not know about break... Also goto will be much usefull one time in future

Thanks for advices!


Top Quote
fk
Avatar
Joined: 2013-07-30, 21:58
Posts: 151
Ranking
At home in WL-forums
Posted at: 2014-02-01, 15:17

SirVer wrote:

extra parameters get nil.

That is new to me, but actually I assumed that the routine had to receive 'true' where it receives 'nil'. But as Tibor states, it works flawlessly. face-grin.png


Top Quote
SirVer

Joined: 2009-02-19, 14:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2014-02-02, 19:48

Tibor wrote:

Today I spent some time on a road algorithm, though an algorithm itself is logical and reliable, to put it into lua is too complex for me. I am thinking about other approach now...

BTW, what is miss most in LUA is break and continue

As mentioned before I also got intrigued and though about writing some AI stuff in Lua. So I started with a road connection algorithm - also I was interested how much work it would be to pull this off in Lua. It is a little rough around the edges, but basically works. I agree that the engine should provide this to Lua instead of this needed to be written in Lua, but oooh well. For now you can find my little script here:

https://gist.github.com/SirVer/8773693

I think I will drop it into the repository, probably in infrastructure.lua. But not before b18 and not before I wrote some tests for it. In the meantime, I hope it is useful.


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-02-02, 21:31

SirVer

thanks for effort, I will investigate the code thoroughly...

Just small comment - the algorithm presumes you know the both fields to be connected. But usually you know one end of a road (a new building) but not the other one. Or rather - you might not care where the road is to be connected. It just have to be connected to a road...

Anyway you code is very usefull for me...


Top Quote
SirVer

Joined: 2009-02-19, 14:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2014-02-03, 10:16

that function should be easy to write. Something along these lines could work:

function connect_to_nearest_flag(flag)
   for i=0,10 do
      for idx, f in ipairs(flag.fields[1]:region(i+1,i)) do
         if f.immovable and f.immovable.name == "flag" and
            f.immovable.owner == flag.owner
         then
            if connect_flags(flag, f.immovable) then
               return true
            end
         end
      end
   end
   return false
end

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-02-03, 19:20

Thanks,

today I created my own algorithm, but I studied your code, it was usefull. F.e. sets are very neat...

And the nearest field might not allways be the one where you can build the shortest road to.

My algorithm finds all possible connection points in radius 10 (it is customizable, of course) and pick the one that is reachable with shortest path...

but of course, at the end usually it is the same point...


Top Quote
SirVer

Joined: 2009-02-19, 14:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2014-02-03, 20:30

If you come up with a bunch of nice algorithms I think we should put them into infrastructure.lua or something similar. This road building algo for example might be useful for scenarios too.


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-02-03, 21:50

I would like to have in few days (or short weeks) a "technological preview" - very primitive AI that can 'colonize' the whole map, of course without fighting an enemy... so of course the code will be avaiable...

I myself wonder if it will work the way I hope .... face-smile.png


Top Quote