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. Whoever has the highest score is the winner.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. The first player to reach 10,000 points begins the final round. A player who rolls no scoring dice three times in a row loses 1,000 points. A player who rolls a one may score 100 points, but he may not score 1,000 points by rolling two more ones on a subsequent turn and adding them to the one he already had. A player who rolls three ones earns 1,000 points.ĭice can’t be saved for future scoring. Three twos are worth 200 points, threes are 300 points, fours are 400 points, fives are 500 points, and sixes are 600 points. All other numbers must be scored as part of a set of three numbers. Ones and fives are the only numbers that can be scored alone. The player can choose to continue playing until he can’t score anymore dice or until he decides to pass on a turn and score the points he has. Any dice that can’t be scored during a player’s turn can be rolled again. Ones and fives can be set aside and scored immediately, or the player can roll again for a chance at scoring more valuable combinations. Each player rolls six dice on his turn to play Farkle.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |