def test_attackRollIncreasedEveryLevel(self): testCharacter1 = Fighter() testCharacter2 = Character() testCharacter1.levelUp() testCharacter1.levelUp() roll = Roll(testCharacter1, testCharacter2, 1) roll.modifyRoll() self.assertEqual(3, roll.modifiedRoll)
def test_RollModifierOnEvenLevel(self): testCharacter1 = Character() testCharacter2 = Character() testCharacter1.experiencePoints = 2000 testCharacter1.levelUp() testCharacter1.levelUp() roll = 1 modifiedRoll = Roll(testCharacter1, testCharacter2, roll) modifiedRoll.modifyRoll() self.assertEqual(2, modifiedRoll.modifiedRoll)
def attemptAttack(self): self.defender.updateHitPoints(self.defender.getConstitutionModifier()) successfulRoll = Roll(self.attacker, self.defender, self.roll).isSuccessful() if successfulRoll: Damage(self.attacker, self.defender, self.roll).applyDamage() self.attacker.updateCharacter()
def test_tripleDmgOnCritHit(self): testCharacter1 = Rogue() testCharacter2 = Character() roll = Roll(testCharacter1, testCharacter2, 20) attack = Attack(testCharacter1, testCharacter2, roll.initialRoll) attack.attemptAttack() self.assertEqual(2, testCharacter2.hitPoints)
def test_does3DmgInsteadOf1OnSuccessfulAttack(self): testCharacter1 = Monk() testCharacter2 = Character() roll = Roll(testCharacter1, testCharacter2, testCharacter2.armor) attack = Attack(testCharacter1, testCharacter2, roll.initialRoll) attack.attemptAttack() self.assertEqual(2, testCharacter2.hitPoints)
def test_addsDexModToAttacksInsteadOfStrength(self): testCharacter1 = Rogue() testCharacter2 = Character() testCharacter1.dexterity = 12 roll = Roll(testCharacter1, testCharacter2, testCharacter2.armor - 1) attack = Attack(testCharacter1, testCharacter2, roll.initialRoll) attack.attemptAttack() self.assertEqual(3, testCharacter2.hitPoints)
def test_ifOpponentDexModIsPositiveModIsNotAppliedToArmor(self): testCharacter1 = Rogue() testCharacter2 = Character() testCharacter2.dexterity = 12 roll = Roll(testCharacter1, testCharacter2, 10) attack = Attack(testCharacter1, testCharacter2, roll.initialRoll) attack.attemptAttack() self.assertEqual(4, testCharacter2.hitPoints)
def test_attackRollNotIncreasedIfNot2ndOr3rdLevel(self): testCharacter1 = Monk() testCharacter2 = Character() roll = Roll(testCharacter1, testCharacter2, testCharacter2.armor-1) attack = Attack(testCharacter1, testCharacter2, roll.initialRoll) attack.attemptAttack() self.assertEqual(5, testCharacter2.hitPoints)
def generate_rolls(self, roll_number): self.rolls = [] for i in range(roll_number): if self.current_dice == DiceTypes.FAIR: self.rolls.append( Roll(DiceTypes.FAIR, self.fair_dice.random_roll_value())) ran = random.random() if ran > self.from_fair_to_biased_probability: self.current_dice = DiceTypes.BIASED else: self.rolls.append( Roll(DiceTypes.BIASED, self.biased_dice.random_roll_value())) if random.random() > self.from_biased_to_fair_probability: self.current_dice = DiceTypes.FAIR logger.info("Created rolls: {}".format(self.rolls)) return self.rolls
def test_dontAddWisdomModIfNegativeToArmor(self): testCharacter1 = Character() testCharacter2 = Monk() testCharacter2.wisdom = 8 roll = Roll(testCharacter1, testCharacter2, testCharacter2.armor) attack = Attack(testCharacter1, testCharacter2, roll.initialRoll) attack.attemptAttack() self.assertEqual(4, testCharacter2.hitPoints)
def test_attackRollIncreasedBy1Every3rdLevel(self): testCharacter1 = Monk() testCharacter2 = Character() testCharacter1.level = 3 roll = Roll(testCharacter1, testCharacter2, testCharacter2.armor-1) attack = Attack(testCharacter1, testCharacter2, roll.initialRoll) attack.attemptAttack() self.assertEqual(2, testCharacter2.hitPoints)
def test_monkGains6HPPerLevel(self): testCharacter1 = Monk() testCharacter2 = Character() testCharacter1.experiencePoints = 990 roll = Roll(testCharacter1, testCharacter2, testCharacter2.armor) attack = Attack(testCharacter1, testCharacter2, roll.initialRoll) attack.attemptAttack() self.assertEqual(11, testCharacter1.hitPoints)
def setUp(self): fair_dice = Dice() biased_dice = Dice(probabilities=[0.2, 0.2, 0.2, 0.2, 0.2, 0.0]) self.apst = Aposteriori(from_fair_to_biased_probability=0.1, from_biased_to_fair_probability=0.2, fair_dice=fair_dice, biased_dice=biased_dice, number_of_throws=100) #TODO #is it acceptable to use class fields in tests or should i implement generator and environment here? # self.rolls = self.apst.generator.generate_rolls(self.apst.environment.number_of_throws) self.rolls = [] self.rolls.append(Roll(DiceTypes.FAIR, 1)) self.rolls.append(Roll(DiceTypes.FAIR, 3)) self.rolls.append(Roll(DiceTypes.BIASED, 2)) self.rolls.append(Roll(DiceTypes.BIASED, 4)) self.rolls.append(Roll(DiceTypes.FAIR, 6)) self.rolls.append(Roll(DiceTypes.FAIR, 5)) self.rolls.append(Roll(DiceTypes.FAIR, 1)) self.rolls.append(Roll(DiceTypes.BIASED, 2)) self.rolls.append(Roll(DiceTypes.FAIR, 5)) self.rolls.append(Roll(DiceTypes.BIASED, 3))
def createRoll(bot, update, args): global rolllist global rollid if (isAdmin(bot, update)): if (len(args) < 2): sendMsg(bot, update, 'Input error') else: try: rolllist.append(Roll(rollid, args[0], float(args[1]))) sendMsg(bot, update, 'All done, /rolllist to see roll list') rollid = rollid + 1 rolllist[-1].start() except: sendMsg(bot, update, 'Failed with unknown error!')
def main(): playerList = [] nbr_players = input( 'Hej! Välkomna till det här enkla Yatzy-spelet. Var vänlig och ange antalet deltagare (1-4): ' ) try: nbr = int(nbr_players) if nbr < 1 or nbr > 4: raise ValueError() for i in range(nbr): name = input(f'Skriv in namnet för spelare {i+1}: ') playerList.append(Player(name, Verifier(), Roll())) except ValueError: print( 'Error. Var vänlig och försök igen och ange antalet deltager i siffror mellan 1-4.' ) plays_list = playerList[0].get_verifier().plays_left() while len(plays_list) > 0: for p in playerList: print('*' * 50) print('Din tur att slå ' + p.get_name()) roller = p.get_roller() verifier = p.get_verifier() roller.first_roll() roller.keep_dices() roller.second_roll() roller.keep_dices() roller.third_roll() verifier.print_plays_left() current_dices = roller.get_kept_dice_list() choice = input( 'Var vänlig att skriv det nummer som du vill lägga till din poäng på (om du inte kan, skriv x:"NUMMER ATT STRYKA"): ' ) todo = roller.get_methods().get(choice) if todo(current_dices): print(f'Lägger till ponäng i {todo}')
accelerometer_calibration = None if os.path.exists(args.accelerometer_calibration): with open(args.accelerometer_calibration, 'r') as yml: accelerometer_calibration = yaml.load(yml) yml.close() accelerometer_calibration['rais_id'] = args.starting_port service_objects = [ PitchEstimate(accelerometer_calibration), GroundRoll(accelerometer_calibration), RollEstimate(), RollRateEstimate(), TurnRateComputed(), HeadingComputed(heading_calibration, args.starting_port), Pitch(args.gyro_correction, args.pitch_conf_mult), Roll(args.gyro_correction, args.roll_conf_mult), Yaw(accelerometer_calibration, args.yaw_multiplier), Heading(), RollRate(), HeadingTasEstimate(), WindEstimate(), PressureFactors(pressure_calibration), AirspeedComputed(airspeed_config), AirspeedEstimate(), AltitudeComputed(pressure_calibration), TrackRate(), TurnRate(), Airspeed(), Altitude(), ClimbRate(), GroundVector(),
print("-------\t-------\t-------\t-------\t-------\t-------") print("| |\t|o |\t|o |\t|o o|\t|o o|\t|o o|") print("| o |\t| |\t| o |\t| |\t| o |\t|o o|") print("| |\t| o|\t| o|\t|o o|\t|o o|\t|o o|") print("-------\t-------\t-------\t-------\t-------\t-------\n") playerInput = raw_input( 'Who is playing the game? (comma separated: e.g. Bob,Jane,Joe)?\n') playerInput = playerInput.split(',') players = [] for input in playerInput: players.append(ScoreCard(str(input))) rounds = 13 # number of rounds per game dice = Roll() for x in range(rounds): for player in players: printScoreCard(player) for y in range(3): dice.diceRoll() #roll the dice if y == 2: break decision = raw_input( "Reroll or Score?\nDefault is Reroll, if 'score' isn't explicitly stated, you will reroll...\n" ) if "score" in decision.lower(): break else:
def game_loop(): player_name = input("What is your name?\n") print(f"Ok {player_name}, let's do this!") rolls = [Roll("Rock"), Roll("Paper"), Roll("Scissors")] count = 0 player_counter_win = 0 computer_counter_win = 0 while count < 3: player_roll = input( "\nPlease choose your roll [r]ock, [p]aper or [s]cissors: \n") computer_roll = random.choice(rolls) if player_roll == 'r': if computer_roll.name == "Rock": print( f"It's a draw the computer choose also {computer_roll.name}" ) count += 1 continue elif computer_roll.name == "Paper": print( f"Computer won as it chose {computer_roll.name}. You Lose!" ) computer_counter_win += 1 count += 1 continue elif computer_roll.name == "Scissors": print( f"You won this one, as the computer chose {computer_roll.name}. Congratulations!" ) player_counter_win += 1 count += 1 continue elif player_roll == 'p': if computer_roll.name == "Rock": print( f"You won this one, as the computer chose {computer_roll.name}. Congratulations!" ) player_counter_win += 1 count += 1 continue elif computer_roll.name == "Paper": print( f"It's a draw the computer choose also {computer_roll.name}" ) count += 1 continue elif computer_roll.name == "Scissors": print( f"Computer won as it chose {computer_roll.name}. You Lose!" ) computer_counter_win += 1 count += 1 continue elif player_roll == 's': if computer_roll.name == "Rock": print( f"Computer won as it chose {computer_roll.name}. You Lose!" ) computer_counter_win += 1 count += 1 continue elif computer_roll.name == "Paper": print( f"You won this one, as the computer chose {computer_roll.name}. Congratulations!" ) player_counter_win += 1 count += 1 continue elif computer_roll.name == "Paper": print( f"It's a draw the computer choose also {computer_roll.name}" ) count += 1 continue if player_counter_win > computer_counter_win: who_won = "Player" else: who_won = "Computer" print() print(f"The ultimate winner for the whole game is the {who_won}") print( f"The player_counter_win: {player_counter_win} and the computer_counter_win: {computer_counter_win}" )
def __str__(self): for roll in self.rolls: print(Roll(roll)) return ''
def test_method_check_frame_award_should_return_spare(self): roll = [Roll(5, 1), Roll(5, 2)] award = self.current_frame.check_frame_award(roll) assert award == 'spare'
def turn(player_name): game_list_top = ['aces' , 'twos' , 'threes' , 'fours' , 'fives' , 'sixes'] game_list_top_values = [1,2,3,4,5,6] player = Player(player_name) dice1 = Roll() for index, item in enumerate(game_list_top): print ('-'*40) print (f'rolling for {item}') print ('-'*40) dice1.roll_dice() keep1 = dice1.keep_dice() dice1.reroll_dice(keep1) keep2 = dice1.keep_dice() roll3 = dice1.reroll_dice(keep2) dice1.forced_keep(roll3) final_roll_collection = dice1.get_kept_dice() print (f'final roll collection: {final_roll_collection}') top_score = dice1.single_values(final_roll_collection,game_list_top_values[index]) player.add_rolled(item, top_score) player.add_top_score(top_score) bottom_score = dice1.get_bottom_score(final_roll_collection) player.add_bottom_score(bottom_score) player.add_top_bonus() player.add_bottom_bonus() player.add_total_score() player.print_scoreboard() return player.get_total_score()
def test_method_check_frame_award_should_return_strike(self): roll = [Roll(10, 1), Roll(0, 2)] award = self.current_frame.check_frame_award(roll) assert award == 'strike'
def test_method_calculate_current_score_should_return_10(self): rolls = [Roll(7, 1), Roll(3, 2)] current_frame_score = self.current_frame.calculate_frame_score(rolls) assert current_frame_score == 10
def __init__(self): self.die = [] for face in faces: self.die.append(Roll(face))
yml.close() accelerometer_calibration = None if os.path.exists(args.accelerometer_calibration): with open(args.accelerometer_calibration, 'r') as yml: accelerometer_calibration = yaml.load(yml) yml.close() service_objects = [ PitchEstimate(accelerometer_calibration), GroundRoll(accelerometer_calibration), RollEstimate(), RollRateEstimate(), TurnRateComputed(), HeadingComputed(heading_calibration), Pitch(), Roll(), Yaw(), Heading(), RollRate(), HeadingTasEstimate(), WindEstimate(), PressureFactors(pressure_calibration), AirspeedComputed(airspeed_config), AirspeedEstimate(), AltitudeComputed(pressure_calibration), TrackRate(), TurnRate(), Airspeed(), Altitude(), ClimbRate(), GroundVector(),
def roll(bot, update, args): args = args[0] roll = Roll(args) bot.send_message(chat_id=update.message.chat_id, text="Rolling {} : {}".format(args, roll.roll_dice()))