AI Common Libraries - (now with AILib.Direction)

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

What do you think

Usefully
23
100%
Useless
0
No votes
 
Total votes: 23

Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI Common Library

Post by Yexo »

Rubidium wrote:
Bilbo wrote:GPL v2+?
I dislike that; if Mr. Stallman writes e.g. GPL v4 that gives someone all rights to do with the stuff what you want to do, like claim it as your own, your library would be rereleasable under those rules. Not sure where you want that.
but using LGPL doesn't fix that:
http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html wrote:3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AI Common Library (Preview version Available)

Post by fanioz »

Hello :D
We have decided to release a Preview version. These libraries are available on 2nd post of this thread. And would not go to Bananas until they're ready :D

If you have a several idea, suggestion or anything that could improve, we're always welcome.
:)
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: AI Common Library

Post by Bilbo »

Yexo wrote:
Rubidium wrote:
Bilbo wrote:GPL v2+?
I dislike that; if Mr. Stallman writes e.g. GPL v4 that gives someone all rights to do with the stuff what you want to do, like claim it as your own, your library would be rereleasable under those rules. Not sure where you want that.
What about GPL v2 or GPL v3? No GPL v4+ (as it does not exist yet), but I think GPL v3 should be fine in addition to GPL v2...
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AI Common Library (Preview version Available)

Post by fanioz »

http://noai.openttd.org/ :: "AIs and AI Libraries, released under (L)GPLv2."
So, the available option was only GPLv2 or LGPLv2.1

I've no idea, but the Queue, Graph and Pathfinder libraries at http://noai.openttd.org/, were released under LGPL v2.1, so this Common Libraries would be under LGPLv2.1 too. (although these wasn't their derivatives)
or do we have to make the license stronger ? (by GPLv2)
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AI Common Library

Post by fanioz »

fanioz wrote: After fixing things around, named this as RC1 version, wich is contain :
...
...
After several svn committ made by (mostly) Yexo, here is the RC-2 version change log:
  • AILib.Common : nothing
  • AILib.Tile : nothing
  • AILib.List :
    • Fix: don't change the value of items while iterating over a list
    • Codechange: use the SORT_ASCENDING and SORT_DESCENDING constants instead of hardcoding true/false
    • Change: add !IsEmpty() as precondition for Peek() and Pop()
    • Fix:Bug#34 :: the index "List" doesn't exist
If everything gonna right, there are a few days to go to Bananas.
If you would like to try first, download links are available on the 2nd post.
Suggestions are always welcome, either would be included in this release or later version.

Cheers :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AI Common Library 1 (Released)

Post by fanioz »

Today, I've decided to release these libraries on Bananas. Sorry for the long time :D
* AILib.Common
* AILib.List
There was no change from RC-2 except the license notice, which is LGPL v2.1. But Bananas did refuse when I try to upload them. So you will see :
* AILib.List -> GPL v2 (would be changed on the next update)
* AILib.Common -> Custom (license.txt was included which is LGPL v.21)


ps:
the AILib.Tile is not released yet, still under construction :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AI Common Libraries - (now with AILib.String)

Post by fanioz »

Added : AILib.String, find it on 3rd post

*There was an html docs attached, however you may look at the code to exactly know what it does.
*And please feel free if you would like to include something missed from this library.
*Again, I 'll need your assistance to determine for a such-good-looking function names :P

:D Cheers
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: AI Common Libraries - (now with AILib.String)

Post by Zuu »

I noticed "IsStartsWith" and "IsEndsWith". Do you have any particular reason for not using correct grammar?

I would suggest "IsStartingWidth" and "IsEndingWidth".
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI Common Libraries - (now with AILib.String)

Post by Yexo »

What about "StartsWith" and "EndsWith"?
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AI Common Libraries - (now with AILib.String)

Post by fanioz »

Zuu wrote:I noticed "IsStartsWith" and "IsEndsWith". Do you have any particular reason for not using correct grammar?
No, I haven't any, as I just guess how to write English correctly. :oops:
Zuu wrote:I would suggest "IsStartingWidth" and "IsEndingWidth".
I guess you would like to write "IsStartingWith" and "IsEndingWith". :?:
Yexo wrote:What about "StartsWith" and "EndsWith"?
Well, the function does return either true or false. So, the name should be begin with "Is" , no?. :?:

Code: Select all

import("AILib.String", "CString", 1);
local my_name = "fanioz";
then (1)

Code: Select all

if (CString.IsStartingWith(my_name, "fan")) {
    //nothing
}
OR (2)

Code: Select all

if (CString.StartsWith(my_name, "fan")) {
    //nothing
}
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: AI Common Libraries - (now with AILib.String)

Post by Zuu »

fanioz wrote:I guess you would like to write "IsStartingWith" and "IsEndingWith". :?:
Yes, also I can do mistakes. :-D
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI Common Libraries - (now with AILib.String)

Post by Yexo »

StartsWith is often used for this function, I can't find any reference to a function named "IsStartingWith". Also squirrel has the built in function "find" which can be used to do the same

Code: Select all

CString.StartsWith("something", "some")
"something".find("some") == 0
static any Left(num, str)
Get left part of string
Built in function slice:

Code: Select all

CString.Left(4, "something")
"something".slice(0, 4)
The rest of the library looks good, nice work.
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AI Common Libraries - (now with AILib.String)

Post by fanioz »

Yexo wrote:

Code: Select all

CString.StartsWith("something", "some")
"something".find("some") == 0

Code: Select all

CString.Left(4, "something")
"something".slice(0, 4)
Well, in fact those function was just a wrapper for 'slice' methods, with a precondition :D
Since those functions doesn't necessary, I would remove them.
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: AI Common Libraries - (now with AILib.String)

Post by Kogut »

No, I never thought that there are build in functions like this.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AI Common Libraries - (now with AILib.String)

Post by fanioz »

Kogut wrote:No, I never thought that there are build in functions like this.
and you did know now :D

Revision 6:
Removed functions: Left(), IsStartsWith(), IsEndsWith()
Added : Enumeration for date format
  • DateYMD
  • DateMDY
  • DateDMY
Added function: Date(). Get date as string.

/**
* Convert date to it string representation
* @param date Date integer to convert
* @param date_format One of DateStr Format
* @return string of date
*/
function Date (date, date_format, separator) {
usage example :

Code: Select all

	 import ("AILib.String", "CString", 1);
	 local cur_date = CString.Date(AIDate.GetCurrentDate(), CString.DateDMY, "-");
	 AILog.Info("Current date " + cur_date);
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AI Common Libraries - (now with AILib.Direction)

Post by fanioz »

AILib.String has gone to Bananas.

It's now time to present :

AILib.Direction - which is actually a splitted version from Zuu's SuperLibrary

Let's go :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: AI Common Libraries - (now with AILib.Direction)

Post by Zuu »

Perhaps you could indent all lines with tabs and not mix spaces and tabs. That makes it much easier to read the code. ( http://noai.openttd.org/svn/lib-directi ... k/main.nut ) You might also want to add an empty line between each constant to increase readability.

Also, since this is more or less a copy of my Directory library (but with modified interface), I would like you to state that in the source code and give proper credits. Also it would be nice if you state that/if the directions are compatible with my library.


Edit: strictly speaking regarding licenses, you are not allowed to use GPL code in a LGPL library. I could put my code there myself as the original author, but you can not take the code and put it there without my permission. In this case, if you just add proper credits, it's fine by me. Please note that in general you need permission from the original author(s) to take GPL code and re-license it as LGPL.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AI Common Libraries - (now with AILib.Direction)

Post by fanioz »

Updated AILib.Common
Updated AILib.List
Updated AILib.String
Updated AILib.Tile
Updated AILib.Direction

Overall :
License was changed to GPL 2.0
Added notice on importing library
Reformatting code to use space instead of tab

New Feature :
AILib.List 2:
  • You should be able to call IsEnd() even if your API compatibility was set to 1.0
    however if API compatibility was set to 1.1 you couldn't call HasNext() at all
Zuu wrote:Perhaps you could indent all lines with tabs and not mix spaces and tabs. That makes it much easier to read the code. ( http://noai.openttd.org/svn/lib-directi ... k/main.nut ) You might also want to add an empty line between each constant to increase readability.

Also, since this is more or less a copy of my Directory library (but with modified interface), I would like you to state that in the source code and give proper credits. Also it would be nice if you state that/if the directions are compatible with my library.


Edit: strictly speaking regarding licenses, you are not allowed to use GPL code in a LGPL library. I could put my code there myself as the original author, but you can not take the code and put it there without my permission. In this case, if you just add proper credits, it's fine by me. Please note that in general you need permission from the original author(s) to take GPL code and re-license it as LGPL.
Thanks for noticing me, I'm sorry. Please check again, or you could just use your right to commit something there.
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: AI Common Libraries - (now with AILib.Direction)

Post by Zuu »

Thanks, this is much better.

I see that you use print("..."); to print license info. IIRC this will only print to the terminal from where OpenTTD is ran, not in the in-game AI debug window. Not sure what is the desired behaviour here, but I wanted to make a notice about it.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: AI Common Libraries - (now with AILib.Direction)

Post by fanioz »

Zuu wrote:Thanks, this is much better.

I see that you use print("..."); to print license info. IIRC this will only print to the terminal from where OpenTTD is ran, not in the in-game AI debug window. Not sure what is the desired behaviour here, but I wanted to make a notice about it.
It did, isn't it ? :D, those line was executed only on first time load with "import" statement.
__
The remaining (not too big) problem was, API compatibility returned by library couldn't win over API compatibility returned by AI. example :
If AILib.List -> return 1.0
And Any_AI -> return 1.1
Then AILib.List wouldn't have HasNext(), but IsEnd() instead.
Attachments
Tanpa nama, 7 Apr 1956.png
Tanpa nama, 7 Apr 1956.png (10.86 KiB) Viewed 2983 times
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 36 guests