forked from rDrama/rDrama
dedup converting game state to json
parent
a18c2e24e9
commit
85abc39632
|
@ -1,6 +1,8 @@
|
|||
from sqlalchemy import *
|
||||
from files.__main__ import Base
|
||||
import time
|
||||
from files.helpers.lazy import lazy
|
||||
import json
|
||||
|
||||
CASINO_GAME_KINDS = ['blackjack', 'slots', 'roulette']
|
||||
|
||||
|
@ -24,3 +26,8 @@ class Casino_Game(Base):
|
|||
|
||||
def __repr__(self):
|
||||
return f"<CasinoGame(id={self.id})>"
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def game_state_json(self):
|
||||
return json.loads(self.game_state)
|
||||
|
|
|
@ -95,7 +95,7 @@ def gambler_placed_roulette_bet(gambler, bet, which, amount, currency):
|
|||
if len(active_games) == 0:
|
||||
parent_id = int(time.time())
|
||||
else:
|
||||
parent_id = json.loads(active_games[0].game_state)['parent_id']
|
||||
parent_id = active_games[0].game_state_json['parent_id']
|
||||
|
||||
charge_gambler(gambler, amount, currency)
|
||||
|
||||
|
@ -130,7 +130,7 @@ def get_roulette_bets_and_betters():
|
|||
participants.append(game.user_id)
|
||||
|
||||
user = get_account(game.user_id)
|
||||
game_state = json.loads(game.game_state)
|
||||
game_state = game.game_state_json
|
||||
bet = game_state['bet']
|
||||
bets[bet].append({
|
||||
'game_id': game.id,
|
||||
|
|
|
@ -76,7 +76,7 @@ def get_active_twentyone_game(gambler):
|
|||
|
||||
def get_active_twentyone_game_state(gambler):
|
||||
active_game = get_active_twentyone_game(gambler)
|
||||
full_state = json.loads(active_game.game_state)
|
||||
full_state = active_game.game_state_json
|
||||
return remove_exploitable_information(full_state)
|
||||
|
||||
|
||||
|
@ -286,7 +286,7 @@ def dispatch_action(gambler, action):
|
|||
raise Exception(
|
||||
f'Illegal action {action} passed to Blackjack#dispatch_action.')
|
||||
|
||||
state = json.loads(game.game_state)
|
||||
state = game.game_state_json
|
||||
|
||||
if action == BlackjackAction.BUY_INSURANCE:
|
||||
if not can_purchase_insurance(state):
|
||||
|
|
Loading…
Reference in New Issue