AI Tornament?

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

User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

AI Tornament?

Post by Lord Aro »

A long time ago, in a galax...
No, it was here actually. :lol:
Truebrain used to run an AI tornament, but (presumably due to his inactivity), it is now offline.
Any chance of getting it back?
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: AI Tornament?

Post by Zuu »

A good way to increase the probability of the AI tournaments happening soon is to make it happen yourself.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: AI Tornament?

Post by planetmaker »

Lord Aro wrote:A long time ago, in a galax...
No, it was here actually. :lol:
Truebrain used to run an AI tornament, but (presumably due to his inactivity), it is now offline.
Any chance of getting it back?
It's moderately easy to setup one yourself; just seethis thread where Roujin started with one, but also subsequently other Battle Royals were added; such thing took me usually a full evening, though. Choose a map, choose a list of AIs and just start the game. Make sure to enable debuging in the AIs and possibly to document the game from time to time. AI authors will love you, if you give valuable feedback based on that experience.There more such runs are made, the better the overall ability to assess the strengths and weaknesses of the AIs; that may depend very much upon the settings.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI Tornament?

Post by Lord Aro »

Ok, i sort of guessed i might get the "do it yourself" sort of answers. ;)
I could do that, but my slow computer usually means it would take a whole day!
Some questions:
- how was truebrains tornament different?
- how hard would it be to set up again (e.g. on a home computer)?

- if i were to do a AI Battle Royale (or whatever), what sort of settings are involved? (e.g. no. of yrs, difficulty setting, etc)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: AI Tornament?

Post by planetmaker »

Lord Aro wrote:Ok, i sort of guessed i might get the "do it yourself" sort of answers. ;)
I could do that, but my slow computer usually means it would take a whole day!
Some questions:
- how was truebrains tornament different?
- how hard would it be to set up again (e.g. on a home computer)?

- if i were to do a AI Battle Royale (or whatever), what sort of settings are involved? (e.g. no. of yrs, difficulty setting, etc)
I basically just chose settings which I like. Somewhat rough landscape, not too many newgrf... it really depends. Important is actually only that you know and state the important game settings which make a difference ;-)

Outcome (and needed time) certainly will be different if you
- run one game with all AI (as Roujin and I did)
- run several games with the exact same map and settings, but one AI only.

Unless you have a really slow home computer that shouldn't stress your computer too much, and game time has kinda a fixed pace. I do all OpenTTD things on a laptop...
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: AI Tornament?

Post by Kogut »

Or you can leave computer for night.
And settings - you can try with full standard to sth completely strange with bloody newgrfs :D
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI Tornament?

Post by Lord Aro »

Kogut wrote:Or you can leave computer for night.
can't because it in my bedroom :roll:

settings = whatever i want, as long as i say what they are :]

and again, because i want an answer :mrgreen: :
Lord Aro wrote: Some questions:
- how was truebrains tornament different?
- how hard would it be to set up again (e.g. on a home computer)?)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: AI Tornament?

Post by Rubidium »

Lord Aro wrote:- how was truebrains tornament different?
It ran from a script and had some custom code to open some windows upon starting OpenTTD, to make screenshots and to stop at a particular time. So the major difference is that TrueBrain's tournament ran mostly automatically.
Lord Aro wrote:- how hard would it be to set up again (e.g. on a home computer)?
Not that hard, you just need to know how to open the windows, how to make the screenshots and how to stop OpenTTD.
Attachments
tb_tournament.diff
Lovely, old, AS-IS, without any support and the latest one I could find. Maybe the ones with images were hand made?
(10.57 KiB) Downloaded 118 times
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI Tornament?

Post by Lord Aro »

Rubidium wrote:
Lord Aro wrote:- how was truebrains tornament different?
It ran from a script and had some custom code to open some windows upon starting OpenTTD, to make screenshots and to stop at a particular time. So the major difference is that TrueBrain's tournament ran mostly automatically.
Lord Aro wrote:- how hard would it be to set up again (e.g. on a home computer)?
Not that hard, you just need to know how to open the windows, how to make the screenshots and how to stop OpenTTD.
ok, can i get a copy of the last/latest version from anywhere?
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: AI Tornament?

Post by Attila7 »

As I am also testing my AI at this time, I would be interested in what you think the major settings should be to give a nice range of tests.

I have been testing with:

No. of towns: Normal or High
No. of industries: Normal
Max initial loan: 100,000 pounds
Interest: 4%
Vehicle running cost: Medium
Construction speed of competitors: Fast
Vehicle breakdown: Normal
Subsidy multiplier: x1.5
Cost of construction: High
Terrain type: Flat
Quantity of sea/lakes: Medium
Economy: Fluctuating
Train reversing: At end of line and at stations
Disasters: Off
City council: Hostile

Allow building on slopes and coasts: On
Autoslope: On

Max trains: 500
Max RV: 500
Max air: 200
Max ship: 300
Plane speed: 1/4
Plane crashes: Normal

Allow joining stations not directly adjacent: On
Allow town controlled noise level for airports: On

I would like to know what other settings might make or break AI behaviour?
Also, what are the major GRfs that you play/test with?

We can then make a number of test setups that everyone can test with in preparation for the tournaments.
Attila
"Artificial intelligence is no match for natural stupidity."
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

Re: AI Tornament?

Post by Brumi »

I think for AI testing it's best to set the construction speed of competitors to 'Very fast'. You have to wait less for some results to come.
Anyway, I think the settings that influence the outcome greatly:
  • Max initial loan
  • Terrain type - height and smoothness
  • Map size - This determines the amount of competition between AIs. Samu's 256x256 test was a typical example how this can be a decisive factor.
  • Realistic acceleration for trains - if this one is disabled and you're playing on a mountainous map, it will be a hard time for train using AIs.
  • Maximum number of aircraft - Plane using AIs may suffer if this one is low.
  • The starting date - some AIs do better with certain starting dates.
Probably I've left out some important ones, I hope the others will add them :)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: AI Tornament?

Post by Kogut »

Vehicles never expire - it may have effects on AIs
climate (pax ais are worse on desert/arctic)
disable foo for ai competitors
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI Tornament?

Post by Lord Aro »

ok, i'm attempting to run TrueBrains tournament, and have run into some problems, i'm not that experienced with python, so if someone could give me a hand, that would be lovely :wink:

current error:

Code: Select all

the_overlord@Toby-Linux:~/tournament-hg-3c6aa93c9223$ ./run.py
|-- Tournament (group) running (18 AIs)
Traceback (most recent call last):
  File "./run.py", line 53, in <module>
    res = tournament.run(2, configure = ["cfgs/default.cfg", "cfgs/default.cfg"], seed = [random.randint(0, 2147483647), random.randint(0, 2147483647)], years = years)
  File "/home/the_overlord/tournament-hg-3c6aa93c9223/tournaments/group/game.py", line 38, in run
    return self.runTournament(1, self.ai_list, rounds, configure = configure, scenario = scenario, seed = seed, years = years)
  File "/home/the_overlord/tournament-hg-3c6aa93c9223/tournaments/group/game.py", line 58, in runTournament
    poule.run(rounds = rounds, configure = configure, scenario = scenario, seed = seed, years = years)
  File "/home/the_overlord/tournament-hg-3c6aa93c9223/tournaments/group/poule.py", line 24, in run
    matches[i].run(configure = configure[i], scenario = scenario[i], seed = seed[i], ticks = years * 366 * 74 + 20)
  File "/home/the_overlord/tournament-hg-3c6aa93c9223/lib/match.py", line 37, in run
    out_file = open("game/scripts/game_start.scr", "w")
IOError: [Errno 2] No such file or directory: 'game/scripts/game_start.scr'
can i guess from this a 'game_start.scr' is missing? can i also guess that only TrueBrain will have (had) a copy of this?

also, as i'm not too sure (no documentation or anything), where is the OTTD binary to be located in relation to the python scripts? it would appear to me to be one directory up, e.g.

Code: Select all

........
        tournament
                run.py
                *other tournament related files*
                game
                        *others*
                        scripts
                                 game_start.scr
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI Tornament?

Post by Yexo »

Since scripts/game_start.scr is a file that is executed by openttd whenver a new game is started, I expect that you have to install openttd in the game/ directory.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI Tornament?

Post by Lord Aro »

ok, i think i'm getting somewhere, but something's going wrong

output text file:
output.txt
(45.59 KiB) Downloaded 127 times
as you can see, it just returns the same result for every AI
it also generates a cfgs folder in the OpenTTD binary with a content_download, save, scenario (usual folders inside them)

i'm doing something wrong, so i guess i need to contact TrueBrain, so what's the best way? here, pm, irc?
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI Tornament?

Post by Yexo »

A normal OpenTTD binary won't work, you need to compile it yourself with the patch Rubidium gave you. If that doesn't work too, you'll need to do some debugging yourself. You are the one who wants to run a tournament.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI Tornament?

Post by Lord Aro »

oh woops, must have missed that. trying now
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI Tornament?

Post by Lord Aro »

am trying to bump patch to trunk (r20632) and have run into some problems...

original patch says:

Code: Select all

Index: src/economy.cpp
===================================================================
--- src/economy.cpp	(revision 15254)
+++ src/economy.cpp	(working copy)
...*other stuff*....
@@ -1481,6 +1485,13 @@
 				st->time_since_unload = 0;
 
 				/* handle end of route payment */
+				switch (v->type) {
+					case VEH_TRAIN:    GetCompany(v->owner)->deliver_rail += cp->count; break;
+					case VEH_ROAD:     GetCompany(v->owner)->deliver_road += cp->count; break;
+					case VEH_AIRCRAFT: GetCompany(v->owner)->deliver_air  += cp->count; break;
+					case VEH_SHIP:     GetCompany(v->owner)->deliver_ship += cp->count; break;
+					default: break;
+				}
 				Money profit = DeliverGoods(cp->count, v->cargo_type, cp->source, last_visited, cp->source_xy, cp->days_in_transit, &industry_set);
 				cp->paid_for = true;
 				route_profit   += profit; // display amount paid for final route delivery, A-D of a chain A-B-C-D
however, the bit of code which is relevant in r20632 is this (i think) (starts at line 1057)

Code: Select all

void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count)
{
	if (this->owner == NULL) {
		this->owner = Company::Get(this->front->owner);
	}

	/* Handle end of route payment */
	Money profit = DeliverGoods(count, this->ct, this->current_station, cp->SourceStationXY(), cp->DaysInTransit(), this->owner, cp->SourceSubsidyType(), cp->SourceSubsidyID());
	this->route_profit += profit;

	/* The vehicle's profit is whatever route profit there is minus feeder shares. */
	this->visual_profit += profit - cp->FeederShare();
}
these are entirely different and the v parameter used in the original patch is gone...
i can just about bump patches to trunk, but when things start going missing i get a bit lost... :roll:
of course, if i've just got the wrong area of code i'm looking at, if someone could just point me in the right direction, i'd be on my way :wink:

cookies to anyone that can help! :bow:
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI Tornament?

Post by Yexo »

You'll have to use this->front instead of v, so just add

Code: Select all

const Vehicle *v = this->front;
above the switch block. And instead of GetCompany(v->owner) you should use this->owner.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI Tornament?

Post by Lord Aro »

i knew there was a reason you're a developer :lol:

next:
while running make (yes, i've got that far), i get this error:

Code: Select all

[SRC] Compiling date.cpp
/home/the_overlord/coding/OTTD/ottdsrc/trunk/src/date.cpp: In function ‘void IncreaseDate()’:
/home/the_overlord/coding/OTTD/ottdsrc/trunk/src/date.cpp:278: error: ‘FOR_ALL_COMPANIES’ was not declared in this scope
/home/the_overlord/coding/OTTD/ottdsrc/trunk/src/date.cpp:278: error: expected ‘;’ before ‘{’ token
/home/the_overlord/coding/OTTD/ottdsrc/trunk/src/date.cpp:361: error: expected ‘}’ at end of input
/home/the_overlord/coding/OTTD/ottdsrc/trunk/src/date.cpp:361: error: expected ‘}’ at end of input
/home/the_overlord/coding/OTTD/ottdsrc/trunk/src/date.cpp: At global scope:
/home/the_overlord/coding/OTTD/ottdsrc/trunk/src/date.cpp:191: warning: ‘void OnNewYear()’ defined but not used
/home/the_overlord/coding/OTTD/ottdsrc/trunk/src/date.cpp:229: warning: ‘void OnNewMonth()’ defined but not used
/home/the_overlord/coding/OTTD/ottdsrc/trunk/src/date.cpp:251: warning: ‘void OnNewDay()’ defined but not used
make[1]: *** [date.o] Error 1
make[1]: Leaving directory `/home/the_overlord/coding/OTTD/ottdsrc/trunk/objs/release'
make: *** [all] Error 1
code snippet it's complaining about:

Code: Select all

Index: src/date.cpp
===================================================================
--- src/date.cpp	(revision 20632)
+++ src/date.cpp	(working copy)
...*other-stuff*....
@@ -271,6 +273,64 @@
 	/* increase day, and check if a new day is there? */
 	_tick_counter++;
 
+	if (*VideoDriver_Null::GetCurrentTicks() == *VideoDriver_Null::GetTicks() - 10) {
+		Company *c;
+		FOR_ALL_COMPANIES(c) {
+			int32 profit_ship,  profit_road,  profit_train,  profit_air;
+			int32 deliver_ship, deliver_road, deliver_train, deliver_air;
+			int32 amount_cash,  amount_loan,  amount_company;
+			int32 town_rating,  cargos;
+
+			profit_ship    = 0;
+			profit_road    = 0;
+			profit_train   = 0;
+			profit_air     = 0;
+
+			{
+				Vehicle *v;
+				FOR_ALL_VEHICLES(v) {
+					if (v->owner != c->index) continue;
+					if (v->IsPrimaryVehicle()) {
+						switch (v->type) {
+							case VEH_SHIP:     profit_ship  += v->profit_last_year; break;
+							case VEH_ROAD:     profit_road  += v->profit_last_year; break;
+							case VEH_TRAIN:    profit_train += v->profit_last_year; break;
+							case VEH_AIRCRAFT: profit_air   += v->profit_last_year; break;
+							default: NOT_REACHED();
+						}
+					}
+				}
+
+				profit_ship  >>= 8;
+				profit_road  >>= 8;
+				profit_train >>= 8;
+				profit_air   >>= 8;
+			}
+
+			deliver_ship   = c->deliver_ship;
+			deliver_road   = c->deliver_road;
+			deliver_train  = c->deliver_rail;
+			deliver_air    = c->deliver_air;
+
+			amount_cash    = c->money;
+			amount_loan    = c->current_loan;
+			amount_company = CalculateCompanyValue(c);
+
+			cargos         = CountBits(c->cargo_types);
+			town_rating    = 0;
+
+			Town *t;
+			int towns = 0;
+			FOR_ALL_TOWNS(t) {
+				town_rating += t->ratings[c->index];
+				towns++;
+			}
+			town_rating /= towns;
+
+			printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", (byte)c->index, profit_ship, profit_road, profit_train, profit_air, deliver_ship, deliver_road, deliver_train, deliver_air, amount_loan, amount_cash, amount_company, cargos, town_rating);
+		}
+	}
+	
	if (_game_mode == GM_MENU) return;

 	_date_fract++;
i personally suspect the FOR_ALL_[COMPANIES/VEHICLES/TOWNS] bit, but i'm probably wrong :roll:
free cookies available as usual! :mrgreen: :bow:
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests