11-16-2020, 10:23 AM
Currently, when working with the GUI, closeAI() gets called when:
1) You compile and load a different game (closeAI() first called on all the different AIs that may have been playing the previously-loaded game)
2) When hitting Ctrl+R or the button to fully Restart the current game (resetting to initial game state)
3) Called on an old AI right before it gets replaced by a new AI when selecting a new AI from the dropdown menu
Hmmm, you're right, it would definitely make sense to at least also call it on all AIs when the application is being terminated. Though I'm not 100% sure how cleanly we can guarantee that it always happens when the application closes due to like the user pressing Alt+F4 or otherwise exiting in an abnormal manner...
So, closeAI() is not always called before an initAI(). closeAI() is only called in the cases listed above. initAI() is called much more frequently, like also whenever re-init may be necessary to reset possibly-invalid memory due to the user taking steps back. I guess if in your case you do always need a closeAI() in such a case first, you can simply detect whether or not closeAI() has already been called since the last call to initAI(), and call it yourself if it hasn't already been called.
I'm not sure about adding a setting to prevent initAI() reset calls for rollbacks... if a user selects such a setting with one of our built-in AIs, they'll be likely to crash. Is there a way you can work around this issue? In theory you could just not do the work in initAI(), but instead do it in the beginning of selectAction(). There you get access to the Context, can use that to detect whether you're in an initial game state (or at least one in which your agent never made any moves yet), and only do the work in that case. But I suppose this is not great if the initialisation work you need to do is time-consuming...
1) You compile and load a different game (closeAI() first called on all the different AIs that may have been playing the previously-loaded game)
2) When hitting Ctrl+R or the button to fully Restart the current game (resetting to initial game state)
3) Called on an old AI right before it gets replaced by a new AI when selecting a new AI from the dropdown menu
Hmmm, you're right, it would definitely make sense to at least also call it on all AIs when the application is being terminated. Though I'm not 100% sure how cleanly we can guarantee that it always happens when the application closes due to like the user pressing Alt+F4 or otherwise exiting in an abnormal manner...
So, closeAI() is not always called before an initAI(). closeAI() is only called in the cases listed above. initAI() is called much more frequently, like also whenever re-init may be necessary to reset possibly-invalid memory due to the user taking steps back. I guess if in your case you do always need a closeAI() in such a case first, you can simply detect whether or not closeAI() has already been called since the last call to initAI(), and call it yourself if it hasn't already been called.
I'm not sure about adding a setting to prevent initAI() reset calls for rollbacks... if a user selects such a setting with one of our built-in AIs, they'll be likely to crash. Is there a way you can work around this issue? In theory you could just not do the work in initAI(), but instead do it in the beginning of selectAction(). There you get access to the Context, can use that to detect whether you're in an initial game state (or at least one in which your agent never made any moves yet), and only do the work in that case. But I suppose this is not great if the initialisation work you need to do is time-consuming...