DictatorAI

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

DictatorAI

Post by krinn »

Hi everyone,

This is now version 1.00, pfff, after all this time i finally manage to do it !
You can grab it on bananas

I'm happy how the AI perform and compete with others, specially without using trains and the eyecandy features doesn't really impact its perf so much.

This is what the AI does now :
- Handle roads (truck all cargos, bus)
- Handle aircrafts (limited to passenger & mail), upto 5 different models could run at the same time (that's to gave a more human touch & diversity in the game, including choppers)
- Should be playable on hard conditions (low money, hard settings... in fact because i need to tune it up a bit more, it play nicer for now in poor conditions)
- Can upgrade vehicles (using its own vehicle upgrade)
- Can upgrade airports
- Can upgrade road stations
- Try to build a network of airports and run aircrafts on it
- 3 options that affect gameplay (a bit dumb ai, fair player or total war), adapt to difficulty settings (this influence where it build stations, number of vehicles allowed...)
- Save/Load supported
- Pretty stable (well, that's not a feature, but it should :P )
- Works with newgrfs (well, the ones i test, ones that change vehicles)
- Can autorepair damage route (road route only)
- Balance load at airports
- Balance load at stations
- Reuse stations & depots (also have a limit per towns to not crowd towns, this depend on gameplay options)
- Detect and lower roads stuck with too many vehicles

I'll be glad to get feedback (specially bugs, i hope you won't get too much crashs)
Thank you
Attachments
cEngineLib.9.tar
(90 KiB) Downloaded 839 times
DictatorAI-177.tar
(670 KiB) Downloaded 1238 times
Last edited by krinn on 16 Mar 2015 12:59, edited 30 times in total.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: DictatorAI

Post by Zuu »

I had to untar the tar-file in order to make it load in OpenTTD. A correctly made .tar should not need to be untared. I've heard that some people have used a rar-program that can make tar files that are not fully compatible with OpenTTD. With 7zip however the tar files produced are compatible with OpenTTD.

Just before posting this report, your AI crashed and produced this error:
Unnamed, 31st Aug 1971.png
(63.25 KiB) Downloaded 2 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: DictatorAI

Post by Brumi »

Nice job! :D I wonder what you will be able to do having started as a fork of SimpleAI...
I've been testing it now, here are my remarks:
  • Your AI is quite CPU-heavy. The game lags hard if you're fast forwarding, and after 4 years, it lags even on normal speed. Try to add some AIController::Sleep()-s in your code.
  • I'm sure you know it, as there are quite a lot of occurences of this one:
    Unnamed, 19th Aug 1950.png
    Unnamed, 19th Aug 1950.png (32.51 KiB) Viewed 37983 times
    I've seen two types of this problem: when the land was sloped wrong and when it wasn't, probably a vehicle was in the way when the AI tried to connect that piece of road.
  • I've seen a route where there were no depots, only double stations at both ends. But later I saw that two depots had been built - clever! :)
  • A little thing, but "Napoleon" as the manager name appears to be wrong. Some coding issue, I believe.
I've attached the savegame.
Unnamed, 6th Feb 1954.sav
(460.27 KiB) Downloaded 671 times
It's nice to see a new AI, keep up the good work! :)
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: DictatorAI

Post by krinn »

Thank you for trying it guys.

Zuu: saddly i can't post a new working version with correction to the bug you've catch Zuu (i've modify too much the ai, and big changes aren't finished yet), but it's now fix.
For the tar problem, i don't know, i have just use tar -cf to build it, and file roller to remove a TODO file from it (might be file roller that put havock)

Brumi: will do, i know it run hards for now i will try optimize that a bit later.
I know the slope problem, last time i played with slope i was having headhatch :P
I'll note i should fix that

For the strange no depot on route or not connected station, it's because if the ai lack money it just stop building road structure (or depot) until it will try later to fix this (as long as station is there, route is considered "working", and that could be fix with few more bucks). The ai itself love to destroy its own depot because it's like a reserved space to upgrade the station, it work nice to find a spot next to your current station, it doesn't work nice when you destroy your depot and lack money ^^

The napoleon bug comes because the name is "a la french", so it's Napoléon, looks like openttd doesn't really like the "é", i have drop it to fix that.

I've start big changes to the ai i was planning to end this WE, saddly i have to go work (and it wasn't plan at first), so i'm affraid i couldn't gave you a new version with less bugs soon.
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: DictatorAI

Post by Rubidium »

krinn wrote:it's Napoléon, looks like openttd doesn't really like the "é"
It should, as far as I know work. As long as you're using the right encoding for the files, i.e. as long as the file it UTF-8 encoded.

After all, the translated AI error messages, when they crash, use the same kind of characters; they even can handle the Chinese characters.
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: DictatorAI

Post by Brumi »

I've just noticed that you're releasing newer versions :) By only editing the first post, your updates go quite unnoticed... Could you post a message in this thread when you release a new version? I think it's quite a legitimate reason for bumping a topic.
Anyway, congrats for the new release, I'll test it more when I'll have a bit more free time :)
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: DictatorAI

Post by krinn »

ok, i will do brumi
i've made a small update that just correct a bug, no big deal, it's rare condition, but it will end the ai running if you fall on it.
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: DictatorAI

Post by Brumi »

I found a bug in your AI:
Attachments
dictator crash.png
dictator crash.png (16.4 KiB) Viewed 36989 times
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: DictatorAI

Post by krinn »

Thank you brumi for reporting it.
I don't have much time to correct it now, i've just check the code to see conditions where this bug could come from. And found it easy, the solve need a better analyze to see why it happen (the bug itself isn't interresting, why it happen is more).

I will correct it when i have more time, i might do a simple workaround until i could do better.
And i also need to add trains, and change things (like optimize for big map play) and this and that and.... pfff so much time need !
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: DictatorAI

Post by Zuu »

krinn wrote:... pfff so much time need !
Indeed! If it wasn't for the time constraint, I would have had a many more features in CluelessPlus, and I would have time to improve PAXLink so that it works better on the economy management section. :-D
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: DictatorAI

Post by krinn »

i've update to 102 (only in bananas) with a workaround for the bug brumi, but as it need specials conditions (if i'm right a dead industry gone while saving game and effect appears when loading that savegame where the ai still think the industry exists), i would be glad if you can try it on your savegame to see it work (and that not others bad effects appears, as it's a quickfix and not a real deep debug).


Zuu: it's even worst, the more time i lack to code & fix things, the more i think about what i could do to make things better.... But as it's the period where my job eats all my time until winter, i'm far from an escape.
Brumi
President
President
Posts: 920
Joined: 18 Jul 2009 17:54

Re: DictatorAI

Post by Brumi »

I loaded the savegame from this post, as that is the last one I have before your AI crashed. But that probably won't reproduce the crash, as the game was reloaded from an autosave during that period, not the savegame in the post I mentioned.

But I encountered a new crash in 1972:
Attachments
new crash.png
new crash.png (31.84 KiB) Viewed 36820 times
User avatar
Kev!
Engineer
Engineer
Posts: 37
Joined: 21 Jun 2011 16:30
Location: In Da House!
Contact:

Re: DictatorAI

Post by Kev! »

Howdy,

?( Looking at your code and wondering what does this do?(comments are mine)...

local townid = townlist.Begin(); // townid is TownID?

local townloc = AITown.GetLocation(townid); //townloc is TileIndex

local place_id = AITile.GetClosestTown(townloc); //place_id is TownID

Is there some advantage to this?

Please advise,
Kev!
I DO like a nice caboose...
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: DictatorAI

Post by krinn »

no there's none, just some code left from trys while learning the api & language.
It's the easiest thing you could create with a visible result. I suppose everyone start playing with the buildhq at first no ? :)

i've start the ai with 0 knowledge about squirrel and api, thanks to brumi's code, i've learned a lot from that. The ai start as a fork of simpleai because brumi want keep simpleai as close to original ai while i was wishing some more functionalities.
then after modifying a lot and adding a lot, i was stuck by poor concept and limitations, learning more (this time from rondje) shown me howto implement oop with squirrel (and i must say, it's the most nice and smart code i've seen in squirrel),
So i've change my mind and rewrite nearly everything from scratch, keeping some basic functions i don't feel the need to rewrite.
this is just a part left from earlier dev of the ai.
Felix Atagong
Engineer
Engineer
Posts: 45
Joined: 16 Apr 2007 19:50
Location: Louvain
Contact:

Re: DictatorAI

Post by Felix Atagong »

Same here, bug after a 'load game', seconds into the game
Attachments
Green Is The Colour, 25 Jun 1881.png
Green Is The Colour, 25 Jun 1881.png (10.28 KiB) Viewed 36272 times
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: DictatorAI

Post by krinn »

thank you for the report felix, can you provide the savegame to track this one better ?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: DictatorAI

Post by Zuu »

Recently I ran a comparison fight between your DictatorAI and my CluelessPlus AI:

Stats:
Unnamed, 18th Jul 1954.png
(180.67 KiB) Downloaded 2 times
Unnamed, 9th Feb 1964.png
(242.32 KiB) Downloaded 2 times
One thing I noticed is that your AI use more stations than mine. It can potentially find a gold mine by exploring more connections quicker but will get a higher maintenance cost as one has to pay maintenance for each station that the AI has. The maintenance fee is not very high though, so as long as you don't spam the game with stations, it is not a major issue. (but it is a contributing factor why PAXLink has economic problems)

In this game, my AI didn't build even a single air link, but your AI managed to build one. Good. :-)

People who like to complain on bad reuse of road will be disappointing by this game as both AIs did a very good job on this. ;-)


Save game:
CLUP vs DictatorAI.sav
IIRC a recent nightly is required. Eg "Last nightly" or so :-)
(228.76 KiB) Downloaded 604 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: DictatorAI

Post by krinn »

i'm happy you've gave a try at my ai zuu, not so happy by the results :)

but i'll try to change that, if my ai manage to understand howto terraform one day ^^

for the airline, i have made code to help build one and help build aircrafts as well, so it's not a big surprise for me, just result of work and evil thinking.
I'm still happy it work as expect this time :)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: DictatorAI

Post by Zuu »

Your AI crashed:
dictator_error.png
dictator_error.png (18.84 KiB) Viewed 4023 times
The game is aircraft only. Crash occurred after loading the attached save. Note that I've loaded this save a few time and at two times your AI crashed. Eg. you might have to try a few times until it crashes.
AITest2.sav
Yesterdays OpenTTD nightly
(471.94 KiB) Downloaded 595 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: DictatorAI

Post by krinn »

Thank you zuu & Felix Atagong, found it, and correct it.
It was easier than i first think.

I will look if i could cleanup a bit the ai to release a fix version. (as i work on it, the ai isn't a "nice" state for now)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest