Implement MCTS AI#7
Conversation
AlexanderNorup
left a comment
There was a problem hiding this comment.
I only did a quick code review for styling. Didn't go through the logic thoroughly, but I'll take your word for it that it works. Very nice!
| } else if(bestChild.getParentSwitch() != null){ | ||
| battleSimulation.switchMonster(participantToControl, bestChild.getParentSwitch()); | ||
| } else { | ||
| throw new IllegalStateException("AI found no moves to do"); |
There was a problem hiding this comment.
We should probably have the battle simulation catch this exception so it can handle it gracefully.
| var possibleActionCount = possibleActions.size(); | ||
| if(possibleActionCount == 0) return -1; | ||
| else{ | ||
| var rand = new Random(); |
There was a problem hiding this comment.
Question: Does Java seed new Random() correctly? Or would it be better to have one shared Random instance?
You don't have to change it, I'm just wondering. It's probably a microoptimization at worst and meaningless at best. I'm just curious.
There was a problem hiding this comment.
I think it might be seeded with the timestamp or something like it. According to javadoc
This constructor sets the seed of the random number generator to a value very likely to be distinct from any other invocation of this constructor.
| IGameViewService selectedView = views.get(currentOption); | ||
| gvm.setView(selectedView); | ||
| if (selectedView instanceof IBattleView) { | ||
| if (selectedView instanceof IBattleView battleView) { |
There was a problem hiding this comment.
The feeling of using a feature > Java 8 is just amazing.
…java Co-authored-by: Alexander Nørup <AlexanderNorup@users.noreply.github.com>
Implemented MCTS, some stuff that should still be checked.
It is now possible to change the BattleAI by chosing one of three options in the settings. This is used in quick battle and battles that start through the map view.