-
Notifications
You must be signed in to change notification settings - Fork 0
Implement MCTS AI #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/main/java/dk/sdu/mmmi/modulemon/MCTSBattleAI/MCTSBattleAI.java
Outdated
Show resolved
Hide resolved
| IGameViewService selectedView = views.get(currentOption); | ||
| gvm.setView(selectedView); | ||
| if (selectedView instanceof IBattleView) { | ||
| if (selectedView instanceof IBattleView battleView) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feeling of using a feature > Java 8 is just amazing.
…java Co-authored-by: Alexander Nørup <[email protected]>
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.