google-research / falken

Falken provides developers with a service that allows them to train AI that can play their games
Apache License 2.0
253 stars 34 forks source link

Problem using falken::ObservationsBase #19

Closed mattlegro closed 3 years ago

mattlegro commented 3 years ago

Hello again, So this is a bit of a complicated one. To get into the background of what I'm doing, I'm trying to integrate falken with Rocket League. This is not a game I made, however, there are two communities that have discovered ways to access the game files that have since been officially sanctioned by Psyonix, Rocket League's producer. One of them is a botting community, for making AI that play each other (no cheating or abusing the system of course).

Now, I realized that they have structures to access all of the information that might be useful to the learner service. However, I am having a weird issue that I can't figure out, so if you can provide any ideas at all I would appreciate it.

So, I am writing a cpp bot. I am using dynamic assignment as in the falken_player_dynamic example.

If I comment out everything referencing falken:: in my bot.cc file, it runs fine with the rest of the code, even with some falken pointers being created in the bot.h file. If I uncomment the first line making a reference falken::ObservationsBase observations; in bot.cc I get an error. The error it gives is "Could not connect to server!" Which is thrown in this function called in their code. The framework is written in python but handles cpp bots.

    def run_independently(self, terminate_request_event):
        while not terminate_request_event.is_set():
            message = f"add\n{self.name}\n{self.team}\n{self.index}\n{game_interface.get_dll_directory()}"
            try:
                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.connect(("127.0.0.1", self.port))
                s.send(bytes(message, "ASCII"))
                s.close()
            except ConnectionRefusedError:
                self.logger.warn("Could not connect to server!")

            time.sleep(1)
        else:
            self.retire()

So, doing some tracing, I find that ConnectionRefusedError is class ConnectionRefusedError(ConnectionError): ... where ConnectionError is class ConnectionError(OSError): ... and finally

class OSError(Exception):
    errno: int
    strerror: str
    # filename, filename2 are actually str | bytes | None
    filename: Any
    filename2: Any
    if sys.platform == "win32":
        winerror: int

EnvironmentError = OSError
IOError = OSError
if sys.platform == "win32":
    WindowsError = OSError

Getting any deeper into Exception you just get to a base exception class which seems built to parse system errors. This leads me to believe that any underlying Environment, OS, or IO errors would lead to their framework throwing 'Could not connect to server." I have no idea if this interpretation is real but can you imagine anything that would cause OS or IO type errors just by adding the line falken::ObservationsBase observations;? If there is any questions I can answer let me know, and if this is really beyond your purview of questions you want to answer, no worries.

hmoraldo commented 3 years ago

It is possible you are not running the service? or you haven't configured it properly?

Are you able to run the example environments?

If that's working well, it is possible that the server is crashing mid-execution, for example. Worth debugging the server and not just the client.

mattlegro commented 3 years ago

I was able to get hello_falken to work fine, and I have a Powershell window with Waiting Assignment... printing every couple minutes when trying to run the bot. Also, as in the falken_player_dynamic, the line falken::ObservationsBase observations; appears before service = falken::Service::Connect( nullptr, nullptr, nullptr); does, so I'm getting this problem before even trying to connect to the service.

mattlegro commented 3 years ago

Hey, so instead of letting their code run the bot for me I started the bot framework then executed my bot with a debugger and pretty quickly found an error

The program '[15004] CPPExampleBot.exe' has exited with code -1073741515 (0xc0000135) 'A dependent dll was not found'.

So now I have somewhere to start. Guess I messed up some dependency related stuff somewhere.

mattlegro commented 3 years ago

Nope, all I needed to do was copy the falken_sdk_cpp.dll into the folder with my bot.exe.. whoops! I'll keep ya posted for more dumb questions!

mattlegro commented 3 years ago

Now I'm running into an issue where I get:

[Falken] ERROR: Service connection failed: UNAUTHENTICATED: Must set API key and project ID before calling Falken APIs. If you don't have them or the error persist please contact falken support team. Exception thrown at 0x00007FFDA25A91A8 (falken_cpp_sdk.dll) in CPPExampleBot.exe: 0xC0000005: Access violation reading location 0x0000000000000008.

I have falken_config.json in the build folder with all my solution files as in the example. In my code I have:

    static const char *kJsonConfig = nullptr;
    service = falken::Service::Connect(
        nullptr, nullptr, kJsonConfig);
mattlegro commented 3 years ago

I see that the other guy having this issue just copied the JSON text as a string into the cpp file. Is this advised?