Пример #1
0
    def decide(self, dice, all_scores, round_score):
        def rerollable(diceR):
            for i in diceR:
                if i[0] == 5 or i[0] == 1:
                    return len(parkle.flatten_dice(diceR)) - 1
            return 0

        def rerollK(diceK):
            for i in range(len(diceK)):
                if diceK[i][0] == 1:
                    return [1]
                elif diceK[i][0] == 5:
                    return [5]

            return diceK

        #print round_score
        def getMax(diceM):
            keptset2 = []
            if parkle.calculate_set(diceM) > 0:
                return parkle.flatten_dice(diceM)
            for i in range(len(diceM)):
                if diceM[i][1] >= 3:
                    for n in range(diceM[i][1]):
                        keptset2.append(diceM[i][0])
            return keptset2

        keptset = []
        d = parkle.copy_dice(dice)
        m = getMax(dice)
        #print m
        #print calculate_set(m)
        #print calculate_set(m)>=400
        if parkle.calculate_set(m) + round_score >= 400 and len(m) < 6:
            self.kept.append([m])
        elif parkle.calculate_set(m) + round_score >= 400:
            self.kept.append([m])
            return 1
        elif rerollable(dice) >= 3:
            self.kept.append([rerollK(dice)])
            #print(rerollK(dice))
            return 1
        else:
            self.kept.append([[]])
        #print self.kept
        """if d[0][0] == 1 and d[0][1] >= 1:
            l = d[0][1]
            if l == 2:
                self.kept.append([[1], [1]])
            else:
                for j in range(l):
                    keptset.append(1)
                    d[0][1] -= 1

                self.kept.append([keptset])

        else:
            self.kept.append([[]])
        """
        return 0
Пример #2
0
    def decide(self, odice, all_scores, round_score):

        self.turn_threshold += .05

        group = []
        kset = []
        group.append(kset)

        dice_count = len(parkle.flatten_dice(odice))
        kept_count = 0

        dice = parkle.copy_dice(odice)

        ## Determine if there is a "high scoring" set
        if dice_count == 6:
            if len(dice) == 1:
                kept_count = 6

                for i in range(6):
                    kset.append(dice[0][0])
                    dice[0][1] -= 1

                kset = []
                group.append(kset)

            if len(dice) == 3:
                if dice[0][1] == 2 and dice[1][1] == 2 and dice[2][1] == 2:
                    for i in range(2):
                        kset.append(dice[0][0])
                        dice[0][1] -= 1
                    for i in range(2):
                        kset.append(dice[1][0])
                        dice[1][1] -= 1
                    for i in range(2):
                        kset.append(dice[2][0])
                        dice[2][1] -= 1

                    kept_count = 6
                    kset = []
                    group.append(kset)

            elif len(dice) == 2:
                if dice[0][1] == 3 and dice[1][1] == 3:
                    for i in range(3):
                        kset.append(dice[0][0])
                        dice[0][1] -= 1
                    for i in range(3):
                        kset.append(dice[1][0])
                        dice[1][1] -= 1

                    kept_count = 6

                    kset = []
                    group.append(kset)

            elif len(dice) == 6:
                kept_count = 6

                kset.extend([1, 2, 3, 4, 5, 6])
                kset = []
                group.append(kset)

        ## Take the highest of what's left
        triple_two = -1
        if kept_count == 0:
            m = 0
            for i in range(1, len(odice)):
                if dice[i][1] >= dice[m][1]:
                    if dice[i][0] == 2 and dice[i][1] == 3:
                        triple_two = i
                    else:
                        m = i

            if dice[m][1] >= 3:
                kept_count = dice[m][1]
                for i in range(dice[m][1]):
                    kset.append(dice[m][0])
                    dice[m][1] -= 1
                    kept_count += 1

            else:
                if dice[0][0] == 1:
                    kset.append(1)
                    kset = []
                    group.append(kset)
                    kept_count += 1
                    dice[0][1] -= 1

                elif dice[-1][0] == 5:
                    kset.append(5)
                    kset = []
                    group.append(kset)
                    kept_count += 1
                    dice[-1][1] -= 1

                elif len(dice) > 1 and dice[-2][0] == 5:
                    kset.append(5)
                    kset = []
                    group.append(kset)
                    kept_count += 1
                    dice[-2][1] -= 1

                elif tripe_two >= 0:
                    kset.extend([2, 2, 2])
                    kset = []
                    group.append(kset)
                    kept_count += 3
                    triple_two = -1


        ## Determine if continuing
        if kset == []:
            group = group[:-1]

        self.kept.append(group)

        groupscore = 0
        for i in range(len(group)):
            groupscore += parkle.calculate_set(group[i])

        # passed goal
        res = 0
        if self.score + round_score + groupscore > 10000:
            res = 0

        elif dice_count == 6:
            res = 1

        elif dice_count - kept_count >= 3:
            if dice_count - kept_count == 3 and self.turn_threshold > .75:
                res = 0

            res = 1

        else:
            if self.turn_threshold <= .25:
                res = 1
            else:
                ## get everything else
                res = 0
                if triple_two > 0:
                    group.append([2, 2, 2])
                    kept_count += 3

                if dice[0][0] == 1:
                    for i in range(dice[0][1]):
                        group.append([dice[0][0]])
                        kept_count += 1

                if dice[-1][0] == 5:
                    kset = []
                    for i in range(dice[-1][1]):
                        group.append([dice[-1][0]])
                        kept_count += 1

                if len(dice) > 1 and dice[-2][0] == 5:
                    kset = []
                    for i in range(dice[-2][1]):
                        group.append([dice[-2][0]])
                        kept_count += 1

        #for i in range(len(group)):
        #    print group[i],
        #print
        return res
Пример #3
0
    def decide(self, dice, all_scores, round_score):
        def rerollable(diceR):
            for i in diceR:
                if i[0]==5 or i[0]==1:
                    return len(parkle.flatten_dice(diceR))-1
            return 0
        def rerollK(diceK):
            for i in range(len(diceK)):
                if diceK[i][0]==1:
                    return [1]
                elif diceK[i][0]==5:
                    return [5]
                
            return diceK
        #print round_score
        def getMax(diceM):
            keptset2 = []
            if parkle.calculate_set(diceM)>0:
                return parkle.flatten_dice(diceM)
            for i in range(len(diceM)):
                if diceM[i][1]>=3:
                    for n in range(diceM[i][1]):
                        keptset2.append(diceM[i][0])
            return keptset2

        
        keptset = []
        d = parkle.copy_dice(dice)
        m=getMax(dice)
        #print m
        #print calculate_set(m)
        #print calculate_set(m)>=400
        if parkle.calculate_set(m)+round_score>=400 and len(m)<6:
            self.kept.append([m])
        elif parkle.calculate_set(m)+round_score>=400:
            self.kept.append([m])
            return 1
        elif rerollable(dice)>=3:
            self.kept.append([rerollK(dice)])
            #print(rerollK(dice))
            return 1
        else:
            self.kept.append([[]])
        #print self.kept


            
        """if d[0][0] == 1 and d[0][1] >= 1:
            l = d[0][1]
            if l == 2:
                self.kept.append([[1], [1]])
            else:
                for j in range(l):
                    keptset.append(1)
                    d[0][1] -= 1

                self.kept.append([keptset])

        else:
            self.kept.append([[]])
        """
        return 0