Skip to content

Add coin flip/random number/die skill#386

Open
tylxr59 wants to merge 3 commits intoStypox:masterfrom
tylxr59:add-rng-skill
Open

Add coin flip/random number/die skill#386
tylxr59 wants to merge 3 commits intoStypox:masterfrom
tylxr59:add-rng-skill

Conversation

@tylxr59
Copy link
Contributor

@tylxr59 tylxr59 commented Dec 24, 2025

This PR adds a coin flip/random number/die skill

Copy link
Owner

@Stypox Stypox left a comment

Choose a reason for hiding this comment

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

Thanks for this nice simple skill that Dicio was definitely missing!

As a future improvement (totally unnecessary for this PR) we could also add some images for coins and dice!

Comment on lines +21 to +25
ctx.parserFormatter?.extractNumber(it)?.mixedWithText
?.filterIsInstance<Number>()
?.firstOrNull()
?.integerValue()
?.toInt()
Copy link
Owner

Choose a reason for hiding this comment

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

If it.isInteger is false, then integerValue() is just 0.

Suggested change
ctx.parserFormatter?.extractNumber(it)?.mixedWithText
?.filterIsInstance<Number>()
?.firstOrNull()
?.integerValue()
?.toInt()
ctx.parserFormatter?.extractNumber(it)
?.first
?.takeIf { it.isInteger }
?.integerValue()
?.toInt()

Since this appeared often recently, maybe you could change the Number class into a sealed interface with two distinct implementations for integer and decimal, and make integerValue() return null if the value is a decimal. And to go further, I'd also add a firstInteger function to ExtractNumberParams that returns Long? and basically does the operations below. This changes will have to go in https://github.com/Stypox/dicio-numbers

Copy link
Owner

Choose a reason for hiding this comment

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

#384 (comment) also applies here: you could separate specific_dice_roll and specific_random_number sentences and disable those if NumberParserFormatter is not available.

Copy link
Owner

Choose a reason for hiding this comment

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

This is probablt a leftover and should be removed

import org.stypox.dicio.R
import org.stypox.dicio.sentences.Sentences.Random
import org.stypox.dicio.util.getString
import kotlin.random.Random as KotlinRandom
Copy link
Owner

Choose a reason for hiding this comment

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

Is this a randomly-seeded RNG, or does it always have the same seed?

Comment on lines +43 to +48
if (results.size == 1) {
Subtitle(text = ctx.getString(R.string.skill_random_dice_sides, sides))
} else {
Subtitle(text = ctx.getString(R.string.skill_random_dice_sides, sides))
Body(text = results.joinToString(" + ") + " = ${results.sum()}")
}
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
if (results.size == 1) {
Subtitle(text = ctx.getString(R.string.skill_random_dice_sides, sides))
} else {
Subtitle(text = ctx.getString(R.string.skill_random_dice_sides, sides))
Body(text = results.joinToString(" + ") + " = ${results.sum()}")
}
Subtitle(text = ctx.getString(R.string.skill_random_dice_sides, sides))
if (results.size != 1) {
Body(text = results.joinToString(" + ") + " = ${results.sum()}")
}

override fun GraphicalOutput(ctx: SkillContext) {
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
Headline(
text = if (results.size == 1) results[0].toString() else results.sum().toString()
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
text = if (results.size == 1) results[0].toString() else results.sum().toString()
text = results.sum().toString()

<string name="failed_to_copy">Failed to copy to clipboard</string>
<string name="skill_translation_auto">Auto</string>
<string name="skill_search_duckduckgo_recaptcha">DuckDuckGo did not provide results, asking for a Captcha to be solved</string>
<string name="skill_random_coin_flip">The coin landed on %1$s</string>
Copy link
Owner

Choose a reason for hiding this comment

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

I'd rather have two skill_random_coin_flip_heads and skill_random_coin_flip_tails strings, so for languages other than english the strings can be translated naturally in full. Then make the others directly uppercase.

Comment on lines +29 to +34
val total = results.sum()
return if (results.size == 1) {
ctx.getString(R.string.skill_random_dice_roll, results[0], sides)
} else {
ctx.getString(R.string.skill_random_dice_roll_multiple, total, results.size, sides)
}
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
val total = results.sum()
return if (results.size == 1) {
ctx.getString(R.string.skill_random_dice_roll, results[0], sides)
} else {
ctx.getString(R.string.skill_random_dice_roll_multiple, total, results.size, sides)
}
return if (results.size == 1) {
ctx.getString(R.string.skill_random_dice_roll, results[0], sides)
} else {
ctx.getString(R.string.skill_random_dice_roll_multiple, results.sum(), results.size, sides)
}

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.

2 participants