def __init__(self): self.chosen = () self.d1 = Die(6) self.d2 = Die(6) self.d3 = Die(6) self.d4 = Die(6) self.d5 = Die(6) self.cup_of_dice = [self.d1, self.d2, self.d3, self.d4, self.d5] self.choices = { "Yahtzee": False, "Chance": False, "Large Straight": False, "Small Straight": False, "Ones": False, "Twos": False, "Threes": False, "Fours": False, "Fives": False, "Sixes": False, "Three of a Kind": False, "Four of a Kind": False, "Full House": False, "Small Straight": False, "Large Straight": False } self.total = 0
def __init__(self): self.chosen = () self.d1 = Die(6) self.d2 = Die(6) self.d3 = Die(6) self.d4 = Die(6) self.d5 = Die(6) self.cup_of_dice = [self.d1, self.d2, self.d3, self.d4, self.d5]
def __init__(self): self.chosen = () self.d1 = Die(6) self.d2 = Die(6) self.d3 = Die(6) self.d4 = Die(6) self.d5 = Die(6) self.cup_of_dice = [self.d1, self.d2, self.d3, self.d4, self.d5] self.choices = {"Yahtzee": False}
def set_possible_damage(self): total = 0 # print(self.weapon_obj.effect_obj.items()) for key, value in self.weapon_obj.damage_dict.items(): if value[0] == 1 and self.versatile_use_2handed is True: d = Die(ctx=self.ctx, sides=self.weapon_obj.versatile_2hnd_die) self.die_used = self.weapon_obj.versatile_2hnd_die self.rolls_used = self.weapon_obj.versatile_2hnd_mod total += d.roll(rolls=self.weapon_obj.versatile_2hnd_mod) else: d = Die(ctx=self.ctx, sides=value[2]) total += d.roll(rolls=value[1]) self.die_used = value[2] self.rolls_used = value[1] return total
def createStartingDie(self, topNum, rightNum, playerStr): d = Die() die = [0] * 6 keyPiece = False # Die[top, bottom, left, right, front, back] # When creating a key piece set the keypiece bool to true if(topNum == 1 and rightNum == 1): die[0] = 1 die[1] = 1 die[2] = 1 die[3] = 1 die[4] = 1 die[5] = 1 keyPiece = True else: die[0] = topNum die[1] = 7 - topNum die[2] = 7 - rightNum die[3] = rightNum die[4] = 4 die[5] = 3 d.setDie(die) d.setKeyPiece(keyPiece) d.setPlayer(playerStr) return d
def __init__(self): print(" -- Welcome to die game called 'oczko'! -- ") self.__die = Die(6) self.__playerScore = 0 self.__computerScore = 0 self.__on = True
def player_turn(player, hand): ''' Logic of one player's turn ''' # Declare player n's turn print('\n' + player.name + "'s turn! \n") # Create 6 dice named A-F dice_letters = ['A', 'B', 'C', 'D', 'E', 'F'] dice = [] for letter in dice_letters: dice.append(Die()) dice_dict = dict(zip(dice_letters, dice)) # Roll and keep values until player's hand has 6 values while len(hand.rolls) < 6: input(">> Press Enter to roll. ") temp_rolls = {} # Show rolled dice with letter names dice_header = '' for die in dice_dict.keys(): dice_header += (' ' + die + ' ') temp_roll = dice_dict[die].roll() temp_rolls[die] = temp_roll #print(Roll(temp_roll)) print(dice_header) display_funcs.ndice(*temp_rolls.values()) # Show player's hand print('Your hand: ') # print(hand) hand.display_hand() # Ask player which dice to keep kept = ask_keep(dice_letters) # Add kept dice to player's hand for die in set(kept): hand.keep_roll(temp_rolls[die]) # Remove kept dice from ones that are "rollable" dice_letters.remove(die) del dice_dict[die] # Show updated hand and score hand.calc_score() hand.display_hand() print(player.name + "'s score: " + str(hand.score))
def get_alignment(self, db): """ Preferred racial alignment is based on a percentage. So, generate a random percentage and pick the alignment that percentage belongs in. """ d = Die(ctx=self.ctx, sides=100) rnd_pct = d.roll() sql = (f"select count(alignment) from dnd_5e.v_alignment_preference " f"where race = '{self.race}';") cnt_result = db.query(sql) if cnt_result[0][0] > 0: use_race = self.race else: use_race = self.subrace_of sql = (f"select count(alignment) from dnd_5e.v_alignment_preference " f"where race = '{use_race}';") cnt_result = db.query(sql) if cnt_result[0][0] > 0: sql = (f"select b.abbreviation, b.value as alignment " f"from dnd_5e.v_alignment_preference as a " f"join lu_alignment as b on a.alignment = b.abbreviation " f"where race = '{use_race}' " f"and lowerbound < {rnd_pct} and upperbound >= {rnd_pct};") alignment_results = db.query(sql) return { "abbreviation": alignment_results[0][0], "alignment": alignment_results[0][1] }
def __init__(self): MAX_COL = 9 MAX_ROW = 8 self.gameboard = [[Die() for j in range(MAX_COL)] for i in range(MAX_ROW)] # Computer Starting Positions self.gameboard[7][0] = self.createStartingDie(5, 6, "C") self.gameboard[7][1] = self.createStartingDie(1, 5, "C") self.gameboard[7][2] = self.createStartingDie(2, 1, "C") self.gameboard[7][3] = self.createStartingDie(6, 2, "C") self.gameboard[7][4] = self.createStartingDie(1, 1, "C") self.gameboard[7][5] = self.createStartingDie(6, 2, "C") self.gameboard[7][6] = self.createStartingDie(2, 1, "C") self.gameboard[7][7] = self.createStartingDie(1, 5, "C") self.gameboard[7][8] = self.createStartingDie(5, 6, "C") # Human Starting Positions self.gameboard[0][0] = self.createStartingDie(5, 6, "H") self.gameboard[0][1] = self.createStartingDie(1, 5, "H") self.gameboard[0][2] = self.createStartingDie(2, 1, "H") self.gameboard[0][3] = self.createStartingDie(6, 2, "H") self.gameboard[0][4] = self.createStartingDie(1, 1, "H") self.gameboard[0][5] = self.createStartingDie(6, 2, "H") self.gameboard[0][6] = self.createStartingDie(2, 1, "H") self.gameboard[0][7] = self.createStartingDie(1, 5, "H") self.gameboard[0][8] = self.createStartingDie(5, 6, "H")
def dieSwitch(self, topNum, rightNum, player): # Die[top, bottom, left, right, front, back] d = Die() if(topNum == 1): if(rightNum == 1): d = self.createDie(topNum, rightNum, 1, 1, player) elif(rightNum == 2): d = self.createDie(topNum, rightNum, 3, 4, player) elif(rightNum == 3): d = self.createDie(topNum, rightNum, 5, 2, player) elif(rightNum == 4): d = self.createDie(topNum, rightNum, 2, 5, player) elif(rightNum == 5): d = self.createDie(topNum, rightNum, 4, 3, player) elif(topNum == 2): if(rightNum == 1): d = self.createDie(topNum, rightNum, 4, 3, player) elif(rightNum == 3): d = self.createDie(topNum, rightNum, 1, 6, player) elif(rightNum == 4): d = self.createDie(topNum, rightNum, 6, 1, player) elif(rightNum == 6): d = self.createDie(topNum, rightNum, 3, 4, player) elif(topNum == 3): if(rightNum == 1): d = self.createDie(topNum, rightNum, 2, 5, player) elif(rightNum == 2): d = self.createDie(topNum, rightNum, 6, 1, player) elif(rightNum == 5): d = self.createDie(topNum, rightNum, 1, 6, player) elif(rightNum == 6): d = self.createDie(topNum, rightNum, 5, 2, player) elif(topNum == 4): if(rightNum == 1): d = self.createDie(topNum, rightNum, 5, 2, player) elif(rightNum == 2): d = self.createDie(topNum, rightNum, 1, 6, player) elif(rightNum == 5): d = self.createDie(topNum, rightNum, 6, 1, player) elif(rightNum == 6): d = self.createDie(topNum, rightNum, 2, 5, player) elif(topNum == 5): if(rightNum == 1): d = self.createDie(topNum, rightNum, 3, 4, player) elif(rightNum == 3): d = self.createDie(topNum, rightNum, 6, 1, player) elif(rightNum == 4): d = self.createDie(topNum, rightNum, 1, 6, player) elif(rightNum == 6): d = self.createDie(topNum, rightNum, 4, 3, player) elif(topNum == 6): if(rightNum == 2): d = self.createDie(topNum, rightNum, 4, 3, player) elif(rightNum == 3): d = self.createDie(topNum, rightNum, 2, 5, player) elif(rightNum == 4): d = self.createDie(topNum, rightNum, 5, 2, player) elif(rightNum == 5): d = self.createDie(topNum, rightNum, 3, 4, player) return d
def test_4d6_withresistance(): ctx = Ctx(app_username='******') d = Die(ctx=ctx, sides=6, debug_ind=True) r = d.roll_with_resistance(rolls=4) details = d.get_details()[-1] assert(len(details.base_roll) == 4) assert(details.die_total_used == r) assert(12 >= r >= 2)
def test_d8_droplowest(): ctx = Ctx(app_username='******') d = Die(ctx=ctx, sides=8, debug_ind=True) r = d.roll(rolls=2, droplowest=True) details = d.get_details()[-1] assert(len(details.base_roll) == 2) assert(details.die_total_used == r) assert(8 >= r >= 1)
def main(): if len(sys.argv) == 1: print("No Rolling-Die-Puzzle file provided. Now exiting") return for i in range(1, len(sys.argv)): filename = sys.argv[i] try: board = Board(filename) startLocation = board._dieLocation startDie = Die() for heuristicFunction in SequenceOfHeuristics: print("") raw_input("Press ENTER to continue to next heuristic") print("") print("Heuristic Function: " + heuristicFunction.__name__) print(board) closedCounter = Counter() #global counter for node closing frontierCounter = Counter() #global counter for node expansion emptyPath = tuple() startNode = BoardNode(board, startLocation, startDie, closedCounter, frontierCounter, emptyPath) path = aStarSearch(heuristicFunction, startNode) if path: #if path is found for direction in path: board.moveDie(direction) print(board) print("") print("Length: " + str(len(path))) else: #if path not found print("No Solution") print("Number Visited : " + str(closedCounter.getCount()) + " (including start state)") print("Number Generated: " + str(frontierCounter.getCount())) print("End of heuristic '" + heuristicFunction.__name__ + "'") ##reset board for next heuristic board._die = Die() board._dieLocation = startLocation except IOError as e: print(e) except NoStartError as e: print(e) return
def test_d20_withdisadvantage(): ctx = Ctx(app_username='******') d = Die(ctx=ctx, sides=20, debug_ind=True) r = d.roll_with_disadvantage() details = d.get_details()[-1] assert(len(details.base_roll) == 2) assert(details.die_total_used == r) assert(min(details.base_roll) == r) assert(20 >= r >= 1)
def roll_attack(self): d = Die(ctx=self.ctx, sides=20) if self.vantage == 'Advantage': r = d.roll_with_advantage() elif self.vantage == 'Disadvantage': r = d.roll_with_disadvantage() else: r = d.roll() return r
def movePieceDown(self, row, col): tempBoard = self.getGameBoard() player = tempBoard[row][col].getPlayer(); emptyDie = Die() if(player == 'H'): tempBoard[row][col].backwardMove() else: tempBoard[row][col].frontalMove() tempBoard[row - 1][col] = tempBoard[row][col] tempBoard[row][col] = emptyDie self.setGameBoard(tempBoard)
def initiative_check( NPC_Name ): # Initiative determines which player will have the first move when fight scene begins #Initiative Bonus PC_initiative = PC["Stats"]["Initiative"] NPC_initiative = NPC[NPC_Name]["Dexterity"]["Modifier"] start = Die().initiative_roll(PC_initiative, NPC_initiative, NPC_Name) return start
def movePieceRight(self, row, col): tempBoard = self.getGameBoard() player = tempBoard[row][col].getPlayer(); emptyDie = Die() if(player == 'H'): tempBoard[row][col].lateralRightMove() else: tempBoard[row][col].lateralLeftMove() tempBoard[row][col + 1] = tempBoard[row][col] tempBoard[row][col] = emptyDie self.setGameBoard(tempBoard)
def main(): theDie = Die() go = raw_input("Roll the die? <enter> for yes, no for stopping: ") theDie.roll() while go == "": theDie.roll() print theDie.getValue() print "die = " + str(theDie) go = raw_input("Roll the die? <enter> for yes, no for stopping: ")
def main(): #make a die obj d = Die() print d.roll() b = Board() print b.toString() s1 = Square(57, "Snake", 40) s2 = Square(26, "Ladder", 84) s3 = Square(2, "Plain", 2) print s1.toString() print s2.toString() print s3.toString()
def set_possible_effect(self): # possible_effect = {"effect_type": {"effect_category": , "possible_amount": , # "effect_modifier": , "die_used": , "rolls_used": ,}} self.possible_effect = {} for effect in self.effect_obj.keys(): t_obj = self.effect_obj[effect] d = Die(ctx=self.ctx, sides=t_obj['effect_die']) tmp_rec = { "effect_category": t_obj['effect_category'], "possible_amount": d.roll(rolls=t_obj['effect_modifier']), "die_used": t_obj['effect_die'], "rolls_used": t_obj['effect_modifier'] } self.possible_effect[effect] = tmp_rec
def game(): '''decathlon_400_meters() -> int plays a solitare version of Reiner Knizia's 400 Meters returns final score''' # initializes rerolls, score, and dice score = 0 rerolls = 5 d1 = Die(6, [1, 2, 3, 4, 5, -6]) d2 = Die(6, [1, 2, 3, 4, 5, -6]) # play 4 rounds for gameround in range(1, 5): print("Your total score so far is " + str(score)) print("Round " + str(gameround) + " -- you have " + \ str(rerolls) + " rerolls left.") while True: # roll the dice input("Press enter to roll.") d1.roll() d2.roll() roundscore = d1.getTop() + d2.getTop() print("You rolled " + str(d1.getTop()) + " and " + \ str(d2.getTop()) + " for a total of " + str(roundscore)) # if the player has no rerolls, they're stuck with this if rerolls == 0: print("You're out of rerolls so you have to keep this.") break # see if they want to reroll response = 'x' while response.lower() not in ['y', 'n']: response = input("Do you want to reroll (y/n)? ") if response.lower() == 'n': break # keeping this roll, move on the the next roll # they're using a reroll rerolls -= 1 print("OK, you have " + str(rerolls) + " rerolls left.") score += roundscore # update the score return score
def skill_check( parameters ): # skill_check determines if a player is succesful at an attempt to perform a certain action. # multiple paramters will always be passed in the form of a tuple: skill = skills_main[parameters[0]] # which skill will be checked difficulty = parameters[1] # diffuclty of the task to be performed method = parameters[ 2] # function which will be used after the check is complete. die = parameters[3] # type of die used check_roll = Die().skill_roll(skill, difficulty, die) (method)(check_roll)
def initializer(self): msg = "##################\n" \ "# WELCOME TO PIG #\n" \ "##################\n" print(msg) player1_name = input("Please enter player1 name: ") player2_name = input("Please enter player2 name: ") die = Die() self.p1 = Player(player1_name, die) self.p2 = Player(player2_name, die) self.game = Game(self.p1, self.p2, die)
def roll_die(): global dice_roll sides = int(request.form['sides']) quantity = int(request.form['quantity']) title = 'Results:' die = Die(sides) results = [] for roll_num in range(quantity): result = die.roll() results.append(result) return render_template('rollresults.html', the_title=title, the_results=results)
def run(self, player_type1, player_type2, is_time): die = Die() game = self.initializer(player_type1, player_type2) player1 = game.players[0] player2 = game.players[1] active_player = game.players[0] print(type(active_player)) if is_time: start_time = t.time() end_time = start_time + 60 while end_time < t.time( ) and player1.count <= 100 or player2.count <= 100: print("{} player is up \n".format(active_player.kind)) game.display_selection_menu() if isinstance(active_player, HumanPlayer): self.human_turn(active_player, die, game) else: self.computer_turn(active_player, die, game) active_player = self.switch_player(active_player, game) else: while player1.count <= 100 or player2.count <= 100: print("{} player is up \n".format(active_player.kind)) game.display_selection_menu() if isinstance(active_player, HumanPlayer): self.human_turn(active_player, die, game) else: self.computer_turn(active_player, die, game) active_player = self.switch_player(active_player, game) if player1.count == 100: print("Player {} is the WINNER".format(player1.kind)) else: print("Player {} is the WINNER".format(player2.kind))
def death_saving_throw( ): # When PC falls unconsious death saving throw will be called giving the player a chance to restore some hit points. current_Hit_Points = PC["Stats"]["CHP"]["Current"] health = Die().death_saving_throw(current_Hit_Points) prompt() if health == 0: print("You've failed to restore any Hit Points") return "PC Dead" else: print("You've regained {}".format(health)) return "PC Revived "
def _populate(self): """ Populate a candidate array of Ability Scores """ # standard = [15, 14, 13, 12, 10, 8] # point_buy_even = [13, 13, 13, 12, 12, 12] # point_buy_one_max = [15, 12, 12, 12, 11, 11] # point_buy_two_max = [15, 15, 11, 10, 10, 10] # point_buy_three_max = [15, 15, 15, 8, 8, 8] if self.array_type == "Predefined": self.candidate_array = self.raw_array elif self.array_type == "standard": self.candidate_array = self.const_array_standard elif self.array_type == "point_buy_even": self.candidate_array = self.const_array_point_buy_even elif self.array_type == "point_buy_one_max": self.candidate_array = self.const_array_point_buy_one_max elif self.array_type == "point_buy_two_max": self.candidate_array = self.const_array_point_buy_two_max elif self.array_type == "point_buy_three_max": self.candidate_array = self.const_array_point_buy_three_max else: d = Die(ctx=self.ctx, sides=6) for i in range(0, 6): if self.array_type == "strict": pr = d.roll(rolls=3, droplowest=False) else: pr = d.roll(rolls=4, droplowest=True) self.candidate_array.append(pr) # set the raw_array to whatever we started with for candidate values self.raw_array = self.candidate_array[:] # self.class_eval[-1]["raw_array"] = self.raw_array[:] jdict = {"raw_array": self.raw_array[:]} self.ctx.crumbs[-1].add_audit(json_dict=jdict) self.set_ability_array()
def assign_hit_points(self): if not self.hit_point_adjustment: self.hit_point_adjustment = 0 if self.hit_point_generator == 'Max': ret_val = ((self.hit_point_modifier * self.hit_point_die) + self.hit_point_adjustment) elif self.hit_point_generator == 'Standard': ret_val = self.standard_hit_points else: d = Die(self.hit_point_die) ret_val = (d.roll(self.hit_point_modifier) + self.hit_point_adjustment) jdict = { "hit_point_generator": self.hit_point_generator, "hit_point_modifier": self.hit_point_modifier, "hit_point_die": self.hit_point_die, "hit_point_admustment": self.hit_point_adjustment } self.ctx.crumbs[-1].add_audit(json_dict=jdict) return ret_val
if choice == str(1): num_sides = input('How many sides should the die have? ') try: num_sides = int(num_sides) except ValueError: print('Sorry, that wasn\'t a number!') continue if num_sides >= 3: num_rolls = input('How many times do you want to roll the die? ') try: num_rolls = int(num_rolls) except ValueError: print('Sorry, that wasn\'t a number!') continue if num_rolls >= 1: die1 = Die(num_sides) die1.roll(num_rolls) die1.roll_stats() print(die1.list_of_rolls) for i, freq in zip(range(len(die1.freq_list)), die1.freq_list): print(f'{i+1}:{freq}', end='\t') else: print('Sorry, you have to roll the die at least once!') else: print('Sorry, the die must have at least 3 sides!') elif choice == str(2): num_flips = input('How many times do you want to flip the coin? ') try: num_flips = int(num_flips) except ValueError: print('Sorry, that wasn\'t a number!')