Skip to content

AI for version 2.0#574

Merged
strinsberg merged 35 commits intomasterfrom
Ai-version2.0-#573
Jun 15, 2020
Merged

AI for version 2.0#574
strinsberg merged 35 commits intomasterfrom
Ai-version2.0-#573

Conversation

@strinsberg
Copy link
Copy Markdown
Collaborator

Fixes #573

Overview of changes

  • Added AI players to the game
  • Built an AiHandler that uses a pattern like chain of responsibility and ActionHandler objects to make turn choices. This is extendable and will execute all given handlers in the order to find one that it can do.
  • Made a special ActionHandler that given a priority list will sort the cards in it's hand and play the best one it can. It uses another chain of responsibility like pattern but with methods instead of more objects. This handler is diverse enough to be used on it's own, but tweaking the card order or adding more action handlers in front of it can customize the AI
  • Created a factory class to allow creating new AiHandlers with different card orders (personalities). In the future it can be updated to have methods or params to create AI that use more than just the PlayBestCardAction handler.
  • Messages have been added to the message box to tell you what the AI did. Without putting some sleeps into the code the AI turn is instant, so currently It is possible to select and interact with AI opponent cards #541 is not so much of a problem, but will still need to be fixed.

Notes

  • The standard AI seems to be pretty competitive, so adjusting game length or making new setups that are easier for difficulties might be needed depending on the user base.
  • I have not added a random personality feature like we had in the previous game. We may want to add this back or use some kind of difficulty setting to allow setting different AI personalities.
  • test files for all AI classes and functions have been added.

Reviewer: @johnanvik

…s hand every turn. Added a simple message event to track AI turns, it is a bit hack for now because of an issue and there is only one message so it won't refresh properly yet.
… hand based on a predefined card priority. Also, reverted the message box to use as once is really only once so it will not work.
…ng the best possible card. Not sure it is working as intended, but it does allow the ai player to play instruction and repeat cards.
…ction. Always plays the highest repeat on the biggest stack first, then plays biggest instruction.
…tart adding unit tests to confirm this properly, now that I think the class is not going to change in any big way except add functionality.
…rking as expected, without proper unit tests yet.
…stCardAction class. They are working as expected with play testing.
…t work in the game and tested the algorithm elsewhere, but it is without formal unit tests yet.
…places if needed. Adjusted some documentation.
…the message box for AI turns so that it is mildly informative for now.
…eally relevant for some newer changes and need to be rewritten.
… action objects and both type and personality.
…e the option of adding new actionHandlers to an AiHanlder in the future, but the PlayBestCardAction is quite competetive so far. Adjusted the comparator for lowest stacks that accept variables as the getTop() calls needed to use type. Adjusted tests to work with this.
@strinsberg strinsberg requested a review from johnanvik June 12, 2020 21:54
Comment thread src/components/game/MessageBox.vue
…not really need to be tested and worked differently on different machines.
…mplicated and uses dynamic programming, but it will give a much more consitent result and should not be a problem with running too long unless something very serious changes with our games group cards and how many stacks a player can get out during a game. Unit tests were re-written to test it better than before.
@johnanvik johnanvik added this to the Sprint #2 (Summer 2020) milestone Jun 15, 2020
Comment thread src/classes/ai/ActionHandler.js Outdated
Comment thread src/classes/ai/aiHelpers.js Outdated
Copy link
Copy Markdown
Collaborator

@johnanvik johnanvik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good. There is an incredible performance improvement in gameplay. We may want to consider putting a timer delay just so the player feels like the AI is actually considering its move!

@strinsberg
Copy link
Copy Markdown
Collaborator Author

Yes I have just created a new branch to address the AI cards being playable and added a small timer to allow for their turn to be "taken" as before. It is now sleeping in only one place so it is also easy to adjust to a time we like.

@strinsberg
Copy link
Copy Markdown
Collaborator Author

I have also found a couple of small bugs since submitting that I have taken care of in other branches that I will submit pull requests for once this is merged.

@strinsberg strinsberg merged commit 533177f into master Jun 15, 2020
@strinsberg strinsberg deleted the Ai-version2.0-#573 branch June 15, 2020 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add AI back for version 2.0

2 participants