Updating with latest version
This commit is contained in:
parent
2b0ed9effe
commit
1086acdbe9
@ -220,8 +220,9 @@ def display_board():
|
|||||||
playing = True
|
playing = True
|
||||||
dict_list = []
|
dict_list = []
|
||||||
wager_type_list = []
|
wager_type_list = []
|
||||||
|
bet = ""
|
||||||
wagers = []
|
wagers = []
|
||||||
|
DEBUG = False
|
||||||
|
|
||||||
def spin_wheel()-> int:
|
def spin_wheel()-> int:
|
||||||
print()
|
print()
|
||||||
@ -248,7 +249,7 @@ def build_a_list_of_wager_types():
|
|||||||
print(f"Wager dict: {wager_dict}")
|
print(f"Wager dict: {wager_dict}")
|
||||||
if isinstance(wager_dict, dict):
|
if isinstance(wager_dict, dict):
|
||||||
wager_type_list.append(wager_dict)
|
wager_type_list.append(wager_dict)
|
||||||
build_a_list_of_wagers()
|
build_a_dict_of_wagers(selected_key)
|
||||||
else:
|
else:
|
||||||
print(f"'{selected_key}' exists but is not a dictionary.")
|
print(f"'{selected_key}' exists but is not a dictionary.")
|
||||||
else:
|
else:
|
||||||
@ -261,49 +262,70 @@ def build_a_list_of_wager_types():
|
|||||||
return wager_type_list
|
return wager_type_list
|
||||||
|
|
||||||
|
|
||||||
def build_a_list_of_wagers():
|
def build_a_dict_of_wagers(code):
|
||||||
wager = input("Enter a wager for this wager_type (e.g. 10 for $10) ")
|
bet = input("Enter a wager for this wager_type (e.g. 10 for $10) ")
|
||||||
|
wager = {code: bet}
|
||||||
wagers.append(wager)
|
wagers.append(wager)
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(f"Wagers: {wagers}")
|
print(f"Wagers: {wagers}")
|
||||||
return wagers
|
return wagers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def search_number_in_dicts(dict_list: list, number_to_find: int):
|
def search_number_in_dicts(dict_list: list, number_to_find: int):
|
||||||
results = {}
|
matched_results = {}
|
||||||
for i, d in enumerate(dict_list):
|
unmatched_results = {}
|
||||||
if isinstance(d, dict): # Only process if it's a dictionary
|
|
||||||
matching_keys = [ k for k, v in d.items()
|
for i, d in enumerate(dict_list):
|
||||||
if ( (isinstance(v, (list, tuple, set)) and number_to_find in v) or
|
if not isinstance(d, dict):
|
||||||
(isinstance(v, str) and str(number_to_find) in v) or
|
print(f"Warning: Item at index {i} is not a dictionary. Skipping.")
|
||||||
(v == number_to_find) ) ]
|
continue
|
||||||
if matching_keys:
|
|
||||||
results[f'dict_{i+1}'] = matching_keys
|
matched_keys = []
|
||||||
if DEBUG:
|
unmatched_keys = []
|
||||||
print(f"Results: {results}")
|
|
||||||
else: print(f"Warning: Item at index {i} is not a dictionary. Skipping.")
|
for k, v in d.items():
|
||||||
return results
|
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_keys.append(k)
|
||||||
|
else:
|
||||||
|
unmatched_keys.append(k)
|
||||||
|
|
||||||
|
if matched_keys:
|
||||||
|
matched_results[f'dict_{i+1}'] = matched_keys
|
||||||
|
if DEBUG:
|
||||||
|
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):
|
def tuple_matches_pattern(data, pattern):
|
||||||
return any(re.search(pattern, item) for item in data)
|
return any(re.search(pattern, item) for item in data)
|
||||||
|
|
||||||
|
|
||||||
def match_wager_type(code):
|
def match_wager_type(code):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(f"Code: {code}")
|
print(f"Code: {code}")
|
||||||
|
|
||||||
for wager_type, pattern in WAGER_PATTERNS.items():
|
for wager_type, pattern in WAGER_PATTERNS.items():
|
||||||
if re.fullmatch(pattern, code) or re.match(pattern, code):
|
if re.fullmatch(pattern, code) or re.match(pattern, code):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(f"Wager type from match_wager_type(code): {wager_type}")
|
print(f"Wager type from match_wager_type(code): {wager_type}")
|
||||||
return 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):
|
def log_match(wager_code, wager_amount, wager_type, payout):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
@ -313,22 +335,59 @@ def log_match(wager_code, wager_amount, wager_type, payout):
|
|||||||
def log_unmatched(wager_code, wager_amount, wager_type):
|
def log_unmatched(wager_code, wager_amount, wager_type):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(f"Unmatched wager code: {wager_code} as {wager_type} → {wager_amount} × -1 = {wager_amount * -1}")
|
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():
|
def calculate_profits():
|
||||||
profits = 0
|
profits = 0
|
||||||
for sublist in wager_types_and_wagers:
|
for item in wagers:
|
||||||
wager_code = sublist[0]
|
for key, value in item.items():
|
||||||
wager_amount = int(sublist[1])
|
if DEBUG:
|
||||||
wager_type = match_wager_type(wager_code)
|
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:
|
if DEBUG:
|
||||||
print(f"Wager type: {wager_type}")
|
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
|
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 ---------------------------------
|
# ----------------------------- 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
|
# User selects which dictionaries to search for number the wheel returns
|
||||||
wager_type_list = build_a_list_of_wager_types()
|
wager_type_list = build_a_list_of_wager_types()
|
||||||
#number = spin_wheel()
|
#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))
|
wager_types_and_wagers = list(zip(flat_list, wagers))
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(f"Wager types and wagers list: {wager_types_and_wagers}")
|
print(f"Wager types and wagers list: {wager_types_and_wagers}")
|
||||||
|
|
||||||
profits = calculate_profits()
|
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) ")
|
playing_again = input("Do you want to keep playing? (y/n) ")
|
||||||
wagers.clear()
|
|
||||||
if playing_again != "y":
|
if playing_again != "y":
|
||||||
playing = False
|
playing = False
|
||||||
else:
|
else:
|
||||||
continue
|
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