In fact we can factor some of that out to drop the if block. This should handle triplets and quadruplets of any value, and removes from count the number of dice consumed by the grouping. Let's use that! for die, count in ems():ĭie_score += die * 2000 if die = 1 else die * 200ĭie_score += die * 1000 if die = 1 else die * 100 We already know that the triple value for each number is 100 * number, except for 1 which is 100 * 10 * number. If (die = 5 and count != 3): score += (count * 50)įirst of all, avoid these repeated if statements. This should be: for die, count in enumerate(dice_array, start=1):īut since I switched to using a collections.Counter, we can just do: for die, count in ems(): We'll stop here for just long enough to mention that enumerate takes a keyword argument start that lets you tell it where to start counting from. Let's look: for i, count in enumerate(dice_array): Your counting loop isn't a whole lot better. ![]() counts will throw a KeyError while counts.get(non_rolled_die, 0) will act like your current code does. It builds a dict-like object, a collections.Counter that has the counts for any dice present in the roll. That might be fast, but it's certainly ugly. ![]() This is wonky because it buids a fixed-size list, then plays with values-as-list-indexes to get a count. # as an aside, this isn't an array, it's a list. Let's take a look at a couple examples of low-level work in your code: dice_array = * sides Print(str(score(roll)) + " : " + str(roll))Ĭode is "pythonic" when it expresses its intention clearly, is easy to read or even looks like pseudo-code, and uses as little low-level garbage as possible. Roll = input("Enter 6 values (1-6) separated by a space: ") If (dice = 5 and count != 3): score += (count * 50) Player would choose which die to 'bank' and which to re-rollĭice = i + 1 #this makes it easier to keep track of the die we're on #add up the number appearances of each die roll and store it in the tableīased on the above scoring, determine the MAXIMUM score in actual Farkle the #create a table to hold the count of each die roll All scoring dice must be rolled in a single turn (i.e. Doubles score nothing (unless a 1 or a 5) as above Quadruple of any non-1 number: Double the triple score Triple of any non-1 number: 100 x number showing Any and all tips are most welcome! """Ĭalculate a Farkle score using the traditional scoring method, which is: I'd like to hear from the community on how I could make it better and more Pythonic. While the results are correct I don't feel it's a very Pythonic implementation. See the Die Category for more information how to gain them and in what way they are manipulated.I've written the following function on Python (3.3) to take a list of 6 integers and return the maximum score for a game of Farkle. Since each player uses his own dice, there's also an opportunity to cheat. three twos are worth 200 points (with one as an exception as three ones are worth 1000 points) - see example table belowįour or more of the same kind is worth double the points, so four 3s are worth 600 points, five 3s are worth 1200 points etc. 3 or more kind of any other number will yield 100 points multiplied by the given number, eg.At the end of the player's turn, the dice are handed to the next player in succession (usually in clockwise rotation), and they have their turn.If none of the dice score in any given throw, the player has "farkled" and all points for that turn are lost.There is no limit to the number of "hot dice" a player may roll in one turn. ![]() If the player has scored all six dice, they have "hot dice" and may continue their turn with a new throw of all six dice, adding to the score they have already accumulated.The player may then either end their turn and bank the score accumulated so far, or continue to throw the remaining dice.After each throw, one or more scoring dice must be set aside (see sections on scoring below).The goal is to be the first one to reach a certain number of points.At the beginning of each turn, the player throws all the dice at once.Farkle is a dice game in Kingdom Come: Deliverance that can be played in almost every tavern.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |