Yahtzee scoring with lists - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: Yahtzee scoring with lists (/thread-16248.html) |
Yahtzee scoring with lists - DavidM - 01-29-2021 01:15 PM Dave Britten's recent post regarding RPN models that could self-score a Yahtzee game prompted me to look up the game rules that I hadn't looked at since the early '70s. As I am inclined of late to see a list-based approach to many problems, this seemed like an interesting exercise to try. Several of the ListExt commands are a nice fit for the scenarios presented for scoring in the game. First, some ground rules for my approach:
Aces - Sixes The "upper section" scoring simply sums the values of a chosen die value (1 through 6). LCNT (List Count) is a good fit for this one: Code: \<< Sorted Group Counts A couple of the "lower section" scoring subroutines make use of a shared intermediate step. I think of this as "sorted group counts", and have named the subroutine that computes it SGC accordingly. SGC returns a list of counts of matching dice in the supplied input, sorted in ascending order. Example: If the input list is { 1 6 4 1 4 }, SGC returns { 1 2 2 } (one 6, two 1s, two 4s). Note that the results are sorted by quantity, not die value. The line comments below show the intermediate results with the above input for better understanding. Code: SGC Three or Four of a Kind This subroutine checks the size of the largest group of repeated die. If 3 or 4 is <= the largest count, then the sum of all dice is returned. Code: \<< Full House This one is fairly brute-force. It simply finds the sorted group count, and checks to see if it exactly matches 2 of one value and 3 of another. Code: \<< Small or Large Straight The approach used here is to look at the differences of the sorted dice list to determine if a straight of the specified size exists. The ListExt command LDLTA gives the same result as the built-in \GDLIST, but is slightly faster and much easier to type into a program. :-) Code: \<< Yahtzee (5 of a Kind) A very simple scenario to check. Code: \<< Chance (any combination) Even simpler than Yahtzee! Code: \<< These are just the methods that came to mind as I looked at the rules. I'm sure there's other approaches (list-based and otherwise), and thoughts and alternate methods are always appreciated. RE: Yahtzee scoring with lists - Dave Britten - 01-29-2021 01:46 PM Very interesting techniques. I'll bet they could serve as the basis for implementations on RPN models. |