GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — New dice-rolling app: InfiniDice! by yusufmte · Pull Request #1326 · InfiniTimeOrg/InfiniTime

Conversation

@yusufmte

@yusufmte yusufmte commented Sep 12, 2022

Copy link
Copy Markdown
Contributor

InfiniDice is a dice-rolling applet where you can roll random numbers from d2 to d99. The functionality is:

  • Set the number of "sides" of the dice
  • Roll to randomly generate a result number in the interval from 1 to the number of sides

It starts at d2 (ie coinflip), and when you first open the app, a roll is made, so you get a "free" coinflip. Then you can change the number of sides and use it as a d6, d20, etc. The color of the result alternates with each roll (so that you can be sure it was actually rolled even when the result is the same).

Tested on PineTime hardware with InfiniTime 1.10.0, and found to be in good working order. See video:

infinidice.mp4

I often find myself looking for dice and think this could come in handy for tabletop players :) Any testing, feedback, or suggestions on optimization would be appreciated!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

NitroNils, ptman, Henry-Hiles, and Haui1112 reacted with thumbs up emoji 99Edorde reacted with thumbs down emoji Gernomaly, agittins, LinuxinaBit, jp-bennett, ptman, tausen, NeroBurner, pipe01, Henry-Hiles, and Haui1112 reacted with heart emoji
All reactions
  • 👍 4 reactions
  • 👎 1 reaction
  • ❤️ 10 reactions
yusufmte and others added 9 commits September 11, 2022 00:05
@yusufmte
initial commit for Dice.h and Dice.cpp
4cc6776
@yusufmte
include Dice.h and Dice.cpp into compilation in CMakeLists.txt
b238d06
@yusufmte
add "d" (0x64) to the range in jetbrains_mono_42 in fonts.json
6278008
@yusufmte
add dice symbol
12a565a
@yusufmte
add dice app to app launcher
b37781a
@yusufmte
Merge branch 'InfiniTimeOrg:develop' into dice
172f20d
@yusufmte
increase number of app screens to 3
1996113
@yusufmte
modify dice seed to use epoch time
f00d779
@yusufmte
Merge branch 'InfiniTimeOrg:develop' into dice
7c011d6
@joseph58tech

joseph58tech commented Sep 13, 2022

Copy link
Copy Markdown

I believe this has been implemented before, check #565

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@minacode

minacode commented Sep 13, 2022

Copy link
Copy Markdown
Contributor

I like the simple interface and think they solve different problems. Maybe we could have both apps in a world where we are able to choose which apps we want.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@NeroBurner NeroBurner added the new app This thread is about a new app label Sep 13, 2022
NeroBurner
NeroBurner requested changes Sep 13, 2022
View reviewed changes

@NeroBurner NeroBurner left a comment

Copy link
Copy Markdown
Contributor

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.

lovely app ❤️

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yusufmte reacted with heart emoji
All reactions
  • ❤️ 1 reaction
Comment thread src/displayapp/screens/Dice.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/displayapp/screens/Dice.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/displayapp/screens/Dice.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/displayapp/screens/Dice.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

@FintasticMan

FintasticMan commented Sep 13, 2022

Copy link
Copy Markdown
Member

One feature that I think is quite nice to have in a dice app, is being able to specify a number of dice, rather than just always rolling one die. I don't think that for this you would need to show the results of all the dice individually, just the final result.

For the rest I think this app looks good! 👍

yusufmte reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@minacode

minacode commented Sep 13, 2022

Copy link
Copy Markdown
Contributor

#565 is doing exactly that already.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@FintasticMan

FintasticMan commented Sep 13, 2022

Copy link
Copy Markdown
Member

You're right, it does do that. But it hasn't been updated in quite a while, and so doesn't merge nicely with some of the changes in InfiniTime. The author of that PR also doesn't seem to be very active, so it's uncertain as to whether it will be updated.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yusufmte added 3 commits September 13, 2022 16:29
@yusufmte
apply clang-format to Dice.h
b073b48
@yusufmte
remove unnecessary stored reference to dateTime in Dice.h
1edfddd
@yusufmte
remove unnecessary stored reference to dateTime in Dice.cpp
6c7d8c2
@minacode

minacode commented Sep 13, 2022

Copy link
Copy Markdown
Contributor

This problem is fundamental for InfiniTime. We need to fix the app problem.
Shameless plug: #1296

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yusufmte added 3 commits September 13, 2022 17:00
@yusufmte
use std::array to reduce unnecessary variables
3bd3d81
@yusufmte
remove unnecessary member variable in Dice.h
21e5ec1
@yusufmte
move NextColor() into private namespace of Dice
b1e522f
@yusufmte

yusufmte commented Sep 13, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Thank you @NeroBurner kindly for your improvements on the code ❤️ Thank you everyone for your comments and feedback as well.

@FintasticMan :

One feature that I think is quite nice to have in a dice app, is being able to specify a number of dice, rather than just always rolling one die.

I definitely appreciate your sentiment, rolling multiples is a frequently needed and useful function of dice! 👍 However I tend to agree with @minacode , there's a value to keeping the interface simple and intuitive, and #565 already implements multi-roll in a lovely way. But I might be thinking about ways to implement that smoothly without crowding the UI too much.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yusufmte added 4 commits September 14, 2022 16:48
@yusufmte
modify seed to avoid overflow error
8ecfb49
@yusufmte
fix unchanging seed
616413d
@yusufmte
fix Dice seed to use system tick count
6d23a14
@yusufmte
implement rolling multiple dice in Dice
52e4af5
@yusufmte

yusufmte commented Sep 15, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Implemented rolling multiple dice in 52e4af5

(Thanks for the suggestion @FintasticMan ! 👍)

The number of dice can range from 1-9 (default 1), and the sides can range from d2-d99 (default d2). The individual rolls are shown as well. Here's the new look:

infinidice_on_infinisim
infinidice_on_pinetime

As before, any feedback or further suggestions are much appreciated. I'll try to keep it up to date with the official develop branch in the meantime. Thanks everyone :)

LinuxinaBit reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yusufmte
yusufmte requested a review from NeroBurner September 15, 2022 18:55
yusufmte and others added 7 commits December 13, 2023 14:24
@yusufmte
update as user/optional app
8c6e98b
@yusufmte
Merge branch 'main' into dice
b5c2057
@yusufmte
updated for new optional user app interface, fixed bugs and formatting
ee8aaad
@yusufmte
fix formatting
3e0e30f
@yusufmte
Merge branch 'InfiniTimeOrg:main' into dice
f504a8b
@yusufmte
Merge remote-tracking branch 'upstream/main' into dice
5a6cd44
@yusufmte
add to user apps
e231b58
@yusufmte

yusufmte commented Jan 10, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Rebased to 1.14! (Very excited about the customizable user app selection implemented in this version of Infinitime.)

I also want to bump this PR in general. It has been ready for a long time, and continuing to work great in 1.14. The shake-to-roll function implemented by @Poohl has been working super well also. This has probably been my most frequently used of the PineTime user apps, and have used it in a few different circles with very good success. Sometimes I have taken the PineTime off the band and passed it around during a tabletop game for players to roll. There have been numerous other PRs for dice apps in the past, so there is definitely interest in such an app from the PineTime community.

I know there are a lot of PRs to review and a lot of more important work to do for Infinitime in general -- all on a volunteer basis, which I recognize and greatly appreciate! However, can the maintainers weigh in on the plans for this at some point? @JF002 Are there plans to add it to the 1.15 milestone? Thanks! :)

FintasticMan reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

FintasticMan
FintasticMan requested changes Jan 11, 2024
View reviewed changes

@FintasticMan FintasticMan left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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 really like this app! A couple of concerns: do we really need the C++ random generator, is it that much better than C's rand? Could you try using rand with the bias elimination implemented in #881, and see what the difference in flash usage is? If the difference isn't too big, or if you think that rand really isn't good enough, I'd be very happy to use the better C++ generator.

Another concern is how well the shaking works when lower to sleep is also enabled. Could you check if there are any issues there? (I'm also not a big fan of the hack of enabling shake to wake if it's disabled to get it to work, but I don't think that needs to be solved now)

Thank you so much for this app, it's very nice, and I apologise for how long it's taking.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yusufmte reacted with heart emoji
All reactions
  • ❤️ 1 reaction
Comment thread src/displayapp/screens/Dice.cpp Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/displayapp/screens/Dice.cpp Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/displayapp/screens/Dice.cpp Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/displayapp/screens/Dice.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/displayapp/apps/CMakeLists.txt Resolved

Uh oh!

There was an error while loading. Please reload this page.

FintasticMan
FintasticMan reviewed Jan 11, 2024
View reviewed changes
Comment thread src/displayapp/screens/Symbols.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

yusufmte and others added 5 commits January 13, 2024 21:49
@yusufmte @FintasticMan
remove unnecessary static declaration
1166939
Co-authored-by: FintasticMan <[email protected]>
@yusufmte @FintasticMan
remove unnecessary static declaration
945a099
Co-authored-by: FintasticMan <[email protected]>
@yusufmte
removed vestigial chartLine symbol
3c4027a
@yusufmte
replace preprocessor def with static constexpr value, and formatting fix
d4c6975
@yusufmte
Merge branch 'main' into dice
446e49e
FintasticMan
FintasticMan requested changes Jan 14, 2024
View reviewed changes

@FintasticMan FintasticMan left a comment

Copy link
Copy Markdown
Member

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.

Just a couple of things.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yusufmte reacted with heart emoji
All reactions
  • ❤️ 1 reaction
Comment thread src/displayapp/screens/Dice.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .gitignore Resolved

Uh oh!

There was an error while loading. Please reload this page.

@yusufmte

yusufmte commented Jan 14, 2024

Copy link
Copy Markdown
Contributor Author

@FintasticMan thank you for your kind words & thoughtful feedback/review, I really appreciate it!! ❤️ No apology necessary, you folks have been doing amazing work with InfiniTime and I know you have a ton on your plate!

I really like this app! A couple of concerns: do we really need the C++ random generator, is it that much better than C's rand? Could you try using rand with the bias elimination implemented in #881, and see what the difference in flash usage is?

I noticed that rand() is used for RNG in other apps like Paddle and Twos, and so I did initially use it in earlier versions of the Dice. However, there are a few significant flaws with rand() (detailed below) that make it inferior to the C++11 <random> lib. I think that doesn't matter for the other apps mentioned, where the experience is fine as long as it generally feels random-- but for the Dice, since the whole point of the app is randomness, it feels important for the randomness to be very fair / high quality.

(1) According to official docs, rand() is considered deprecated for most needs as it does not guarantee quality of the randomness of the sequence produced. More details here:

There are no guarantees as to the quality of the random sequence produced. In the past, some implementations of rand() have had serious shortcomings in the randomness, distribution and period of the sequence produced (in one well-known example, the low-order bit simply alternated between 1 and 0 between calls). rand() is not recommended for serious random-number generation needs. It is recommended to use C++11's random number generation facilities to replace rand(). (since C++11)

(2) As you mentioned, there is the possibility of modulo bias with rand() % x (where is RAND_MAX is not divisible by x, then generating smaller numbers is more likely). With rand(), it's possible to correct for it with a few extra lines of code, but feels more elegant to instead use the intended standard library function, which picks integers uniformly distributed on a specified closed interval.

(3) The <random> library has the very neat std::seed_seq function used here, which mixes multiple sources of randomness together (as opposed to srand(), which takes in just 1 seed), and makes seeds that are distributed over the whole 32-bit range even when the inputs are close or poorly distributed. This is nice here particularly because the PineTime has a few possible sources of randomness that can work together in tandem; the dice app mixes the system tick count and the X/Y/Z components of the PineTime's sensitive motion controller (credit to @w4tsn #1199 for the motion controller idea!), making seed collision vanishingly unlikely.

Another concern is how well the shaking works when lower to sleep is also enabled. Could you check if there are any issues there? (I'm also not a big fan of the hack of enabling shake to wake if it's disabled to get it to work, but I don't think that needs to be solved now)

That's a great point; I am not sure as I haven't previously used lower to sleep on my own PineTime -- I will test this shortly and report back here soon!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@FintasticMan

FintasticMan commented Jan 14, 2024

Copy link
Copy Markdown
Member

Thank you for the thorough explanation. I think it shows you've put a lot of thought into this and I agree that using rand() is not well-suited for this application. Let's stick with the C++ random classes you've already implemented then!

yusufmte reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yusufmte

yusufmte commented Jan 15, 2024

Copy link
Copy Markdown
Contributor Author

Another concern is how well the shaking works when lower to sleep is also enabled. Could you check if there are any issues there? (I'm also not a big fan of the hack of enabling shake to wake if it's disabled to get it to work, but I don't think that needs to be solved now)

Tested current version on PineTime hardware, it's working well! The lower-to-sleep & raise-to-wake continues to work inside & outside the Dice app when these are enabled, and the shake-to-roll works as well.

FintasticMan reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yusufmte and others added 3 commits January 14, 2024 22:07
@yusufmte
Merge branch 'InfiniTimeOrg:main' into dice
e6cfd9e
@yusufmte
remove unrelated .gitignore changes
8880acc
@yusufmte
use camelCase for rollHysteresis constant
01b241b
FintasticMan
FintasticMan approved these changes Jan 15, 2024
View reviewed changes

@FintasticMan FintasticMan left a comment

Copy link
Copy Markdown
Member

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.

Awesome! This looks good to me

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yusufmte reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@yusufmte

yusufmte commented Jan 15, 2024

Copy link
Copy Markdown
Contributor Author

Awesome, thanks again!!! Let me know if anything else needed prior to merge!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@NeroBurner NeroBurner added this to the 1.15.0 milestone Jan 15, 2024
@yusufmte
Merge branch 'InfiniTimeOrg:main' into dice
0c7a77a
@NeroBurner
NeroBurner merged commit a40168a into InfiniTimeOrg:main Jan 23, 2024
@NeroBurner

NeroBurner commented Jan 23, 2024

Copy link
Copy Markdown
Contributor

@yusufmte thank you for your hard work and endurance!

We can finally say: Alea iacta est

agittins reacted with laugh emoji FintasticMan, yusufmte, minacode, ebrahimebrahim, and agittins reacted with hooray emoji
All reactions
  • 😄 1 reaction
  • 🎉 5 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yusufmte

yusufmte commented Jan 23, 2024

Copy link
Copy Markdown
Contributor Author

@yusufmte thank you for your hard work and endurance!

We can finally say: Alea iacta est

Thank you friend, and many thanks to all who contributed and reviewed along the way! 🎉 Alea iacta est, indeed! :)

agittins reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

user84918342 pushed a commit to user84918342/LasnikrInfiniTime that referenced this pull request Mar 5, 2024
@yusufmte @NeroBurner
@Riksu9000 @Poohl @FintasticMan @user84918342
New dice-rolling app: InfiniDice! (InfiniTimeOrg#1326)
205f4bf
Add new App `Dice.h` to randomly roll the dice(s).
The number of dice can range from 1-9 (default 1), and the sides can
range from d2-d99 (default d2).

To have a haptic feedback we make Dice vibrate on roll.

Regarding the use of C++ `<random>` library:
There are known problems with `rand()` and `srand()` (see https://en.cppreference.com/w/cpp/numeric/random/rand)
and the `<random>` library is preferred for this reason. The function used from
`<random>` also avoids a very rare bias that would occur using `rand()` and modulo,
when `RAND_MAX` is not a multiple of `d` and the initially generated number falls in
the last "short" segment. This commit also updates the seed to derive entropy
(via `seed_seq`) from a mix of the system tick count and the x,y,z components of the
PineTime motion controller -- taking inspiration from and with credit to @w4tsn
(InfiniTimeOrg#1199)

Thanks for suggestions:
* in Dice, when rolling 1d2, also show "HEADS" or "TAILS" -- suggestion by @medeyko
* ui adjustments and result realignment -- suggestion by @Boteium

---------

Co-authored-by: NeroBurner <[email protected]>
Co-authored-by: Riku Isokoski <[email protected]>
Co-authored-by: Paul Weiß <[email protected]>
Co-authored-by: FintasticMan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JF002 JF002 JF002 left review comments
@NeroBurner NeroBurner NeroBurner approved these changes
@FintasticMan FintasticMan FintasticMan approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

new app This thread is about a new app

Projects

None yet

Milestone

1.15.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

12 participants

@yusufmte @joseph58tech @minacode @FintasticMan @NeroBurner @JF002 @Danimations @Avamander @medeyko @Boteium @Riksu9000 @Poohl
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.