Esempio 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
Esempio n. 2
0
def winning_probability_for_score(score, opponent_score):
    if is_swap(score, opponent_score):
        score, opponent_score = opponent_score, score
    if score >= K_FINAL_SCORE:
        return 1
    elif opponent_score >= K_FINAL_SCORE:
        return 0
    else:
        probability_of_losing = aggegrate_winning_probabilites_for_n(
            opponent_score, score, opponent_strategy(score, opponent_score))
        return 1 - probability_of_losing
Esempio n. 3
0
def swap_strategy(score, opponent_score, margin=8, num_rolls=5):
    """This strategy rolls 0 dice when it results in a beneficial swap and
    rolls NUM_ROLLS if rolling 0 dice results in a harmful swap. It also
    rolls 0 dice if that gives at least MARGIN points and rolls NUM_ROLLS
    otherwise.
    """
    # BEGIN Question 9
    if is_swap(score, opponent_score) and opponent_score > score:
        return 0
    return bacon_strategy(score, opponent_score, margin,
                          num_rolls)  # Replace this statement
Esempio n. 4
0
def swap_strategy(score, opponent_score, margin=8, num_rolls=5):
    """This strategy rolls 0 dice when it results in a beneficial swap and
    rolls NUM_ROLLS if rolling 0 dice results in a harmful swap. It also
    rolls 0 dice if that gives at least MARGIN points and rolls NUM_ROLLS
    otherwise.
    """
    # BEGIN Question 9
    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

    return num_rolls
Esempio n. 5
0
 def test_is_swap6(self):
     self.assertTrue(is_swap(114, 41))
Esempio n. 6
0
 def test_is_swap4(self):
     self.assertTrue(not is_swap(23, 42))
Esempio n. 7
0
 def test_is_swap3(self):
     self.assertTrue(is_swap(41, 14))
Esempio n. 8
0
 def test_is_swap2(self):
     self.assertTrue(not is_swap(20, 40))
Esempio n. 9
0
 def test_is_swap1(self):
     self.assertTrue(is_swap(19, 91))
Esempio n. 10
0
def XJ4_S(FKo_3_0, N_43_, o_5Hw0):
    'yh4_6_T4_58TE82W03E_4o__'
    J_Q_co3 = (FKo_3_0 + o_5Hw0)
    if hog.is_swap(J_Q_co3, N_43_):
        (J_Q_co3, N_43_) = (N_43_, J_Q_co3)
    return (J_Q_co3, N_43_)