Can an AI read/write files?

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

Post Reply
SummerBulb
Engineer
Engineer
Posts: 24
Joined: 06 Feb 2010 22:12

Can an AI read/write files?

Post by SummerBulb »

Hi,

Can an AI perform I/O on files while running?

SummerBulb
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Can an AI read/write files?

Post by Rubidium »

No.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Can an AI read/write files?

Post by Zuu »

If you for development reasons want to output data to a file that is possible with a bit of work.

In non-windows you just run OpenTTD with high enough debug level for the ai category so that AILog message come out at stdout/stderr and then save that to a file. In windows you need to either convert openttd.exe to a console application or make some modifications and compile your own custom build for that.

Add a start and stop flag for the data you want to export and use a script / sed / grep that look for this flag in the log file to extract the data you are interested in.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
SummerBulb
Engineer
Engineer
Posts: 24
Joined: 06 Feb 2010 22:12

Re: Can an AI read/write files?

Post by SummerBulb »

Is there a reason why save text files is disabled?

Having that possibilty will be of great use.

SummerBulb
Blustuff
Engineer
Engineer
Posts: 112
Joined: 21 Aug 2008 09:37
Location: France

Re: Can an AI read/write files?

Post by Blustuff »

You can read any Squirrel File, and Squirrel has a syntax similar to ECMa so you can define data using nearly JSON.
You can't write in files, but you can write in savedgames by implementing Save and Load function in yout AIController. This would be enough for most of the cases. But, writing in text files may not be in the philosophy of NoAI. Would it be good that an AI behaviour depends on something else than the game and a random source ?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Can an AI read/write files?

Post by Zuu »

For development purpose such as some kind of evolution or learning it is fully possible to work around the restriction. You can export data via the log and then you can import data by modifying the nut files. Write a helper script/program that reads the logs and put the data into a nut file that the AI can read when you load a save game or start a new game etc.

The restriction is there so that you can't store things between different games.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 5 guests