Skip to content
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

JS support issue of MadeHand.best(): when flutter code compiled to JS to run on Chrome or Edge browser #35

Open
wfzhou2 opened this issue Nov 18, 2022 · 0 comments

Comments

@wfzhou2
Copy link

wfzhou2 commented Nov 18, 2022

In a flutter application, when the device selected to run (in VS Code) is Chrome or Edge browser (web-javascript), the MadeHand.best() method return is not always right. Probably due to integer is 32 bit in JavaScript in browser and 64 bit in Dart/Flutter?

When device is browser, MadeHand.best() hand evaluation result is not consistent at all. For example,

  • cards 'QdKsQsJhTd9h8c' or 'KsQsJhTd9h' evaluated to be MadeHandType.fullHouse with a hashcode of 167
  • cards '6d2s4s5h3d' evaluated to be MadeHandType.fullHouse with a hashcode of 265
  • cards '6d2s4s5h3d2hQd' evaluated to be MadeHandType.trips with a hashcode of 2270
  • cards 'Ad2s4s5h3d2h2d' evaluated to be right as MadeHandType.straight with a hashcode of 1609, yet the 5 cards straight 'Ad2s4s5h3d' evaluated to be MadeHandType.fullHouse with a hashcode of 265

However, if device selected is a Android emulator (Pixel 6 API 29), all the above cards are correctly evaluated to be MadeHandType.straight.

A little more digging and I think the issue is in ImmutableCardSet class, where the _indexUnion probably should be fixnum:Int64 to be JS safe. Though JS number can be as large as 2^53-1, however, any bit operations in JS are operated on 32 bit int. So any bit operation on integer larger than 2^32-1 inside JS would cause issue.

@wfzhou2 wfzhou2 changed the title JS support issue of MadeHand.best() when flutter code compiled to JS to run on Chrome or Edge browser JS support issue of MadeHand.best(): when flutter code compiled to JS to run on Chrome or Edge browser Nov 18, 2022
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

No branches or pull requests

1 participant