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

User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

AI Common Libraries - (now with AILib.Direction)

Post by fanioz »

The Idea :
>> Common library that would be useful for all AI writers. This should be written by, from and for all AI writers.

Scope :
>> Every problem that can be solved using squirrel, included but not limited to Math, String, even extension to current API (tile, vehicle, cargo, industry etc..)

Contributors :
>> All AI writer

Administrator
>> Yexo, fanioz

Registered Developer
>> Zutty, Zuu

Every body could register here :D
Last edited by fanioz on 26 Jun 2010 10:17, edited 10 times in total.
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 »

Project Host :
  • Lib common : Series of library that contain assorted function that hopefully to be useful for many AI writers.
  • Lib List : An improvement of API - AIList, which can call do command inside valuator and several other functions
  • Lib Tile : Improvement on API - AITile functions
  • Lib String : Provide string handling
  • Lib Direction : Provide direction handling for AI

License : GPl 2.0

Download Links (Bananas) Documentation
Check Out here

Download Links (Non-Bananas)
Attachments
AILib.Tile.1.tar
(10 KiB) Downloaded 773 times
Last edited by fanioz on 19 Aug 2010 03:33, edited 17 times in total.
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 »

Library Tester

It's here to test AI Common Libraries Project functions.

Make sure you have the latest Libraries in 2nd post.
Put Test.tar inside your /ai folder
Load Lib_Test.sav in OpenTTD (nightly)
Look at AI's Log and Game Map
:D

edit : note that AILib.Tile test wasn't included yet
Attachments
Lib_Test.sav
Saved Test Game for Library Tester
(12.12 KiB) Downloaded 268 times
test.tar
(20 KiB) Downloaded 324 times
Last edited by fanioz on 14 Jul 2010 05:12, edited 7 times in total.
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI Common Library

Post by Yexo »

fanioz wrote:pload this to Bananas)
>> mmmmm............ I think Yexo :D
If you want me to do it, that's fine, but I think it should be the general maintainer of the library (I think we should appoint someone who is responsible for merging patching and keeping the latest version), and why would that not be you, fanioz? After all, you've taken the time to start it.

Let's be very clear from the start that this library is GPL v2 (I hope you all agree :p).

I've looked through your files, and they seems to be nice.Some comments:
1. Since r17043 it's possible to subclass API classes without problems, so you don't have to wrap all AIAbstractList functions.
2. AbstractList::SetItemValue returns ar without ever defining it.
3. Did you test CountIfRemoveAboveValue/CountIfRemoveValue? I'm not sure, but I think that "local tmp = this._list;" just makes another reference to the same list, so you still remove the items from the original list. Easiest solution (untested):

Code: Select all

local tmp = AIList().AddList(this._list);
Blustuff
Engineer
Engineer
Posts: 112
Joined: 21 Aug 2008 09:37
Location: France

Re: AI Common Library

Post by Blustuff »

Yexo wrote:I'm not sure, but I think that "local tmp = this._list;" just makes another reference to the same list, so you still remove the items from the original list.
That's absolutely right. Since copy of objects is a common operation, Squirrel use the keyword "clone" to explicitely copy an objet. Note that it only clone one level, subobjects are not cloned. Hopefully this would work :

Code: Select all

local tmp = clone this._list;
but I think it won't since there probably no _cloned metamethod for AIAbstractList which is able to clone internal representation of the list. The solution of Yexo seems to be the best.
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 »

Yexo wrote:If you want me to do it, that's fine, but I think it should be the general maintainer of the library (I think we should appoint someone who is responsible for merging patching and keeping the latest version), and why would that not be you, fanioz? After all, you've taken the time to start it.
This will go to vote to ... :D I believe you will be the winner. :mrgreen:
Yexo wrote: Let's be very clear from the start that this library is GPL v2 (I hope you all agree :p).
Of course yes.
Yexo wrote: I've looked through your files, and they seems to be nice.Some comments:
1. Since r17043 it's possible to subclass API classes without problems, so you don't have to wrap all AIAbstractList functions.
I didn't know that, will try it to night :)
Yexo wrote: 2. AbstractList::SetItemValue returns ar without ever defining it.
Typos .. :oops:
Yexo wrote: 3. Did you test CountIfRemoveAboveValue/CountIfRemoveValue? I'm not sure, but I think that "local tmp = this._list;" just makes another reference to the same list, so you still remove the items from the original list. Easiest solution (untested):

Code: Select all

local tmp = AIList().AddList(this._list);
Thanks for better solution :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI Common Library

Post by Yexo »

fanioz wrote:
Yexo wrote: I've looked through your files, and they seems to be nice.Some comments:
1. Since r17043 it's possible to subclass API classes without problems, so you don't have to wrap all AIAbstractList functions.
I didn't know that, will try it to night :)
r17043 was committed after you posted your library, so it wasn't possible before :p (guess what was the reason for that commit)
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 »

Yexo wrote: r17043 was committed after you posted your library, so it wasn't possible before :p (guess what was the reason for that commit)
However... Thanks :D (thats happen too, long time ago :D )

==========
Okay All, :D
Have no time yet to generate html documentation now, please read the code instead, or read below :D

After fixing things around, named this as RC1 version, wich is contain :

1. AILib.Common :
--function ACall() an acall replacement to allow you execute do command with array as arguments
--function GetVersion() return the table of current version of OTTD ran
--Class AIRoadTypeList() to get available Road type in game as AIList
--Class AIPlaneTypeList() to get all plane type as AIList
(the last two class above would be removed if API made them)

2. AILib.List :
--extends AIList() with several new function
--constructor argument is now optional.
--Not overriding Valuate -- not changed
--function DoValuate -- if what you want is to execute do command inside valuator. It need "this" as argument
--Integrating AITileList() methode with new implementation.
--Emulate Queue mode (Pop, Peek, Push) <- ambiguous isn't ..?

3.AILib.Tile ::
-- extends AITile. Right now only two function available
-- Tile.IsMine() to check if I am the owner
-- Tile.IsCompetitorTile() to check if my competitor owned that.

However, my english is not that good, I really need your correction for such a function names, or documentation to make this library self-descriptive.

Another question :: Which is better, Make this all as single library or separate them for each category. ?
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI Common Library

Post by Yexo »

I haven't looked through your new source code yet, but your overview of functions is nice.
fanioz wrote:However, my english is not that good, I really need your correction for such a function names, or documentation to make this library self-descriptive.
All function names look ok.
Another question :: Which is better, Make this all as single library or separate them for each category. ?
I'm in favor of making a different library for each class you have above.
User avatar
AndersI
Tycoon
Tycoon
Posts: 1732
Joined: 19 Apr 2004 20:09
Location: Sweden
Contact:

Re: AI Common Library

Post by AndersI »

fanioz wrote:-- Tile.IsMine() to check if I am the owner
My first thought was that this would check if there was a mining industry on the tile. I'm playing too much Civilization (and clones), probably :-)
-- Tile.IsCompetitorTile() to check if my competitor owned that.
To be consistent, I think the names should be:

- Tile.IsMyTile() and Tile.IsCompetitorTile()

or

- Tile.IsMine() and Tile.IsCompetitors()
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI Common Library

Post by Yexo »

AndersI wrote:To be consistent, I think the names should be:

- Tile.IsMyTile() and Tile.IsCompetitorTile()
or
- Tile.IsMine() and Tile.IsCompetitors()
I prefer the first option (IsMyTile/IsCompetitorTile)
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 »

Yexo wrote:
AndersI wrote:To be consistent, I think the names should be:

- Tile.IsMyTile() and Tile.IsCompetitorTile()
or
- Tile.IsMine() and Tile.IsCompetitors()
I prefer the first option (IsMyTile/IsCompetitorTile)
Change in AILib.Tile


changed function name :
Tile.IsMine() => Tile.IsMyTile();

Added code : From this thread

Code: Select all

/**
 * Gets the TileIndex relatively from given offset. 
 * @param tile Start tile index
 * @param x The X coordinate.
 * @param y	The Y coordinate.
 * @return Tile index
 */ 
function Tile::AddOffset(tile, x, y)
{
	/* pre-condition */
	if (!AIMap.IsValidTile(tile)) return -1;
	local tx = AIMap.GetTileX(tile) + x;
	local ty = AIMap.GetTileY(tile) + y;
	if (tx < 1) return -1;
	if (ty < 1) return -1;
	if (tx > (AIMap.GetMapSizeX() - 2)) return -1;
	if (ty > (AIMap.GetMapSizeY() - 2)) return -1;
	/* ==== */
	return AIMap.GetTileIndex(tx, ty);
}

=====
Please look at the precondition, is the behaviour of AddOffset() function is ok?
also there is no INVALID_TILE enumeration, so I've decided to use -1 instead. Which is should be an Invalid Tile :D
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: AI Common Library

Post by Zutty »

This is quite a good idea. Are any of the functions in here of use to you?...

http://code.google.com/p/ottd-noai-path ... common.nut
PathZilla - A networking AI - Now with tram support.
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 »

Zutty wrote:This is quite a good idea. Are any of the functions in here of use to you?...

http://code.google.com/p/ottd-noai-path ... common.nut
Wow.......... :o very much functions there, i think I should divide them for each category. Thanks :mrgreen:
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
svetovoi
Engineer
Engineer
Posts: 87
Joined: 12 Oct 2007 14:07

Re: AI Common Library

Post by svetovoi »

The idea of such library is really great, it'll be very useful.
After reading this topic, I think there is thing in my AI, that could be in library (i.e. if it were in some library, I would not write it, and would be happy).
For own AI(yeah, I'm writting one) I've made a small event system, and today rewrited it to a library form.
Hope you find it useful.
Attachments
Lib.Event.1.tar
Libary with event system code.
(6 KiB) Downloaded 232 times
Lib.Event.1.example.txt
How to use example.
(1.73 KiB) Downloaded 244 times
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 »

ac84 wrote:The idea of such library is really great, it'll be very useful.
After reading this topic, I think there is thing in my AI, that could be in library (i.e. if it were in some library, I would not write it, and would be happy).
For own AI(yeah, I'm writting one) I've made a small event system, and today rewrited it to a library form.
Hope you find it useful.
:D thanks for contributing. It seems interesting, although I've only look at example
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:Let's be very clear from the start that this library is GPL v2 (I hope you all agree :p).
Errr .... could it be GPL v2+? GPL v3 / GPL v3+ is gaining popularity, so unless someone is opposed to GPL v3, maybe we should stick to v2+ to allow combinging with GPL v3 code.
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
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: AI Common Library

Post by SirkoZ »

Really nice work, fanioz.
Vote for GPL: I say GPL v2. Why would anyone even want v3?
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: AI Common Library

Post by Rubidium »

Yexo wrote:Let's be very clear from the start that this library is GPL v2 (I hope you all agree :p).
I disagree with making it GPLv2; GPLv2 would mean that linking to it makes your AI GPLv2 too. I'd go for LGPLv2, which is the generally accepted 'GPLv2' for libraries.
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.
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: AI Common Library

Post by Bilbo »

And what about GPL v2 or v3 (without possibility of 4+)? The problem with GPL2 and GPL3 is that while they are essentially very similar, they are incompatible. And many new projects choose GPL3 or GPL3+ to start. So combining GPL2 and GPL3 code is impossible. LGPL2 would solve that too, though :)
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)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 9 guests