Page 7 of 7

Re: OtviAI (version 415)

Posted: 19 Jul 2015 00:21
by Baldy's Boss
In my current Buborough & Penbourne game,OTVI after OTVI has risen to be my closest competitor and then gone bust.Lately the pink OTVI bought a failing NiceCAB that had airports that multiplied the OTVI's infrastructure costs,it had least had some aircraft.
Then the fast-growing yellow OTVI built two international airports that are nearly all its infrastructure cost (7.7 million out of 8.1 million...it also has hundreds of tiles of electric railway but runs no trains) but has no aircraft.This save is April 1999,it was offered to me in bankruptcy in August and went bust by November (I COULD have bought it and nuked those airports,the road vehicle operation was doing well).

If OTVI knew how to get out of bad investments,it would be a really strong competitor.

Re: OtviAI (version 415)

Posted: 16 Aug 2015 01:36
by Baldy's Boss
I'm told this is a feedback loop gone wrong...looks like a bug in OTVI.
(It's generally my closest competitor in games where it's present,but it does have drawbacks).

Re: OtviAI (version 415)

Posted: 27 Apr 2016 13:05
by Wormnest
OTVI v. 418 for several years now keeps trying to use a Kirby Paul as a mail cart? and fails. Trying the same again and again instead of going for something different.
There's also another train in the same depot that's not running.

Re: OtviAI (version 415)

Posted: 16 Sep 2016 16:16
by Kogut
crash

Re: OtviAI (version 415)

Posted: 13 Apr 2018 01:33
by Baldy's Boss
An OTVI in my Sesninghill & Freaway game has gone from nowhere to Chairman level in a few years and is my closest competitor in more ways than one...it bought out another AI whose road alongside the eponymous flagship route stands in the way of landscaping I've wanted to do for ages.

Re: OtviAI (version 415)

Posted: 29 Sep 2018 16:40
by xarick
OtviAI 422, OpenTTD 1.8.0

excessive cpu valuator

Re: OtviAI (version 415)

Posted: 10 Apr 2019 18:29
by xarick
The index 'RONDJE_ALERT' does not exist.
It was trying to complete a subsidy as the first task.

Re: OtviAI (version 415)

Posted: 11 Apr 2021 14:37
by Maninthebox
xarick wrote: 10 Apr 2019 18:29 The index 'RONDJE_ALERT' does not exist.
It was trying to complete a subsidy as the first task.
I have been away for a while, but like others: the Steam release triggered a comeback :) I'll be going in reverse order through the bugs after updating to 1.11 API. Handled this bug first, turns out it was indeed possible that a subsidy was handled before this variable was set. It's fixed, but not yet available in the online download system as I first need to get my account login transferred to the new login :)

Now trying to see whether I can re-use my patches (from 1.3.3...) on 1.11 that I used to do fully automated tests of one or more AIs against a set of configs and scenarios... Time to brush up my Squirrel, C and C++ coding skills.

Re: OtviAI (version 415)

Posted: 15 Apr 2021 15:21
by Maninthebox
Got automated testing up & running again and first tests (after fixing the issues mentioned in this thread) look all ok, so I'll release a new version soon (tm).
all_25_year_competition_666_score.png
all_25_year_competition_666_score.png (15.03 KiB) Viewed 1579 times

Re: OtviAI (version 423?)

Posted: 15 Apr 2021 21:38
by Baldy's Boss
Maninthebox wrote: 15 Apr 2021 15:21 Got automated testing up & running again and first tests (after fixing the issues mentioned in this thread) look all ok, so I'll release a new version soon (tm).
all_25_year_competition_666_score.png
Is 423 the upcoming version or the most recent past version?

Re: OtviAI (version 415)

Posted: 16 Apr 2021 08:30
by Maninthebox
That would be the upcoming version. Currently re-running tests on a number of scenarios/configurations as I discovered a flaw in the logic that dealt with other companies going bankrupt.

Re: OtviAI (version 423)

Posted: 21 Apr 2021 13:32
by Maninthebox
Version 423 is online and should be available via the in-game download system now.

Fixes:
  • * RONDJE_ALERT missing
    * excessive CPU valuator
    * fixed bankruptcy due to buying out really bad companies
    * tram division by zero
    * cart selection for train updated

Re: OtviAI (version 423)

Posted: 24 Apr 2021 16:37
by Baldy's Boss
Maninthebox wrote: 21 Apr 2021 13:32 Version 423 is online and should be available via the in-game download system now.

Fixes:
  • * RONDJE_ALERT missing
    * excessive CPU valuator
    * fixed bankruptcy due to buying out really bad companies
    * tram division by zero
    * cart selection for train updated
I don't see Otvi listed among the AIs in "Check Online Content" at all now...I had been checking for upgrades!
EDIT:I see from revised first post that you are keying to 1.11 so is it not visible to people playing 1.10.3?

It now evaluates potential takeover candidates before jumping in?

Re: OtviAI (version 423)

Posted: 04 Jun 2021 11:41
by Maninthebox
It is indeed targeted for 1.11 and up. I would have to see whether I could lower that to 1.10; I did add a few things that came in API versions 1.9, 1.10 and/or 1.11.

The evaluation of takeover candidates is still very minimal, but at least the AI won't buy another company any more if low on cash; it at least makes sure to be able to have enough money to be able to pay for maintenance etc. It cleans up unprofitable stations, but the maintenance fee might come before being able to clean up.

Re: OtviAI (version 423)

Posted: 08 Apr 2024 21:05
by xarick
OtviAI has in the code a very unoptimized piece that absolutely tanks OpenTTD performance with very long stalls in longer sessions.

I tried to identify the source of the problem and it seems to stem from this part onwards:

Code: Select all

			Debug("Cargo wants to go to town...");
			local townTiles = AITileList();
			local min = MIN_DISTANCE;
			local max = MAX_DISTANCE;
			SafeAddRectangle(townTiles, place1, max, min);
			Debug("Made a list of this many tiles: " + townTiles.Count() + ", min: " + min + ", Max: " + max);
			while (townTiles.Count() > 150000) { // TODO Guessed value to prevent CPU excessive usage error
				min++;
				max--;
				townTiles = AITileList();
				SafeAddRectangle(townTiles, place1, max, min);
				Debug("Adapted list to this many tiles: " + townTiles.Count() + ", min: " + min + ", Max: " + max);
			}

Code: Select all

/**
 * Add a rectangular area to an AITileList containing tiles that are within /radius/
 * tiles from the center tile, taking the edges of the map into account.
 */  
function SafeAddRectangle(list, tile, radius, exclude_radius = 0) {
	if (tile == null) {
		Error("Got a nullpointer");
		return;
	}

	local x1 = max(1, AIMap.GetTileX(tile) - radius);
	local y1 = max(1, AIMap.GetTileY(tile) - radius);
	
	local x2 = min(AIMap.GetMapSizeX() - 2, AIMap.GetTileX(tile) + radius);
	local y2 = min(AIMap.GetMapSizeY() - 2, AIMap.GetTileY(tile) + radius);
	
	list.AddRectangle(AIMap.GetTileIndex(x1, y1),AIMap.GetTileIndex(x2, y2));

	if (exclude_radius > 0) {
		x1 = max(1, AIMap.GetTileX(tile) - exclude_radius);
		y1 = max(1, AIMap.GetTileY(tile) - exclude_radius);

		x2 = min(AIMap.GetMapSizeX() - 2, AIMap.GetTileX(tile) + exclude_radius);
		y2 = min(AIMap.GetMapSizeY() - 2, AIMap.GetTileY(tile) + exclude_radius);

		list.RemoveRectangle(AIMap.GetTileIndex(x1, y1),AIMap.GetTileIndex(x2, y2));
	}
}
The number of tiles count can start as large as 1 500 000 tiles, but the adjustments after are a major source of stalls. The act of discarding the list, adding a rectangle with a million tiles to the list and removing a rectangle from the list until it fits the criteria of 150 000 tiles can take up to 16 seconds to complete on my system! That is a stall of 16 seconds where OpenTTD is unresponsive!

I edited this part of the code and made the min and max changes happen without requiring to constantly change lists. It's much faster as the rectangle is only added/removed when the 150 000 criteria is met, which is a more manageable amount.

Code: Select all

			Debug("Cargo wants to go to town...");
			local townTiles = AITileList();
			local min = MIN_DISTANCE;
			local max = MAX_DISTANCE;
			local res = SafeAddRectangle(townTiles, place1, max, min, 150000);
			min = res.min;
			max = res.max;
			Debug("Made a list of this many tiles: " + townTiles.Count() + ", min: " + min + ", Max: " + max);

Code: Select all

/**
 * Add a rectangular area to an AITileList containing tiles that are within /radius/
 * tiles from the center tile, taking the edges of the map into account.
 */
function SafeAddRectangle(list, tile, radius, exclude_radius = 0, max_tiles = null) {
	if (tile == null) {
		Error("Got a nullpointer");
		return;
	}

	local rx1;
	local ry1;

	local rx2;
	local ry2;

	local ex1;
	local ey1;

	local ex2;
	local ey2;

	local area_radius;
	local exclude_area_radius = 0;
	local num_tiles;

	do {
		rx1 = max(1, AIMap.GetTileX(tile) - radius);
		ry1 = max(1, AIMap.GetTileY(tile) - radius);

		rx2 = min(AIMap.GetMapSizeX() - 2, AIMap.GetTileX(tile) + radius);
		ry2 = min(AIMap.GetMapSizeY() - 2, AIMap.GetTileY(tile) + radius);

		area_radius = (rx2 - rx1 + 1) * (ry2 - ry1 + 1);

		if (exclude_radius > 0) {
			ex1 = max(1, AIMap.GetTileX(tile) - exclude_radius);
			ey1 = max(1, AIMap.GetTileY(tile) - exclude_radius);

			ex2 = min(AIMap.GetMapSizeX() - 2, AIMap.GetTileX(tile) + exclude_radius);
			ey2 = min(AIMap.GetMapSizeY() - 2, AIMap.GetTileY(tile) + exclude_radius);

			exclude_area_radius = (ex2 - ex1 + 1) * (ey2 - ey1 + 1);
		}

		num_tiles = area_radius - exclude_area_radius;
	}
	while (max_tiles != null && num_tiles > max_tiles && radius-- && exclude_radius++);

	list.AddRectangle(AIMap.GetTileIndex(rx1, ry1), AIMap.GetTileIndex(rx2, ry2));
	if (exclude_radius > 0) list.RemoveRectangle(AIMap.GetTileIndex(ex1, ey1), AIMap.GetTileIndex(ex2, ey2));
	if (max_tiles != null) return {	max = radius, min = exclude_radius };
}
Hoping for a fix on OtviAI.