def score_check(self, category, dice, scorecard): #For current score current_score = Scorecard() current_score.scorecard = scorecard.scorecard.copy() current_score.Categories = copy.deepcopy(scorecard.Categories) current_score.Numbers = scorecard.Numbers.copy() current_score.record(category,dice) return current_score.scorecard[category]
def rest_check(self, dice, scorecard): #For remaining dice readings current_score = Scorecard() current_score.scorecard = scorecard.scorecard.copy() current_score.Categories = copy.deepcopy(scorecard.Categories) current_score.Numbers = scorecard.Numbers.copy() available_category = { "unos" : 0, "doses" : 0, "treses" : 0, "cuatros" : 0, "cincos" : 0, "seises" : 0, "pupusa de queso" : 0, "pupusa de frijol" : 0, "elote" : 0, "triple" : 0, "cuadruple" : 0, "quintupulo" : 0, "tamal" : 0 } check_possibilty = False for current_category in available_category: if current_category not in current_score.scorecard: current_score.record(current_category, dice) if available_category[current_category]==0: available_category[current_category] = current_score.scorecard[current_category] best_available_score = max(available_category.values()) #Checking for next best if len(available_category)>0: for my_index, label in available_category.items(): if label == best_available_score: return my_index if check_possibilty == False: return "null"
def find_category(self, dice, scorecard, finalFlag): returnCategory = [] maxScoreCapacity = { "unos": 5, "doses": 10, "treses": 15, "cuatros": 20, "cincos": 25, "seises": 30, "pupusa de queso": 40, "pupusa de frijol": 30, "elote": 25, "triple": 36, "cuadruple": 36, "quintupulo": 36, "tamal": 36 } compare = lambda x, y: collections.Counter(x) == collections.Counter(y) self.diceCounts = [dice.dice.count(i) for i in range(1, 7)] valSc = Scorecard() [ valSc.record(cats, dice) for cats in Scorecard.Categories if cats not in scorecard.scorecard ] if 5 in self.diceCounts and 'quintupulo' not in scorecard.scorecard: returnCategory = [ 'quintupulo', self.getKeptDice('quintupulo', dice) ] elif 4 in self.diceCounts and 'cuadruple' not in scorecard.scorecard: returnCategory = ['cuadruple', self.getKeptDice('cuadruple', dice)] elif 3 in self.diceCounts and 2 in self.diceCounts and 'elote' not in scorecard.scorecard: returnCategory = ['elote', self.getKeptDice('elote', dice)] elif 3 in self.diceCounts and 'triple' not in scorecard.scorecard: returnCategory = ['triple', self.getKeptDice('triple', dice)] elif compare((dice.dice), [1, 2, 3, 4, 5]) or compare( (dice.dice), [2, 3, 4, 5, 6]) and 'pupusa de queso' not in scorecard.scorecard: returnCategory = [ 'pupusa de queso', self.getKeptDice('pupusa de queso', dice) ] elif len(set([1, 2, 3, 4]) - set(dice.dice)) == 0 or len( set([2, 3, 4, 5]) - set(dice.dice) ) == 0 or len(set([3, 4, 5, 6]) - set(dice.dice) ) == 0 and 'pupusa de frijol' not in scorecard.scorecard: returnCategory = [ 'pupusa de frijol', self.getKeptDice('pupusa de frijol', dice) ] if (returnCategory != [] and returnCategory[0] not in scorecard.scorecard) or (finalFlag == 0): if returnCategory == [] or returnCategory[0] in scorecard.scorecard: for rep in range(0, 5): if self.diceCounts.__contains__(6 - rep): return [ '', [ i for i, x in enumerate(dice.dice) if x in [ j + 1 for j, y in enumerate(self.diceCounts) if y == (6 - rep) ] ] ] else: if rep == 3: if len(set([1, 2, 3]) - set(dice.dice)) == 0 or len( set([2, 3, 4]) - set(dice.dice)) == 0 or len( set([3, 4, 5]) - set(dice.dice)) == 0 or len( set([4, 5, 6]) - set(dice.dice)) == 0: if len(set([1, 2, 3]) - set(dice.dice)) == 0: return [ '', [ i for i, x in enumerate(dice.dice) if x in [1, 2, 3] ] ] elif len(set([2, 3, 4]) - set(dice.dice)) == 0: return [ '', [ i for i, x in enumerate(dice.dice) if x in [2, 3, 4] ] ] elif len(set([3, 4, 5]) - set(dice.dice)) == 0: return [ '', [ i for i, x in enumerate(dice.dice) if x in [3, 4, 5] ] ] elif len(set([4, 5, 6]) - set(dice.dice)) == 0: return [ '', [ i for i, x in enumerate(dice.dice) if x in [4, 5, 6] ] ] return ['', []] else: return returnCategory else: retKey = [ k for k, v in valSc.scorecard.items() if v == max(valSc.scorecard.values()) ][0] return [retKey, self.getKeptDice(retKey, dice)]
from ZacateState import Dice from ZacateState import Scorecard from ZacateAutoPlayer import ZacateAutoPlayer ####### # Main program: # # Plays 100 games of Zacate and averages together the scores. # scores = [] for i in range(0, 1000): print "\n\n***** Starting a new game of Zacate!!" d = Dice() s = Scorecard() ap = ZacateAutoPlayer() for i in range(1, 14): print "\n * Turn " + str(i) # first roll d.roll() print " Roll #1: " + str(d) which_to_reroll = ap.first_roll(d, s) d.reroll(which_to_reroll) print " Roll #2: " + str(d) which_to_reroll = ap.second_roll(d, s)