Updating with latest version
This commit is contained in:
parent
2b0ed9effe
commit
1086acdbe9
@ -220,8 +220,9 @@ def display_board():
|
||||
playing = True
|
||||
dict_list = []
|
||||
wager_type_list = []
|
||||
bet = ""
|
||||
wagers = []
|
||||
|
||||
DEBUG = False
|
||||
|
||||
def spin_wheel()-> int:
|
||||
print()
|
||||
@ -248,7 +249,7 @@ def build_a_list_of_wager_types():
|
||||
print(f"Wager dict: {wager_dict}")
|
||||
if isinstance(wager_dict, dict):
|
||||
wager_type_list.append(wager_dict)
|
||||
build_a_list_of_wagers()
|
||||
build_a_dict_of_wagers(selected_key)
|
||||
else:
|
||||
print(f"'{selected_key}' exists but is not a dictionary.")
|
||||
else:
|
||||
@ -261,8 +262,9 @@ def build_a_list_of_wager_types():
|
||||
return wager_type_list
|
||||
|
||||
|
||||
def build_a_list_of_wagers():
|
||||
wager = input("Enter a wager for this wager_type (e.g. 10 for $10) ")
|
||||
def build_a_dict_of_wagers(code):
|
||||
bet = input("Enter a wager for this wager_type (e.g. 10 for $10) ")
|
||||
wager = {code: bet}
|
||||
wagers.append(wager)
|
||||
if DEBUG:
|
||||
print(f"Wagers: {wagers}")
|
||||
@ -271,39 +273,59 @@ def build_a_list_of_wagers():
|
||||
|
||||
|
||||
def search_number_in_dicts(dict_list: list, number_to_find: int):
|
||||
results = {}
|
||||
matched_results = {}
|
||||
unmatched_results = {}
|
||||
|
||||
for i, d in enumerate(dict_list):
|
||||
if isinstance(d, dict): # Only process if it's a dictionary
|
||||
matching_keys = [ k for k, v in d.items()
|
||||
if ( (isinstance(v, (list, tuple, set)) and number_to_find in v) or
|
||||
if not isinstance(d, dict):
|
||||
print(f"Warning: Item at index {i} is not a dictionary. Skipping.")
|
||||
continue
|
||||
|
||||
matched_keys = []
|
||||
unmatched_keys = []
|
||||
|
||||
for k, v in d.items():
|
||||
if (
|
||||
(isinstance(v, (list, tuple, set)) and number_to_find in v) or
|
||||
(isinstance(v, str) and str(number_to_find) in v) or
|
||||
(v == number_to_find) ) ]
|
||||
if matching_keys:
|
||||
results[f'dict_{i+1}'] = matching_keys
|
||||
(v == number_to_find)
|
||||
):
|
||||
matched_keys.append(k)
|
||||
else:
|
||||
unmatched_keys.append(k)
|
||||
|
||||
if matched_keys:
|
||||
matched_results[f'dict_{i+1}'] = matched_keys
|
||||
if DEBUG:
|
||||
print(f"Results: {results}")
|
||||
else: print(f"Warning: Item at index {i} is not a dictionary. Skipping.")
|
||||
return results
|
||||
print(f"Matched Results for dict_{i+1}: {matched_keys}")
|
||||
if unmatched_keys:
|
||||
unmatched_results[f'dict_{i+1}'] = unmatched_keys
|
||||
if DEBUG:
|
||||
print(f"Unmatched Results for dict_{i+1}: {unmatched_keys}")
|
||||
|
||||
if DEBUG:
|
||||
print(f"\nFinal Matched keys: {matched_results}")
|
||||
print(f"Final Unmatched keys: {unmatched_results}")
|
||||
|
||||
return matched_results, unmatched_results
|
||||
|
||||
|
||||
|
||||
def tuple_matches_pattern(data, pattern):
|
||||
return any(re.search(pattern, item) for item in data)
|
||||
|
||||
|
||||
def match_wager_type(code):
|
||||
if DEBUG:
|
||||
print(f"Code: {code}")
|
||||
|
||||
for wager_type, pattern in WAGER_PATTERNS.items():
|
||||
if re.fullmatch(pattern, code) or re.match(pattern, code):
|
||||
if DEBUG:
|
||||
print(f"Wager type from match_wager_type(code): {wager_type}")
|
||||
return wager_type
|
||||
return None # ← Only return None after all patterns have been checked
|
||||
|
||||
|
||||
|
||||
DEBUG = True
|
||||
|
||||
def log_match(wager_code, wager_amount, wager_type, payout):
|
||||
if DEBUG:
|
||||
@ -313,23 +335,60 @@ def log_match(wager_code, wager_amount, wager_type, payout):
|
||||
def log_unmatched(wager_code, wager_amount, wager_type):
|
||||
if DEBUG:
|
||||
print(f"Unmatched wager code: {wager_code} as {wager_type} → {wager_amount} × -1 = {wager_amount * -1}")
|
||||
unmatched = []
|
||||
if wager_type is None:
|
||||
losses += wager_amount
|
||||
unmatched.append((wager_code, wager_amount))
|
||||
|
||||
|
||||
def calculate_profits():
|
||||
profits = 0
|
||||
for sublist in wager_types_and_wagers:
|
||||
wager_code = sublist[0]
|
||||
wager_amount = int(sublist[1])
|
||||
wager_type = match_wager_type(wager_code)
|
||||
for item in wagers:
|
||||
for key, value in item.items():
|
||||
if DEBUG:
|
||||
print(f"Line 346: Wager types and wagers: {wagers}")
|
||||
wager_code = key
|
||||
wager_amount = int(value)
|
||||
for k, v in matched_results.items():
|
||||
if DEBUG:
|
||||
print(f"k is {k} and v is {v}")
|
||||
print(f"Wager code is: {wager_code}")
|
||||
wager_type = match_wager_type(wager_code)
|
||||
payout = int(payouts.get(wager_type, 0))
|
||||
if str(wager_code) in v:
|
||||
profits += wager_amount * payout
|
||||
|
||||
if DEBUG:
|
||||
print(f"Wager type: {wager_type}")
|
||||
if wager_type:
|
||||
print(f"DEBUG: wager_code={wager_code}, matched_type={wager_type}")
|
||||
payout = int(payouts.get(wager_type, 0))
|
||||
log_match(wager_code, wager_amount, wager_type, payout)
|
||||
profits += wager_amount * payout
|
||||
return profits
|
||||
|
||||
def calculate_losses():
|
||||
losses = 0
|
||||
for item in wagers:
|
||||
for key, value in item.items():
|
||||
if DEBUG:
|
||||
print(f"Line 366: Wager types and wagers: {wagers}")
|
||||
wager_code = key
|
||||
wager_amount = int(value)
|
||||
for k, v in unmatched_results.items():
|
||||
if DEBUG:
|
||||
print(f"k is {k} and v is {v}")
|
||||
print(f"Wager code is: {wager_code}")
|
||||
if str(wager_code) in v:
|
||||
losses += wager_amount
|
||||
if DEBUG:
|
||||
print(f"LOSS → code: {wager_code}, amount: {wager_amount}")
|
||||
wager_type = match_wager_type(wager_code)
|
||||
|
||||
if DEBUG:
|
||||
print(f"Wager for type: {wager_amount}")
|
||||
|
||||
if DEBUG:
|
||||
print(f"DEBUG: wager_code={wager_code}, wager_type={repr(wager_type)}")
|
||||
|
||||
return losses
|
||||
|
||||
|
||||
|
||||
# ----------------------------- G A M E P L A Y ---------------------------------
|
||||
|
||||
@ -340,47 +399,32 @@ while playing:
|
||||
# User selects which dictionaries to search for number the wheel returns
|
||||
wager_type_list = build_a_list_of_wager_types()
|
||||
#number = spin_wheel()
|
||||
results = search_number_in_dicts(wager_type_list, 32)
|
||||
matched_results, unmatched_results = search_number_in_dicts(wager_type_list, 4)
|
||||
|
||||
flat_list = [item for sublist in results.values() for item in sublist]
|
||||
flat_list = [item for sublist in matched_results.values() for item in sublist]
|
||||
wager_types_and_wagers = list(zip(flat_list, wagers))
|
||||
if DEBUG:
|
||||
print(f"Wager types and wagers list: {wager_types_and_wagers}")
|
||||
|
||||
profits = calculate_profits()
|
||||
holdings += profits
|
||||
print(f"Your total profits are: ${profits} and current holdings are: ${holdings}")
|
||||
|
||||
flat_list = [item for sublist in unmatched_results.values() for item in sublist]
|
||||
if DEBUG:
|
||||
print(f"Line 404: {flat_list}")
|
||||
wager_types_and_wagers = list(zip(flat_list, wagers))
|
||||
if DEBUG:
|
||||
print(f"Line 407: {wagers}")
|
||||
print(f"Line 405: wager_types_and_wagers: {wager_types_and_wagers}")
|
||||
|
||||
losses = calculate_losses()
|
||||
|
||||
holdings += (profits - losses)
|
||||
print(f"Your profits are: ${profits} and losses are {losses} yielding current holdings: ${holdings}")
|
||||
keep_current_wagers = input("Do you want to leave your wagers on the table? (y/n): ").lower()
|
||||
if keep_current_wagers != 'y':
|
||||
wagers.clear()
|
||||
playing_again = input("Do you want to keep playing? (y/n) ")
|
||||
wagers.clear()
|
||||
if playing_again != "y":
|
||||
playing = False
|
||||
else:
|
||||
continue
|
||||
|
||||
''' unmatching_keys = [ k for k, v in d.items()
|
||||
if ( (isinstance(v, (list, tuple, set)) and number_to_find in v) or
|
||||
(isinstance(v, str) and str(number_to_find) in v) or
|
||||
(v != number_to_find) ) ]'''
|
||||
|
||||
'''def search_number_in_dicts(dict_list: list, number_to_find: int):
|
||||
results = {}
|
||||
for i, d in enumerate(dict_list):
|
||||
if isinstance(d, dict): # Only process if it's a dictionary
|
||||
matched = []
|
||||
unmatched = []
|
||||
for k, v in d.items():
|
||||
if (
|
||||
(isinstance(v, (list, tuple, set)) and number_to_find in v) or
|
||||
(isinstance(v, str) and str(number_to_find) in v) or
|
||||
(v == number_to_find)
|
||||
):
|
||||
matched.append(k)
|
||||
print(matched)
|
||||
else:
|
||||
unmatched.append(k)
|
||||
results[f'dict_{i+1}'] = {
|
||||
'matched_keys': matched,
|
||||
'unmatched_keys': unmatched
|
||||
}
|
||||
else:
|
||||
print(f"Warning: Item at index {i} is not a dictionary. Skipping.")
|
||||
return results'''
|
||||
Loading…
Reference in New Issue
Block a user