Exemplo n.º 1
0
def final_strategy(score, opponent_score, margin=8):
    """Write a brief description of your final strategy.

    *** YOUR DESCRIPTION HERE ***
    """
    # BEGIN Question 10
    zero = 0
    digits = [
        int(i) for i in str(opponent_score)
    ]  # https://stackoverflow.com/questions/21270320/turn-a-single-number-into-single-digits-python
    for i in digits:
        if i + 1 > zero:
            zero = i + 1
    if (is_swap(score + zero, opponent_score)
            and opponent_score > score) or zero >= margin:
        return 0

    if score >= 90:
        return 3

    if select_dice(score, opponent_score) == four_sided:
        return 3

    if score - opponent_score > 20:
        return 5

    return 7
Exemplo n.º 2
0
    def strategy(self, score, opp_score):
        s0 = score if self.who == 0 else opp_score
        s1 = opp_score if self.who == 0 else score
        self.s_labels[0].text = s0
        self.s_labels[1].text = s1
        self.roll_label.text = name(self.who) + ' will roll:'
        status = self.status_label.text
        if hog.select_dice(score, opp_score) == hog.four_sided:
            status += ' Hog Wild!'
        self.status_label.text = status

        if self.computer and self.who == self.turn:
            self.update()
            self.after(DELAY)
            result = hog.final_strategy(score, opp_score)
        else:
            self.roll_entry.focus_set()
            self.wait_variable(self.roll_verified)
            result = self.roll_verified.get()
            self.roll_entry.text = ''
        if result == HogGUI.KILL:
            raise HogGUIException

        self.clear_dice()
        self.dice_count = 0
        self.status_label.text = '{} chose to roll {}.'.format(
            name(self.who), result)
        self.switch()
        return result
Exemplo n.º 3
0
    def strategy(self, score, opp_score):
        """A strategy with a hook to the GUI. This strategy gets
        passed into the PLAY function from the HOG module. At its
        core, the strategy waits until a number of rolls has been
        verified, then returns that number. Game information is
        updated as well.

        score     -- player's score
        opp_score -- opponent's score
        """
        s0 = score if self.who == 0 else opp_score
        s1 = opp_score if self.who == 0 else score
        self.s_labels[0].text = s0
        self.s_labels[1].text = s1
        self.roll_label.text = name(self.who) + ' will roll:'
        status = self.status_label.text
        if hog.select_dice(score, opp_score) == hog.four_sided:
            status += ' Hog Wild!'
        self.status_label.text = status

        if self.computer and self.who == self.turn:
            self.update()
            self.after(DELAY)
            result = hog.final_strategy(score, opp_score)
        else:
            self.roll_entry.focus_set()
            self.wait_variable(self.roll_verified)
            result = self.roll_verified.get()
            self.roll_entry.text = ''
        if result == HogGUI.KILL:
            raise HogGUIException

        self.clear_dice()
        self.dice_count = 0
        self.status_label.text = '{} chose to roll {}.'.format(
            name(self.who), result)
        self.switch()
        return result
Exemplo n.º 4
0
    def strategy(self, score, opp_score):
        """A strategy with a hook to the GUI. This strategy gets
        passed into the PLAY function from the HOG module. At its
        core, the strategy waits until a number of rolls has been
        verified, then returns that number. Game information is
        updated as well.

        score     -- player's score
        opp_score -- opponent's score
        """
        s0 = score if self.who == 0 else opp_score
        s1 = opp_score if self.who == 0 else score
        self.s_labels[0].text = s0
        self.s_labels[1].text = s1
        self.roll_label.text = name(self.who) +' will roll:'
        status = self.status_label.text
        if hog.select_dice(score, opp_score) == hog.four_sided:
            status += ' Hog Wild!'
        self.status_label.text = status

        if self.computer and self.who == self.turn:
            self.update()
            self.after(DELAY)
            result = hog.final_strategy(score, opp_score)
        else:
            self.roll_entry.focus_set()
            self.wait_variable(self.roll_verified)
            result = self.roll_verified.get()
            self.roll_entry.text = ''
        if result == HogGUI.KILL:
            raise HogGUIException

        self.clear_dice()
        self.dice_count = 0
        self.status_label.text = '{} chose to roll {}.'.format(name(self.who),
                                                               result)
        self.switch()
        return result
Exemplo n.º 5
0
 def test_select_dice4(self):
     val = select_dice(50, 80)
     self.assertTrue(val == six_sided)
Exemplo n.º 6
0
 def test_select_dice3(self):
     val = select_dice(0, 0)
     self.assertTrue(val == four_sided)
Exemplo n.º 7
0
 def test_select_dice2(self):
     val = select_dice(16, 64)
     self.assertTrue(val == six_sided)
Exemplo n.º 8
0
 def test_select_dice1(self):
     val = select_dice(4, 24)
     self.assertTrue(val == four_sided)