Page 13 of 14

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 07 May 2012 03:45
by Dustin
oxyk wrote:i discovered one funny glitch. when playing small map (128x128 or 64), AI tries to build HQ and spend years ingame to find right spot. it just writes debug lines and keep trying. i left it for 10 ingame years and it never found that spot to build. not to mention it outputs debug text as crazy, and eats CPU for nothing. would it be possible to create array of possible coordinates and save it in table? then run 100 queries, remove bad coordinates from table, save and try in a month or year again. or do the opposite - save bad coordinates. i don't mind it spam in debug window, but also it does nothing in game, so become useless.

you said you're discontinuing support for the AI? anyone can crack the code or someone already working on it?

thank you,
oxyk
Sorry to hear you find a killer bug. I don't really have time to work on this. It was great fun at the time though. It shouldn't be super hard to open the code file and comment out the HQ. This is what I get for putting in something just to be cute I guess.

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 07 May 2012 09:07
by oxyk
Dustin wrote: Sorry to hear you find a killer bug. I don't really have time to work on this. It was great fun at the time though. It shouldn't be super hard to open the code file and comment out the HQ. This is what I get for putting in something just to be cute I guess.
i think, if you don't mind, i can just limit # of times it tries to build the HQ. it would be nice excercise as i'm learning squirrel and noAI api. i will post updated files, if it will happen.

update. i have changed HQ placement, now it start in main loop when AI idle, and will try to build evety time it's idle, if previous attempt failed.
changes to build function:
every already checked town pushed to array and when we have new randon town, it check itself in the list before trying to build anything. new town get to the list if building failed, and we look for new town while quantity of rejected towns does not exceed quantity of towns on the map. if we're out of towns, script exit and will try again in good faith someone demolished building or road, or bankrupted and freed land )

why previous attempt can fail even if we didn't reached quantity of towns on the map - random selection for towns is not that random ) it can pull repeatedly the same towns, when there's another towns to try. these doubles checked in the array and rejected. so if random selection fails for 100000 times, script exit and will try again next time.
i have tested it on different sized maps, looks like working. please give it a try )

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 07 May 2012 16:02
by Dustin
oxyk wrote:
Dustin wrote: Sorry to hear you find a killer bug. I don't really have time to work on this. It was great fun at the time though. It shouldn't be super hard to open the code file and comment out the HQ. This is what I get for putting in something just to be cute I guess.
i think, if you don't mind, i can just limit # of times it tries to build the HQ. it would be nice excercise as i'm learning squirrel and noAI api. i will post updated files, if it will happen.

update. i have changed HQ placement, now it start in main loop when AI idle, and will try to build evety time it's idle, if previous attempt failed.
changes to build function:
every already checked town pushed to array and when we have new randon town, it check itself in the list before trying to build anything. new town get to the list if building failed, and we look for new town while quantity of rejected towns does not exceed quantity of towns on the map. if we're out of towns, script exit and will try again in good faith someone demolished building or road, or bankrupted and freed land )

why previous attempt can fail even if we didn't reached quantity of towns on the map - random selection for towns is not that random ) it can pull repeatedly the same towns, when there's another towns to try. these doubles checked in the array and rejected. so if random selection fails for 100000 times, script exit and will try again next time.
i have tested it on different sized maps, looks like working. please give it a try )
Nice work. I don't have time to load it up, or upload the new version, but you have my permission (and encouragement) to post this as Denver & Rio Grande V2 and take over as the owner. :)

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 07 May 2012 16:20
by oxyk
Dustin wrote:
Nice work. I don't have time to load it up, or upload the new version, but you have my permission (and encouragement) to post this as Denver & Rio Grande V2 and take over as the owner. :)
lol, that's tempting, thank you. but someone should test it and confirm it works as it should. and definitely i can't take it over for such small edit ) i would be happy if you'll check it someday and include to your main version if my code style is ok with you. i wanted to write my own AI, with the key difference in some aspects, but i'm still learning and not very experienced to handle your big script ) for now i can get around squirrel syntax, but know nothing about pathfinders and specific noAI things.

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 07 May 2012 16:26
by Dustin
oxyk wrote:
Dustin wrote:
Nice work. I don't have time to load it up, or upload the new version, but you have my permission (and encouragement) to post this as Denver & Rio Grande V2 and take over as the owner. :)
lol, that's tempting, thank you. but someone should test it and confirm it works as it should. and definitely i can't take it over for such small edit ) i would be happy if you'll check it someday and include to your main version if my code style is ok with you. i wanted to write my own AI, with the key difference in some aspects, but i'm still learning and not very experienced to handle your big script ) for now i can get around squirrel syntax, but know nothing about pathfinders and specific noAI things.
Where I work we have a rule: Last one to touch the code owns it. :)
Besides making some improvements to a working program is a great way to learn. I didn't know anything about pathfinders or noAI when I started this project.

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 07 May 2012 16:39
by oxyk
Dustin wrote: Where I work we have a rule: Last one to touch the code owns it. :)
nice rule :) i have similar when it comes to projects with team. but it never saved me from final bugfixing after everyone. i have some ideas for my AI (basically why i wanted to write one), but need to think about it a bit, maybe i can integrate it into your AI and then we can promote it to v2. i'll get in touch once will have real detailed plan.

thank you,
oxyk

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 07 May 2012 18:11
by Zuu
If you get to the point of releasing updates, you might want to talk to the devs about transferring the bananas entry ownership. This way if the second version is compatible, users will be allowed to upgrade to it in existing games.

If the ownership is not transferred, the V2 will have to use a different short name and thus appear as a different AI to OpenTTD.

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 07 May 2012 18:37
by Dustin
Zuu wrote:If you get to the point of releasing updates, you might want to talk to the devs about transferring the bananas entry ownership. This way if the second version is compatible, users will be allowed to upgrade to it in existing games.

If the ownership is not transferred, the V2 will have to use a different short name and thus appear as a different AI to OpenTTD.
Good point! I'm all for it.

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 19 May 2012 21:59
by oxyk
Dustin allowed me to maintain his AI, so i'll release updates and will address issues. For now here's development version of the updated AI.

what's new:
* fixed bug with HQ placement infinite loop
* fixed fatal error while loading with industries newgrf. now fully compatible with ECS, FIRS
* added support for aircraft.
* updated API version compatibility from 0.7 to 1.0

what's planned:
* update to API 1.2 and make compatible with aviators newgrf (range calculation need newer API)
* lots of other things :)

please try it and report any issues.

can someone suggest how to get this version added to bananas? i have created account, but there's no option to add content.

p.s. attached screenshot from FIRS game, testing with most powerful AIs. In the long run AI created almost 200 aircrafts and had much better profit than the rest of AIs. Game settings was hard, plane speed 1/4. used planeset grf for air and german vehicles for competitors to earn something :) at the same time with such hard economy train routes was uprofitable due to 2cc trainset. While testing without newgrfs, AI demonstrated still solid results, going on 3-4th place in rank.

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 20 May 2012 10:37
by Brumi
There's a typo in the code:

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 20 May 2012 10:53
by oxyk
oops, never played with breakdown settings on, forgot to check that part. and geany does not highlight weird words for squirrel. i take it it bugged on the load?
fixed, uploading current version (here i have added better balancing for routes from the last upload/ it uses the same version.

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 20 May 2012 12:14
by Alberth
Hi, I am having a go with your AI.

How it does is too early to tell, but it seems to do weird things with loans. I see loan jumping between some value and max-loan constantly (ie 10 times a second or so)

Edit: Do you handle lack of auto-slope? It seems not.

Edit2: It sends out a lot of aircraft, I have 5-6 circling around a small airport (with 300+ passengers and 340+ mail bags). Doesn't seem very useful, the landing and take-off capacity is not big enough for this number of aircraft.

Edit3: My console spits out warning messages:

Code: Select all

dbg: [script] Next() is invalid as Begin() is never called

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 20 May 2012 14:50
by oxyk
Alberth wrote: How it does is too early to tell, but it seems to do weird things with loans. I see loan jumping between some value and max-loan constantly (ie 10 times a second or so)

Edit: Do you handle lack of auto-slope? It seems not.

Edit2: It sends out a lot of aircraft, I have 5-6 circling around a small airport (with 300+ passengers and 340+ mail bags). Doesn't seem very useful, the landing and take-off capacity is not big enough for this number of aircraft.

Edit3: My console spits out warning messages:

Code: Select all

dbg: [script] Next() is invalid as Begin() is never called
hello,
thank you for spending your time on testing and valuable feedback, i really appreciate it. i'm complete noob with openttd scripting, the only experience i have is a bit of scripting for TES3 and TES4. but i'm willing to learn )

yes, loan jumping because it did so before in original version, each main loop call paydownloan and then borrows max to try build rail. then what i have added is when it build aircraft or clone aircaft it takes maxloan because rail manager pays it off. kinda weird and i'll change that behaviour in the next update. as long as AI agressively build new connections it will use all funds immediately first years, so that jump is just minor technical distraction i'm aware of.

if you have 5-6 circling, how much in total of arcraft that airport have? what is the engine models? does it started upgrage? you might think it's not useful and it does not in the first years. just watch what it will do next ) actually it's a strategy. AI tries to balance lines and transfer as much cargo as possible, so when it comes to better planes, AI will sell some of small planes and will get better stable profit. also when you will start to have lots of mail waiting on big stations (over 500), AI will launch mail route and it will be about 2-3x profitable than same pass route. In fact compare station profits for similar setup (another Ai or your own), does AI earn less than competitor?
i tested it in 3 games, would appreciate any feedback.

strange thing with Next(), are you reffering to ingame console or AI debug window? what is your openttd version? never saw this message, please provide some info how to reproduce it.

autoslope - no, i dont think so. i looked into original rail files just to get an idea how to use basic features and how to link aircraft module. i worked on standalone module only for now. so if there's an issue with slopes, i'll get to it when will read all code in rail files. basically currently AI have an issue with terraforming - bancrupcy as a result of finding the right spot. so i had to add aircraft as an insurance.

thank you,
oxyk

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 20 May 2012 17:29
by Alberth
oxyk wrote:thank you for spending your time on testing and valuable feedback, i really appreciate it. i'm complete noob with openttd scripting, the only experience i have is a bit of scripting for TES3 and TES4. but i'm willing to learn )
We all have to start somewhere, and making an AI is a nice way, as you get fast feedback whether it works or not. Much better than coding for a month and then finding the structure is wrong :)
oxyk wrote:if you have 5-6 circling, how much in total of arcraft that airport have? what is the engine models? does it started upgrage? you might think it's not useful and it does not in the first years. just watch what it will do next ) actually it's a strategy. AI tries to balance lines and transfer as much cargo as possible, so when it comes to better planes, AI will sell some of small planes and will get better stable profit. also when you will start to have lots of mail waiting on big stations (over 500), AI will launch mail route and it will be about 2-3x profitable than same pass route. In fact compare station profits for similar setup (another Ai or your own), does AI earn less than competitor?
i tested it in 3 games, would appreciate any feedback.
I attached the game. It has just started, with default vehicles in toyland, 1958.
I have built some trains to a toy-factory. There are 4 competitors, the yellow company is WmDot, very good at road building, but it does not understand you also need to build road vehicles to survive :p
The other 3 companies all all your AI.

They all set up a PAX connection with aircraft (see Drenford, at the far west). "Drenford airport" has 6 circling Ploddyphut 100 aircraft and one at the ground. it has 16 aircraft in its list. (and 2 airports in the order list). The other airport has just 3 circling. I don't know whether you ever watched a small airport, but with an aircraft at the ground, it is pretty much impossible to land another aircraft onto it, before the previous aircraft has left. The runway is simply not available enough.
So any surplus of aircraft simply gets queued in the air. Throwing in more aircraft just adds to the delay, since the queue gets longer. Ie it has the opposite effect than you intend to have.

The green company tried building stations, the "2 producer" station got the furthest. There is a track going south, but it stops at the foot of the hill at an unbuildable slope (without autoslope).

I didn't really play, so my profits are very low. I still beat the AIs though.
The best AI makes 175,000 a year with 16 aircraft. I make 120,000 with 5 trains, and another 55 with the buses I added for fun. The difference is not having to pay 20,000 interest :p
Airports at this point in time is not worth the effort, two stations with a few PAX trains scale way better.

(it may be difficult to get an AI to understand that, though)
oxyk wrote:strange thing with Next(), are you reffering to ingame console or AI debug window? what is your openttd version? never saw this message, please provide some info how to reproduce it.
I always play trunk with debugging info enabled. If you start the program with an -d option, it should also work I think. The output is printed at the console where I started openttd (ie open a command window, and type "openttd -d", or something in that direction). Quite likely the last stable will still work, otherwise you need to use a nightly.
Unfortunately, it gives not more information than that line of text (it gets printed several times though), which makes looking for the problem tricky.
The only thing I can think of is to look for all Next(), and check that it always has a Begin() before it.
oxyk wrote:bancrupcy as a result of finding the right spot. so i had to add aircraft as an insurance.
That works, as you can see in the profit graph. The blue company has aircraft very fast, and the other two took a while longer.
oxyk wrote:thank you,
oxyk
I hardly played, and it was certainly no good test :)
I was interested in a freight AI, so I was a bit surprised to see it running aircraft, but your explanation above clears that up nicely :)

Good luck with programming the AI :)

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 20 May 2012 18:21
by Zuu
oxyk wrote:if you have 5-6 circling, how much in total of arcraft that airport have?
Depending on the length of your connections, type of aircraft and airports you need different amount of aircrafts to cause the same length of queue. Thus trying to set a maximum value for a connection is hard. For that I've developed a routine that determines the amount of aircrafts in the queue currently.

SuperLib.Airport.GetNumAircraftInAirportQueue (If you are good, you'll spot a bug in my code, so use the GetNumAircraftsInAirportQueue function despite the spelling error until the bug is fixed)

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 20 May 2012 21:28
by krinn
oxyk wrote: strange thing with Next(), are you reffering to ingame console or AI debug window? what is your openttd version? never saw this message, please provide some info how to reproduce it.
Next() and Begin() are properties of AIList() (or AIAbstractList() for old API).

so you can expect
avar = AIList();
avar.Next() somewhere in your code

and because none use Next() when using a foreach loop, i suppose you have a bad for loop using Next() somewhere

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 21 May 2012 03:36
by oxyk
Alberth,

thank you for detailed info and savegame, it helped me to spot issues with profit manager (aircraft to be sold sitting in the depot for unknown reason). and looks like when using small capacity engines early in game needs better calculations. also i need to solve funds management fast, if all players set loan limit that high, AI will be in touble very fast with that loan interest ) sadly none of the running AIs was able to build a rail, even with such big initial loan amount. that's something i need to solve in the next updates. wmDOT designed to just build roads, it's not the competitive AI from what i know. It's hard to create AI that will run better than human, for now i compare AI to other AIs to see how it performs. However i hope someday i will compare his performance to human player )

Krinn,

i figured that out, i need to find missing .Begin() somewhere. i just surprised squirrel let me go with that crime ) now i see it in terminal if run game with just openttd (i'm on linux but have 2 game versions, nightly runs from the desktop and i left 1.2 path defined in system to run from terminal)

Zuu,

thanks ) i'll look into your solution. i just need to limit each airport type to max aircraft it can hold, and do not add new vehicles to that station if limit is reached.

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 09 Jul 2012 09:28
by Brumi
The AI seems to have a typo in the code:

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 21 Feb 2015 22:45
by Baldy's Boss
I just bought one of these in a bankruptcy offer.
The company had 4 stations and 3 trains (only built electric track and only bought diesel trains)...the trains could not get from one end of their routes to the other because of knots of track surrounding stations,bridges,and depots.

it took me until the following May game time to make sure that the (now electric) trains could now travel sufficiently-cleaned-up routes.
I note the coders haven't logged in here since 2012 but maybe someone could tackle the bug.

Re: Denver & Rio Grande train AI (A freight train AI)

Posted: 16 Sep 2016 12:55
by Kogut
Crash almost immediately after start.