Finding starting positions?

Finding starting positions?

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Finding starting positions?

Post by PauloMorfeo »

When I start playing a map I remember from the lobby what the possible starting positions where.

As for an AI, I've been looking but there appears to be no way to extract from the map, or from the game's definitions, what starting positions were used, right?

Nor starting positions type (if random, specific or within a specified box), right?

Cheating to find that out won't work if the engine is connected to anyone else other than the local AIs (and possibly host), right?
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Finding starting positions?

Post by Silentwings »

As for an AI, I've been looking but there appears to be no way to extract from the map, or from the game's definitions, what starting positions were used, right?
If the map uses mapinfo.lua instead of the older format, you can load this file directly from the VFS and just check the table of stratpoints. However, many maps use the older format, which lua cannot load. But there is another problem too - games can and sometimes do override these startpoints (BA, for example, does so in several ways e.g. http://springrts.com/phpbb/viewtopic.php?f=44&t=31849 and http://imolarpg.dyndns.org/trac/balates ... uesser.lua).

If all you want to know is where the starting units were actually placed, as opposed to the possible locations where they could have been placed, you can check it by calling Spring.GetAllUnits (or equivalent via whichever AI wrapper you are using) and sorting through them. It would be best to do this at maybe gameframe ~10, after the game has had a bit of time to sort out its startup stuff.

If you know which game you are writing an AI for - some (maybe even most) games expose the table of startpoints that were actually used to GG, so it is probably worth checking out their spawning gadget.
Nor starting positions type (if random, specific or within a specified box), right?
You can't extract that from the map/game definitions because it is an option set in startscript.
Cheating to find that out won't work if the engine is connected to anyone else other than the local AIs (and possibly host), right?
I don't work on AIs myself, but I am pretty sure that AIs can cheat (i.e. access synced info outside of los) regardless of whether they are running on the host or not.
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: Finding starting positions?

Post by lamer »

PauloMorfeo wrote: Nor starting positions type (if random, specific or within a specified box), right?
As for starting boxes you can investigate output of callback->GetGame()->GetSetupScript().
It should have startrecttop, startrectbottom, startrectleft, startrectright params that defines starting box for each allyteam. Also there is startpostype that defines position type (thus you can send desired position with callback->GetGame()->SendStartPosition(false, pos) if startpostype==CGameSetup::StartPosType::StartPos_ChooseInGame but only with engine >= 98.0).
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Finding starting positions?

Post by Jools »

I don't think it's fair to say that most games define own start positions, iirc it's only ba and this also only for some maps.

Getting all units at start may not be accurate either, that would include animals and other units on gaia team, gaia team is sometimes used as the zombie's team. I would also not work for missions where units can be placed anywhere at start.

Also note that there used to be an automatic placing of the commander at 0,0 before game started (http://springrts.com/mantis/view.php?id=4294), but that seems to now be corrected or at least I could not reproduce it. But therefore some older gadgets check if start position is different from -100,-100, some newer check if it's > 0,0 and now you can probably just check if it's >= 0,0.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Finding starting positions?

Post by Silentwings »

say that most games define own start positions
No one said it.
iirc it's only ba
No - there are some other games/maps that do so, although admittedly the majority of such cases that I know of are variants/copies of my code (and I am happy to see it used). As to what happens in the future, who knows.
and this also only for some maps.
That's wrong.
Getting all units at start may not be accurate either, that would include ...
@PaulMorpheus; To make it clear, there is no fully reliable way to determine which units are used by which games as start units and you just have to hardcode something game dependent for each game you want to cover :( But what you can do, as I said above, is that if you know which units (or unitdefs) these are, you can at least find out where they are.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Re: Finding starting positions?

Post by PauloMorfeo »

Thanks for the answers. Plenty of good ideas that I'm going to investigate.
- mapinfo.lua (seems of very low reliability - going to have a look at some maps)
- cheating and peeking all units (seems average reliability - need to try to check if it always works or not) (thanks for the tip "gameframe ~10")
- "games expose the table of startpoints that were actually used to GG" - not finding from code nor from the game's data how to find this - need to look with more attention (I might not know enough how modern "games" are built)
- "callback->GetGame()->GetSetupScript()": quite important functionality. Thanks.
Jools wrote:...
Getting all units at start may not be accurate either, that would include animals and other units on gaia team, ...
If I manage to get all units shortly after start, I guess I can just check each unit's team and disregard the "neutral" ones.
Silentwings wrote:...
If all you want to know is where the starting units were actually placed, as opposed to the possible locations where they could have been placed, ...
I'm aiming at building up a toy AI that interacts with the game as much as a human as possible - I, as a player, do not know exactly where the other player spawned, I merely infer it from knowledge of other things (which I'm trying to get in the AI).

I'm looking to build it as non-cheating as possible, if nothing else because there's the possibility that the engine won't allow certain things. But also, because if it cheats, it can just cheat in ways that almost guarantee it a win - I think we can just spawn whatever unit wherever by command.
Silentwings wrote:...
@PaulMorpheus; To make it clear, there is no fully reliable way to determine which units are used by which games as start units and you just have to hardcode something game dependent for each game you want to cover :( ...
Not completely unexpected. I already knew there will have to be plenty of specialization to specific "games", especially considering how varied the games for SpringRTS can be (*). Heck, even our own (non-A)I's have adaptations to specific mods - back in the day I was a good player of most versions of XTA, average at BA and completely sucked at NOTA (just to mention some oTA variations).

* either that or build such an adaptable/learning AI that I don't even want to think how much work that would be...
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Finding starting positions?

Post by Anarchid »

Finding starting positions?
Here's what i do:
https://github.com/Anarchid/zkgbai/blob ... .java#L358

It works for box start positions and is used for targeting (mexes in enemy startbox are marked as targets).

I presume, discrete start positions are written into startscript in a similar way.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Re: Finding starting positions?

Post by PauloMorfeo »

So cheating does work (at least if I'm alone playing with the AI), and is quite easy:

Code: Select all

		// Turn on cheats?
		Cheats cheats = callback.getCheats ();
		sendTextMsg ("cheats.isEnabled: " + cheats.isEnabled ());
		sendTextMsg ("Whether cheats will desync: " + cheats.isOnlyPassive ());
		cheats.setEnabled (true);
		sendTextMsg ("cheats.isEnabled: " + cheats.isEnabled ());

		// Find enemies		
		AIFloat3 enemyPos = null;
		List<Unit> enemyUnits = callback.getEnemyUnits ();
		if (enemyUnits.size () > 0)
		{
			for (Unit enemyUnit : enemyUnits)
			{
				enemyPos = enemyUnit.getPos ();
				sendTextMsg (enemyUnit.getDef ().getName () + " exists at: " + enemyPos.x + ";" + enemyPos.y + ";" + enemyPos.z);
			}
		}
		else
		{
			... TODO
			sendTextMsg ("No enemy units found. HandleStartingUnit()");
		}
Digging into the script.txt appears to be a very reliable way for standard match-ups (and is very easy with some Regex knowledge):

Code: Select all

[GAME]
{
	...
	startpostype=3;
	...
	[TEAM0]
	{
		TeamLeader=2;
		StartPosX=284;
		StartPosZ=256;
		...
	}
	[TEAM1]
	{
		TeamLeader=2;
		StartPosX=2784;
		StartPosZ=2816;
		...
	}
	...
}
"startpostype" enum:
https://github.com/spring/spring/blob/6 ... etup.h#L65
(an enum with 2 entries with the same number...)
Post Reply

Return to “AI”