Page 14 of 22

Re: trAInsported: Alpha testers needed

Posted: Fri Mar 22, 2013 5:35 am
by AnToHu0
Is that possible to know where one of my trains locates now? For example my train goes to a passenger, but another AI boards him first and i need to recalculate the path to new goal. For this i need to know current coordinates of my train. Ofcource its possible to wait when the train arrives to next junсtion, but this way it needs more calculations to check stored passengers list.

Re: trAInsported: Alpha testers needed

Posted: Fri Mar 22, 2013 12:23 pm
by Germanunkol
AnToHu0 wrote:Is that possible to know where one of my trains locates now? For example my train goes to a passenger, but another AI boards him first and i need to recalculate the path to new goal. For this i need to know current coordinates of my train. Ofcource its possible to wait when the train arrives to next junсtion, but this way it needs more calculations to check stored passengers list.
Hey,
No, that's not possible. Of course, you could estimate, but since you can't actually do anything when not at a junction, the calculations I'd have to do internally would probably be almost as costly as the calculations people need to do now. However, I'll think about just exposing the internal train values to the users, maybe that's possible somehow.

One thing I noticed: Everyone seems to be using Djikstra, A* or similar algorithms. All of these work in real-time, there's no pre-calculation involved. However, since there's more time in ai.init() than in any other function, it might be smart to set up some sort of net of connections in there. Dijkstra could even work with that...
Has anyone tried something like this? I realise it's more involved, but it might be worth it...
asfreng wrote:np dude, thats its free xD, how can i test my AI using the numbers of lines u are using in the server?
I decided to leave it at the old settings for the time being. But you can see how the server has a real hard time keeping up when you connect to it and your AI is playing...
You can however get the source code from github or extract the .love file I posted, open Scripts/ai.lua and change the line
local MAX_LINES_EXECUTING = 20000
near the top to something like
local MAX_LINES_EXECUTING = 5000

I might have to go for 5000 or so in the future. That's too bad :( But I don't see a way around this. One of my friends suggested being able to "buy" more code-lines using the money the train makes, that might be interesting in this case.
Maybe I'll set a maximum 5000, unless you spend money on code lines, in which case you can get up to 10 000 lines.

Re: trAInsported: Alpha testers needed

Posted: Fri Mar 22, 2013 2:35 pm
by asfreng
thx, ill try to make it ligther :)

Re: trAInsported: Alpha testers needed

Posted: Sun Mar 24, 2013 11:10 am
by Germanunkol
asfreng wrote:thx, ill try to make it ligther :)
Wow, your new AI seems to kick ass... well done, it's won all of its matches so far!

Re: trAInsported: Alpha testers needed

Posted: Sun Mar 24, 2013 11:00 pm
by asfreng
Here is some feedback:

- I did upgrades in the code of two types +performance -lines and -performance -lines, the second are the problem, for example

(2 lines)
local aux = "this" .. "is" .. "a".. "string"
local aux2 = aux .. aux .. aux .. aux .......

changing to

(1 line)
local aux2 = "this" .. "is" .. "a".. "string" .. "this" .. "is" .. "a".. "string" ........

is a -performance -lines, that means, its more "heavy" to calculate but it has less line count

here is other example

table.sort( {2,34,45,5,6,3,12,3,23,4,34,5} )
line cost 1!!!!!, in large tables it can be a problem :(

There is a way to take the real line cost of build in functions?

- Theres a way to get the time to a passanger lose his vip status? (i mean without calculate it, something like passanger.vipTimeLeft)
It would be very usefull :)

Re: trAInsported: Alpha testers needed

Posted: Mon Mar 25, 2013 12:43 am
by Germanunkol
asfreng wrote:Here is some feedback:

- I did upgrades in the code of two types +performance -lines and -performance -lines, the second are the problem, for example

(2 lines)
local aux = "this" .. "is" .. "a".. "string"
local aux2 = aux .. aux .. aux .. aux .......

changing to

(1 line)
local aux2 = "this" .. "is" .. "a".. "string" .. "this" .. "is" .. "a".. "string" ........

is a -performance -lines, that means, its more "heavy" to calculate but it has less line count

here is other example

table.sort( {2,34,45,5,6,3,12,3,23,4,34,5} )
line cost 1!!!!!, in large tables it can be a problem :(

There is a way to take the real line cost of build in functions?
Thanks for the tests!
This is indeed a problem, and I tried to figure this one out for quite some time now.
I use the sethook function to count the number of Lua executions. Using this, I could stop the coroutine after a certain amount of time or a certain amount of lines. With lines, the problem is that they, as you noticed, don't take the same amount of line and don't even correspond 1:1 to the number of lines.
When stopping after a certain time instead, the problem is that the game runs very differently on different PCs, making the idea of an online server running the same script unusable...
asfreng wrote:
- Theres a way to get the time to a passanger lose his vip status? (i mean without calculate it, something like passanger.vipTimeLeft)
It would be very usefull :)
Uhm, it should be easy to calculate, right?
Since I don't have any functions that actually allow access to the VIPs, the easiest way is to store the time when ai.newPassenger is called. Just use os.time() to calculate the difference.
Anything I'd do internally would just take more lines again...

Re: trAInsported: Alpha testers needed

Posted: Mon Mar 25, 2013 4:39 am
by asfreng
Germanunkol wrote: Thanks for the tests!
This is indeed a problem, and I tried to figure this one out for quite some time now.
I use the sethook function to count the number of Lua executions. Using this, I could stop the coroutine after a certain amount of time or a certain amount of lines. With lines, the problem is that they, as you noticed, don't take the same amount of line and don't even correspond 1:1 to the number of lines.
When stopping after a certain time instead, the problem is that the game runs very differently on different PCs, making the idea of an online server running the same script unusable...
Yes, count time is not a option, ill tell u if I think something to solve it :(
Germanunkol wrote: - Theres a way to get the time to a passanger lose his vip status? (i mean without calculate it, something like passanger.vipTimeLeft)
It would be very usefull :)
Uhm, it should be easy to calculate, right?
Since I don't have any functions that actually allow access to the VIPs, the easiest way is to store the time when ai.newPassenger is called. Just use os.time() to calculate the difference.
Anything I'd do internally would just take more lines again...
nevermind this, is more simple than i thought

Re: trAInsported: Alpha testers needed

Posted: Mon Mar 25, 2013 9:22 am
by AnToHu0
In my AI i need to use the sleep(s) function, i implement it by using os.time() and "while true" cycle, but i can`t use it because of run time restrictions of game. Is there a way to create and use sleep function in game?

Re: trAInsported: Alpha testers needed

Posted: Mon Mar 25, 2013 9:55 am
by Germanunkol
Uhm... why do you need to sleep?
Any calculation done by your AI should be as fast as possible, because it pauses the entire game...
Or to put it into other words: while your AI sleeps, nothing happens in the game. After you're done sleeping, the game state will be exactly the same as before. So there's no point in sleeping, really...

Re: trAInsported: Alpha testers needed

Posted: Mon Mar 25, 2013 11:05 am
by AnToHu0
Yes, you are right. I`m already understood how to solve the problem, without using sleep function. I forgot that there are no parallel threads in lua and sleep in one AI can freeze all game ;)