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?
Finding starting positions?
Moderators: hoijui, Moderators
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Finding starting positions?
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).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 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.
You can't extract that from the map/game definitions because it is an option set in startscript.Nor starting positions type (if random, specific or within a specified box), 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.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?
Re: Finding starting positions?
As for starting boxes you can investigate output of callback->GetGame()->GetSetupScript().PauloMorfeo wrote: Nor starting positions type (if random, specific or within a specified box), right?
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).
Re: Finding starting positions?
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.
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.
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Finding starting positions?
No one said it.say that most games define own start positions
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.iirc it's only ba
That's wrong.and this also only for some maps.
@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.Getting all units at start may not be accurate either, that would include ...
- PauloMorfeo
- Posts: 2004
- Joined: 15 Dec 2004, 20:53
Re: Finding starting positions?
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.
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.
* either that or build such an adaptable/learning AI that I don't even want to think how much work that would be...
- 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.
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.Jools wrote:...
Getting all units at start may not be accurate either, that would include animals and other units on gaia team, ...
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).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 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.
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).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 ...
* either that or build such an adaptable/learning AI that I don't even want to think how much work that would be...
Re: Finding starting positions?
Here's what i do:Finding starting positions?
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.
- PauloMorfeo
- Posts: 2004
- Joined: 15 Dec 2004, 20:53
Re: Finding starting positions?
So cheating does work (at least if I'm alone playing with the AI), and is quite easy:
Digging into the script.txt appears to be a very reliable way for standard match-ups (and is very easy with some Regex knowledge):
"startpostype" enum:
https://github.com/spring/spring/blob/6 ... etup.h#L65
(an enum with 2 entries with the same number...)
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()");
}
Code: Select all
[GAME]
{
...
startpostype=3;
...
[TEAM0]
{
TeamLeader=2;
StartPosX=284;
StartPosZ=256;
...
}
[TEAM1]
{
TeamLeader=2;
StartPosX=2784;
StartPosZ=2816;
...
}
...
}
https://github.com/spring/spring/blob/6 ... etup.h#L65
(an enum with 2 entries with the same number...)