robocode-dev / tank-royale

Git repository for Robocode Tank Royale
Apache License 2.0
145 stars 29 forks source link

TickEventForObserver and TickEventForBot seem not containing real values #76

Closed SirStone closed 1 year ago

SirStone commented 1 year ago

Describe the bug I have the suspect that the "botState" in both TickEventForBot and TickEventForBot is reporting only the starting values for the bot but for some elements. For example: energy is updated direction is not updated

Is a suspect, because I'm observing this using my API that I'm developing, but if I run the bot with the GUI i can see it moving and doing actions, but from the printed RAW ticks the botState is not changing.

To Reproduce TickEventForObserver one need to implement an observer and watch the TicketEventForObserver messages

TickEventForBot build an API and observe the raw ticks from the server during a match. :P

Error info Here RAW messages of a TickEventForBot and TickEventForObserver of the turn 38

the server was started with initial positions enabled and with this positions: test bot x:400,y:300,angle:0 another bot x:0,y:0,angle:90

and the ONLY instruction given was for the test bot to turn right by ~176 degrees (random value) starting at turn 10 and completed at turn 37 (expected behavior)

TickEventForBot

{
    "roundNumber": 1,
    "enemyCount": 1,
    "botState": {
        "isDroid": false,
        "energy": 97.30000000000015,
        "x": 400.0,
        "y": 300.0,
        "direction": 0.0,
        "gunDirection": 0.0,
        "radarDirection": 0.0,
        "radarSweep": 0.0,
        "speed": 0.0,
        "turnRate": 0.0,
        "gunTurnRate": 0.0,
        "radarTurnRate": 0.0,
        "gunHeat": 0.0
    },
    "bulletStates": [],
    "events": [],
    "turnNumber": 38,
    "type": "TickEventForBot"
}

TickEventForObserver

{
    "roundNumber": 1,
    "botStates": [
        {
            "id": 1,
            "sessionId": "7/ZlaPDCR6mLNQ938GltPQ",
            "isDroid": false,
            "energy": 97.30000000000015,
            "x": 18.0,
            "y": 18.0,
            "direction": 90.0,
            "gunDirection": 90.0,
            "radarDirection": 90.0,
            "radarSweep": 0.0,
            "speed": 0.0,
            "turnRate": 0.0,
            "gunTurnRate": 0.0,
            "radarTurnRate": 0.0,
            "gunHeat": 0.0
        },
        {
            "id": 2,
            "sessionId": "7fOJndqFQXq/LZkB9A8r6Q",
            "isDroid": false,
            "energy": 97.30000000000015,
            "x": 400.0,
            "y": 300.0,
            "direction": 0.0,
            "gunDirection": 0.0,
            "radarDirection": 0.0,
            "radarSweep": 0.0,
            "speed": 0.0,
            "turnRate": 0.0,
            "gunTurnRate": 0.0,
            "radarTurnRate": 0.0,
            "gunHeat": 0.0
        }
    ],
    "bulletStates": [],
    "events": [],
    "turnNumber": 38,
    "type": "TickEventForObserver"
}

Expected behavior The ticks should contain values reflecting the real status of the bot

Desktop (please complete the following information): NixOs 23.05

Java info: openjdk version "21" 2023-09-19 OpenJDK Runtime Environment Zulu21.28+85-CA (build 21+35) OpenJDK 64-Bit Server VM Zulu21.28+85-CA (build 21+35, mixed mode, sharing)

Additional context About the TickEventforObserver: This problem is affecting only who is working with a Controller. So me that I'm developing an API for the bots, and i use a Controller to do automated tests, and I'm using the BotState to check what the bot is doing. For the majority of the people, the Controller is hidden in the GUI and are not affected by this issue.

About the TickEventForBot, every creator of a bot should be able to observe this

flemming-n-larsen commented 1 year ago

@SirStone Thank you for reporting this. 🙂👍 I will have a look into this ASAP. It sure looks odd to me, so I might have introduced a bug that causes this issue.

flemming-n-larsen commented 1 year ago

@SirStone: I have had a look. TL;DR: I was not able to reproduce the issue.

The GUI application implements a TickEventForObserver to receive updates from the server, which runs in its own process. This is used for drawing the bots on the battlefield, but also to provide detailed information about the current bot properties within the Properties tab of the Bot Console (by clicking the button with the name of the bot showing the ongoing battle). So at least the TickEventForObserver seems working fine for the GUI application.

I also added some print lines to the Crazy sample bot to dump some values to standard out (can be read out in the Bot Console as well):

    @Override
    public void onTick(TickEvent e) {
        var bot = e.getBotState();

        String sb =
                "\nTurn number: " + e.getTurnNumber() +
                "\nRound number: " + e.getRoundNumber() +
                "\nEnergy: " + bot.getEnergy() +
                "\nSpeed: " + bot.getSpeed() +
                "\nDirection: " + bot.getDirection() +
                "\nGun direction: " + bot.getGunDirection() +
                "\nRadar direction: " + bot.getRadarDirection() +
                "\nX: " + bot.getX() +
                "\nY: " + bot.getY() +
                "\nGun heat: " + bot.getGunHeat() +
                "\nEnemy count: " + e.getEnemyCount() +
                "\n----------";

        System.out.println(sb);
    }

Note that I limited some of the unimportant fields like colors etc. 😉

Comparing the values that Crazy writes (TickEventForBot) out with the Properties (TickEventForObserver) I see no difference in the values with turn 162:

Skærmbillede 2023-11-12 200605

Skærmbillede 2023-11-12 200448

Did you read the TickEventForBot from the Java or .Net API or use your own implementation? I guess we could create a simple "event dumper" using JavaScript for the browser just by reading on a web-socket.

SirStone commented 1 year ago

I'm using my own implementation but the json I've pasted comes from the raw json string out of the websocket connection. I'm assuming now that there's no bug on your side and now I'm suspecting that if I run the bot with the GUI my bot is working properly and is failing only in the automated test for some reason, for example, the bot could be that is skipping all turns and I'm failing to monitoring this part.

I need to investigate more, next time I will come back with a resolution or with more evidence

flemming-n-larsen commented 1 year ago

You could try running your bots using the GUI and see what the Bot Console writes out from the Properties pane. Here the Properties (using TickEventForObserver) should tell the current properties of your bot.

SirStone commented 1 year ago

ok I confirm this is not a bug. I've discovered a very hard to spot memory management problem between threads that I can't explain that affects only my unit tests. So I've reprogrammed how the bots are run and problem solved.