temporalio / samples-php

Temporal PHP SDK samples
Other
88 stars 40 forks source link

[Bug] Allow for repeated pairs in update scoring #55

Closed vid-n3t closed 1 month ago

vid-n3t commented 2 months ago

What are you really trying to do?

Correct the logic in the 'Update' sample's dice scoring code, to allow for multiple pairs of the same number.

Describe the bug

When the rolled dice values result in 3 pairs and 2 or 3 pair are the same number, such as: 1,1; 2,2; 2,2; or 3,3; 3,3; 3,3;, the 'Three pairs' logic fails to allow for repeated pairs;

Minimal Reproduction

  1. Run the update game until you have 3 pairs, and two or more pairs are repeated;

  2. Select all pairs

  3. Result: "Picked dice with value # has no score"

    Dice values: 4,3,3,3,4,3. When repeated pairs are selected for 3 pairs, it error out
  4. Expected result: "Your total score is 750 (+750)"

QA notes: For testing you can ensure this case by updating the roll(): function in app/src/Updates/Zonk/Dice.php b/app/src/Updates/Zonk/Dice.php to return all one number or randomly assign two numbers:

diff --git a/app/src/Updates/Zonk/Dice.php b/app/src/Updates/Zonk/Dice.php
index 216d37a..1b95da6 100644
--- a/app/src/Updates/Zonk/Dice.php
+++ b/app/src/Updates/Zonk/Dice.php
@@ -37,6 +37,6 @@ final class Dice

     private function roll(): int
     {
-        return $this->value = \random_int(1, 6);
+        return $this->value = \random_int(3, 4); //force 3's and 4's to increase the likelyhood of 3 pairs of repeated pairs: 3,3; 4,4; 4,4;
     }
 }

Environment/Versions

Additional context

Just a quick fix:

-            if (\count(\array_unique($values)) === 3
+            if (\count(\array_unique($values)) <= 3

to allow for repeated pairs in the sample.

roxblnfk commented 2 months ago

Hi. Sorry for the delay.

Farkle has many variations with different rules. The variation implemented in the example (Zonk) implies that four identical dice and a pair of others cannot form "three pairs". image

I found rules where four identical dice can form "three pairs," but in this version, the prize points for other denominations are different.

Q. I rolled four-of-a-kind and a pair. What is my score? A. 1500 points. Four of a kind would be 1000, but if you're lucky enough to pair up the other two dice, it's actually three pairs even though four dice are identical. https://web.archive.org/web/20110812072301/http://www.pocketfarkel.com/frequentquestions.html

vid-n3t commented 1 month ago

Thanks for doing the deep dive @roxblnfk!

So I suppose it works as designed then, and I'll close the bug and PR.

Either way, it was a fun tangent to dig into!