Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Mon Nov 12, 2018 7:04 pm

All times are UTC




Post new topic  Reply to topic  [ 17 posts ] 
Author Message
 Post subject: SmallTownAI
PostPosted: Thu Apr 05, 2018 6:35 pm 
Offline
Engineer
Engineer
User avatar

Joined: Thu Apr 05, 2018 4:50 pm
Posts: 11
Location: due west of somewhere...
Hello,
I have been playing OpenTTD for years, but this is my first attempt at a useful AI.
It is currently a WIP, and occasionaly fails to make money.
Please help me to find and remove bugs, and any feedback is appreciated.

SmallTownAI currently:

Builds a two-station network in a town with less than 1250 people.
Expands that network to nearby towns and cities

Known Issues:

Stops building after the first network is complete



Some credit to WrightAI, as several parts of SmallTownAI are based upon it.


Attachments:
SmallTownAI-5.tar [26 KiB]
Downloaded 26 times
File comment: A typical network made by smalltownAI
SmalltownAI.png [865.46 KiB]
Not downloaded yet


Last edited by ethaninfinity on Mon Jul 30, 2018 1:32 am, edited 12 times in total.
Top
   
 Post subject: Re: SmallTownAI
PostPosted: Thu Apr 05, 2018 11:31 pm 
Offline
Graphics Moderator
Graphics Moderator
User avatar

Joined: Mon Sep 13, 2004 1:21 pm
Posts: 5305
Location: The Moon
Hey, that's a good start! Welcome to the forums and the fun of coding AI. :)

_________________
Pikkarail.com blog | Patreon
Dev reference: NML Specs - NewGRF Specs - Savegame Internals - NoAi API - NoGo API


Top
   
 Post subject: Re: SmallTownAI
PostPosted: Fri Apr 06, 2018 4:02 pm 
Offline
Engineer
Engineer
User avatar

Joined: Thu Apr 05, 2018 4:50 pm
Posts: 11
Location: due west of somewhere...
Quote:
Hey, that's a good start! Welcome to the forums and the fun of coding AI. :)

Thanks for the encouragement! It doesn't do much now, but I hope to work on it until it is at least competitive with some of the other AIs out there.

Also, an update! This version actually places stations that connect to roads and builds a bus to connect them.


Attachments:
File comment: The first money-making(sometimes) version of this AI!
SmallTownAi_R1.tar [13.5 KiB]
Downloaded 25 times
Top
   
 Post subject: Re: SmallTownAI
PostPosted: Wed Apr 25, 2018 12:27 am 
Offline
Engineer
Engineer
User avatar

Joined: Thu Apr 05, 2018 4:50 pm
Posts: 11
Location: due west of somewhere...
Update!

R2: Now builds an inter-city network!

Now on BaNaNaS! :D


Attachments:
Inter-city connection.png [931.51 KiB]
Not downloaded yet
SmallTownAi_R2.tar [24.5 KiB]
Downloaded 21 times
Top
   
 Post subject: Re: SmallTownAI
PostPosted: Wed Apr 25, 2018 6:45 am 
Offline
Graphics Moderator
Graphics Moderator
User avatar

Joined: Mon Sep 13, 2004 1:21 pm
Posts: 5305
Location: The Moon
Nice update. :)

I've noticed it frequently builds the first two bus stops right next to each other. Also, with newgrfs loaded (eg Road Hog), the AI thinks it's building buses but nothing is built.


Attachments:
Image1.png [37.43 KiB]
Not downloaded yet

_________________
Pikkarail.com blog | Patreon
Dev reference: NML Specs - NewGRF Specs - Savegame Internals - NoAi API - NoGo API
Top
   
 Post subject: Re: SmallTownAI
PostPosted: Thu Apr 26, 2018 9:05 pm 
Offline
Engineer
Engineer
User avatar

Joined: Thu Apr 05, 2018 4:50 pm
Posts: 11
Location: due west of somewhere...
Quote:
Nice update. :)

I've noticed it frequently builds the first two bus stops right next to each other. Also, with newgrfs loaded (eg Road Hog), the AI thinks it's building buses but nothing is built.


Thanks for the info! The bus stops being built close to each other is a known issue that should be fixed soon, and I will look into the bus issue and try to fix it.


Top
   
 Post subject: Re: SmallTownAI
PostPosted: Thu Apr 26, 2018 10:22 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Nov 03, 2017 6:57 pm
Posts: 1619
Location: Courbevoie, near Paris, France
PikkaBird wrote:
Nice update. :)

I've noticed it frequently builds the first two bus stops right next to each other. Also, with newgrfs loaded (eg Road Hog), the AI thinks it's building buses but nothing is built.


Isn't that because the ai_engine_rank is set at 0 ?
AFAIK there are a few sets that do allow their vehicles being used by AI other than Road Hog. Bob's British Buses/Random Vehicles work perfectly with AI - even though, in the later years, it tends to use a lot the UKB Quad ;)

_________________
NewGRFs by Tony Pixel :
North American Passenger Railroads
Not Enough Subways


My screenshots


Top
   
 Post subject: Re: SmallTownAI
PostPosted: Thu Apr 26, 2018 11:05 pm 
Offline
Graphics Moderator
Graphics Moderator
User avatar

Joined: Mon Sep 13, 2004 1:21 pm
Posts: 5305
Location: The Moon
acs121 wrote:
Isn't that because the ai_engine_rank is set at 0 ?


No, it isn't.

_________________
Pikkarail.com blog | Patreon
Dev reference: NML Specs - NewGRF Specs - Savegame Internals - NoAi API - NoGo API


Top
   
 Post subject: Re: SmallTownAI
PostPosted: Thu Apr 26, 2018 11:18 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Nov 03, 2017 6:57 pm
Posts: 1619
Location: Courbevoie, near Paris, France
PikkaBird wrote:
acs121 wrote:
Isn't that because the ai_engine_rank is set at 0 ?


No, it isn't.


Why then ?

_________________
NewGRFs by Tony Pixel :
North American Passenger Railroads
Not Enough Subways


My screenshots


Top
   
 Post subject: Re: SmallTownAI
PostPosted: Fri Apr 27, 2018 12:27 am 
Offline
Graphics Moderator
Graphics Moderator
User avatar

Joined: Mon Sep 13, 2004 1:21 pm
Posts: 5305
Location: The Moon
acs121 wrote:
Why then ?

At a quick glance: Because something in ethan's vehicle evaluation code isn't working as intended. I'd draw his attention, particularly, to the fact that AICargo.CC_PASSENGERS is a cargo class (and == 1), not the cargo ID for passengers. It's probably safe to assume passengers are cargo 0, at least for now.

_________________
Pikkarail.com blog | Patreon
Dev reference: NML Specs - NewGRF Specs - Savegame Internals - NoAi API - NoGo API


Top
   
 Post subject: Re: SmallTownAI
PostPosted: Fri Apr 27, 2018 3:07 am 
Offline
Engineer
Engineer
User avatar

Joined: Thu Apr 05, 2018 4:50 pm
Posts: 11
Location: due west of somewhere...
Quote:
Because something in ethan's vehicle evaluation code isn't working as intended. I'd draw his attention, particularly, to the fact that AICargo.CC_PASSENGERS is a cargo class (and == 1), not the cargo ID for passengers.


Yes, that was the issue, or at least one of the issues. My code also wasn't removing invalid engines from the list, so it was trying to build one of the default buses though it couldn't with Road Hogs in use. It was mostly luck that it somewhat worked in the first place, but all of that is (hopefully) fixed now. It also now chooses the newest vehicle available, which is not the best way to choose but not as bad as it was, and is simple to do.


Attachments:
SmallTownAI-3.tar [24.5 KiB]
Downloaded 24 times
Top
   
 Post subject: Re: SmallTownAI
PostPosted: Fri May 04, 2018 7:22 pm 
Offline
Engineer
Engineer
User avatar

Joined: Thu Apr 05, 2018 4:50 pm
Posts: 11
Location: due west of somewhere...
Hello, I have gotten stuck while trying to fix the issue of stations being built too close together. I don't see anything wrong with the code, but it seems to do absolutely nothing :
Code:

//station1_location is the list of potential tiles for station construction

//go through every potential station location to check for nearby stations
for(local test_tile = station1_location.Begin(); station1_location.IsEnd() == 0; station1_location = station1_location.Next()) {

   //create a list of tiles near the tile being tested
   local neighbors = AITileList()
   neighbors.AddRectangle(test_tile - (2, 2), test_tile + (2, 2));
   
   
   //remove non-station tiles
   neighbors.Valuate(AITile.IsStationTile)
   neighbors.RemoveValue(0);

   // if there are still tiles, remove the tile being tested from the list of potential station locations
   if(neighbors.Count != 0) {
      station1_location.RemoveTile(test_tile);
   }
}


After this is fixed, the next version of the ai should be nearly ready


Top
   
 Post subject: Re: SmallTownAI
PostPosted: Fri May 04, 2018 7:53 pm 
Offline
Graphics Moderator
Graphics Moderator
User avatar

Joined: Mon Sep 13, 2004 1:21 pm
Posts: 5305
Location: The Moon
neighbors.Count() ? Gets me every time too.

_________________
Pikkarail.com blog | Patreon
Dev reference: NML Specs - NewGRF Specs - Savegame Internals - NoAi API - NoGo API


Top
   
 Post subject: Re: SmallTownAI
PostPosted: Tue May 22, 2018 11:31 pm 
Offline
Engineer
Engineer
User avatar

Joined: Thu Apr 05, 2018 4:50 pm
Posts: 11
Location: due west of somewhere...
Quote:
neighbors.Count() ? Gets me every time too.

Unfortunately, that did not solve the issue. I have added some debug messages, and it appears that what is inside the loop never occurs. I am still stumped. The other thing I am working on for the next update is vehicle renewal, but that also needs a similar loop to work, and I haven't had any luck with it either.
Unfortunately, I haven't worked on the AI much recently, but should return to it after the end of the school year.

P.S.
How do you make a quote show who was quoted?


Top
   
 Post subject: Re: SmallTownAI
PostPosted: Wed May 23, 2018 9:47 pm 
Offline
Engineer
Engineer

Joined: Sun Jul 14, 2013 12:33 pm
Posts: 86
Location: Netherlands
I think you need to replace
Code:
station1_location.IsEnd() == 0

with
Code:
!station1_location.IsEnd()


Top
   
 Post subject: Re: SmallTownAI
PostPosted: Sun May 27, 2018 11:28 pm 
Offline
Engineer
Engineer
User avatar

Joined: Thu Apr 05, 2018 4:50 pm
Posts: 11
Location: due west of somewhere...
Quote:
I think you need to replace
Code:
station1_location.IsEnd() == 0

with
Code:
!station1_location.IsEnd()


Thank you! This solved the problem, which means...

Update!
R4: Sensible Stations

The two initial stations now will not be closer than 2 tiles from another station.
Vehicles older than their lifespan will be replaced.


Attachments:
SmallTownAI-R4.tar [27.5 KiB]
Downloaded 21 times
Top
   
 Post subject: Re: SmallTownAI
PostPosted: Mon Jul 30, 2018 1:23 am 
Offline
Engineer
Engineer
User avatar

Joined: Thu Apr 05, 2018 4:50 pm
Posts: 11
Location: due west of somewhere...
Update!
R5

This is a bugfix update that fixes the occasional infinite loop when a new network is created, the building of buses even when no bus station is built, and removes the broken vehicle replacement.


Attachments:
File comment: SmallTownAI R5
SmallTownAI-5.tar [26 KiB]
Downloaded 16 times
Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 17 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2018 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2018.
Hosted by Zernebok Hosting.