def put(self, name): data = Player.parser.parse_args() # not getting the name correctly from the url name = data["name"] player = PlayerModel.find_by_name(name) # PlayerModel.insert(player) if player: # update attributes player.strategy = data['strategy'] player.buyIn = data["buyIn"] player.chips = data["buyIn"] player.unitBet = data["unitBet"] else: player = PlayerModel(name=name, strategy=strategy, buyIn=buyIn, chips=chips, unitBet=unitBet) player.save_to_db() return player.json()
def delete(self, name): player = PlayerModel.find_by_name(name) if player: item.delete_from_db() return {'message': 'Player deleted'}
def post(self, name): data = Player.parser.parse_args() # not getting the name correctly from the url name = data["name"] if PlayerModel.find_by_name(name): return { 'message': f'A player with name {name} already exists' }, 400 data = Player.parser.parse_args() strategy = data['strategy'] buyIn = data["buyIn"] chips = data["buyIn"] unitBet = data["unitBet"] player = PlayerModel(name=name, strategy=strategy, buyIn=buyIn, chips=chips, unitBet=unitBet) # print(f'{name}:{strategy}:{buyIn}:{chips}{unitBet}') try: player.save_to_db() except: #raise return {'message': 'an error occurred inserting the player.'}, 500 #return player.json(), 201 return redirect("/", code=302)
def get(self, name, division=None, team_name=None): if team_name is None and division is None: players = PlayerModel.find_by_name(name) if players.count() > 0: return {"players": [player.json() for player in players]} elif team_name is None: print(division) else: team = TeamModel.find_by_name_division(team_name, division) if team: players = PlayerModel.find_by_team_id(team.id) if players.count() > 0: return {"players": [player.json() for player in players]} return {"message": "Player does not exists"}
def get(self, name): player = PlayerModel.find_by_name(name) if player: return player.json() return {'message': 'Player not found'}, 404
def run_simulation(self): # get play info from the database playerInfo = [player.json() for player in PlayerModel.query.all()] # create player players = [] for p in playerInfo: player_name = p['name'] player_strategy = p['strategy'] player_buyIn = p['buyIn'] player_chips = p['chips'] player_unitBet = p['unitBet'] a_player = Player(player_name, player_buyIn, player_unitBet, strategy=player_strategy) players.append(a_player) # create a deck and shuffle cards self.new_shoe() # deal cards results = [] for i in range(2000): cards_left = len(self.deck.cards) # print('Cards left in shoe: ', cards_left) if cards_left < self.deck.cut_card: self.new_shoe() self.deal() result = self.hit_or_stand() # This code won't work if we have more than 2 players p = players[0] self.update_bank(p, result['winner']) result['p1_chips'] = p.chips p = players[1] self.update_bank(p, result['winner']) result['p2_chips'] = p.chips results.append(result) print( f'Player hand: {self.player_hand}: Value: {self.player_hand.get_value()}' ) print( f'Dealer hand: {self.dealer_hand}: Value: {self.dealer_hand.get_value()}' ) #print(f"Winner: {result['winner']} Total chips: {p1.chips} {p2.chips}\n") # print(results) print(f'{players[0].name} stats: chips: {players[0].chips}') print(f'{players[1].name} stats: chips: {players[1].chips}') print(f'Player max consecutive wins: {players[0].max_consec_wins}') print(f'Player max consecutive losses: {players[0].max_consec_losses}') # update player stats # to modify to work with multiple players for p in playerInfo: player = PlayerModel.find_by_name(p['name']) if players[0].name == p['name']: player.chips = players[0].chips elif players[1].name == p['name']: player.chips = players[1].chips player.save_to_db() return results