EntelectChallenge / 2024-Sproutopia

16 stars 22 forks source link

Leaderboard generation ordering not guaranteed #4

Open kobus-v-schoor opened 7 months ago

kobus-v-schoor commented 7 months ago

Currently, from what I can tell, the player index (i.e. the bot's numeric ordering [0,1,2,3], which is used in the cell types) can be inferred from the leaderboard key in the state update. The ordering of this key however is not guaranteed, as it's making use of the normal Dictionary which may or may not preserve insertion order. Can this please be updated to make use of an OrderedDictionary, so that the order of the keys are guaranteed to match up with the player indices? Thanks!

JeniquePeters commented 7 months ago

Hi Kobus 😸 good to hear from you! Thank you for pointing this out to us. We will address this in another butfix release 😊

deefstes commented 6 months ago

Hey @kobus-v-schoor , I've been looking at ways to address this issue. It's definitely a legit gap that the individual bots don't know the order of all the bots and their mapping to the values in the enum.

I'm not mad about the OrderedDictionary though as it is not a drop in replacement for Dictionary<TKey, TValue> but rather just for Dictionary<string, string>. I realise this is only for a DTO where the type is perhaps not as important but I figured there might be a better way to communicate the order of the bots back to the individual bots.

Besides, there are other static game information that the bot might also want to know in addition to the other bots' indices - like the max ticks, the random seed for the game, the grid size, etc.

So I've taken a different approach and rather implemented an additional SignalR method through which a bot can request the game info from the Game Engine. The response DTO that is sent to the bots looks as follows:

public class GameInfoDTO
{
    public int MaxTicks { get; private set; }
    public int TickRate { get; private set; }
    public int Rows { get; private set; } 
    public int Cols { get; private set; }
    public int RandomSeed { get; private set; }
    public int PlayerWindowSize { get; private set; }
    public Dictionary<int, Guid> Bots { get; private set; }
}

This DTO will be sent to each bot as the first message from the Game Engine when the game starts, but will also be returned to the bot upon whenever it sends a GetGameInfo command to the Game Engine.

I realise this is a more roundabout way for the bot to obtain the list of bot indices but I believe it makes it more versatile.

This will be included in the next release.

kobus-v-schoor commented 6 months ago

Thanks @deefstes , that would be great way to do it 🙌 One of the things I missed last year was a way to retrieve the game settings (hardcoding always felt very iffy). PS please don't include the RandomSeed in there 😅 We might be able to use that to figure out what the map will look like (there was a guy who did that 2 years ago with the racing game - he was able to reverse engineer the seed from the state updates and predict the map, which was awesome)