Exemple #1
0
    def plays(self, score):
        '''This is where the computer plays its turn'''
        #TODO break out Controller and View logic and make testable
        self.score = score
        set_of_dice = SetOfDice()
        self.turn_scorer = TurnScorer()
        the_dice = set_of_dice.roll_all()
        user_input = True
        while user_input is True:
            the_dice = self.turn_scorer.score_roll(*the_dice)

            if the_dice is None:
                print("{} went bust!".format('Computer'))
                self.turn_scorer.zero_score()
                break
            else:
                print("{}'s counting dice: ".format('Computer'))
                display_dice(*self.turn_scorer.return_dice_held())
                print("Dice returned: ")
                display_dice(*the_dice, inline=True)
                user_input = self.will_play(len(the_dice))

            print("{}'s score: {}".format('Computer', self.turn_scorer.return_score()))
            the_dice = set_of_dice.roll(*the_dice)
            sleep(2)


        return self.turn_scorer.return_score()
Exemple #2
0
class Computer:
    '''This contains all of the computer playing logic'''
    set_of_dice = SetOfDice()
    turn_scorer = TurnScorer()
    score = {}

    def will_play(self, num_dice):
        '''This is the main 'will the computer roll' logic'''
        for player, score in self.score.items():
            if player == 'Computer':
                computer_score = score
            else:
                player_score = score
        if num_dice > 3:
            return True
        elif num_dice == 3:
            if computer_score > player_score:
                return False
            else:
                return True
        elif num_dice == 2:
            if self.turn_scorer.return_score() > 400:
                return False
            else:
                return True
        elif num_dice == 1:
            return False

    def plays(self, score):
        '''This is where the computer plays its turn'''
        #TODO break out Controller and View logic and make testable
        self.score = score
        set_of_dice = SetOfDice()
        self.turn_scorer = TurnScorer()
        the_dice = set_of_dice.roll_all()
        user_input = True
        while user_input is True:
            the_dice = self.turn_scorer.score_roll(*the_dice)

            if the_dice is None:
                print("{} went bust!".format('Computer'))
                self.turn_scorer.zero_score()
                break
            else:
                print("{}'s counting dice: ".format('Computer'))
                display_dice(*self.turn_scorer.return_dice_held())
                print("Dice returned: ")
                display_dice(*the_dice, inline=True)
                user_input = self.will_play(len(the_dice))

            print("{}'s score: {}".format('Computer', self.turn_scorer.return_score()))
            the_dice = set_of_dice.roll(*the_dice)
            sleep(2)


        return self.turn_scorer.return_score()
Exemple #3
0
    def players_turn(self, player='User'):
        set_of_dice = SetOfDice()
        the_dice = set_of_dice.roll_all()
        turnscorer = TurnScorer()
        user_input = ''
        while user_input == '':
            the_dice = turnscorer.score_roll(*the_dice)
            if the_dice is None:
                print("{} went bust!".format(player))
                turnscorer.zero_score()
                break
            else:
                print("{}'s counting dice: ".format(player))
                display_dice(*turnscorer.return_dice_held())
                print("Dice returned: ")
                display_dice(*the_dice, inline=True)

            print("{}'s score: {}".format(player, turnscorer.return_score()))
            the_dice = set_of_dice.roll(*the_dice)
            user_input = input('Press return to keep going?')
        return turnscorer.return_score()