Untitled
unknown
python
2 months ago
8.4 kB
7
Indexable
import tkinter as tk from tkinter import filedialog import os import glob # Create the main window root = tk.Tk() root.title("Heads or Tails Counter") # Set the window size root.geometry("400x600") # Global variable to store the folder path folder_path = None last_modified_time = None # Global variable to store the sequences sequences = [] last_displayed_sequence = "" balance = 1000 # Initial balance # Weights for prediction models frequency_weight = 0.65 pattern_weight = 0.35 # Track the last prediction and actual outcome last_prediction = None last_actual = None # Function to update counts and sequences def update_counts(event=None): global sequences, last_displayed_sequence, last_actual content = text_widget.get("1.0", tk.END).lower() heads_count = content.count('(h) has defeated') tails_count = content.count('(t) has defeated') result_label.config(text=f"Heads: {heads_count}, Tails: {tails_count}") # Reset sequences sequences = [] current_sequence = [] # Parse the content to find sequences for line in content.splitlines(): if '(h) has defeated' in line: current_sequence.append('H') elif '(t) has defeated' in line: current_sequence.append('T') # If the sequence ends, add it to sequences list if current_sequence: sequences.append(current_sequence) current_sequence = [] # Update the latest sequence label if it has changed latest_sequence = ''.join([item for sublist in sequences for item in sublist]) if latest_sequence != last_displayed_sequence: last_displayed_sequence = latest_sequence latest_sequence_label.config(text=f"Latest Sequence: {latest_sequence}") # Predict the next occurrence next_occurrence, confidence = predict_next_occurrence(sequences) prediction_label.config(text=f"Next: {next_occurrence}") # Calculate and display the bet amount based on confidence bet_amount = calculate_bet_amount(confidence) bet_label.config(text=f"Bet Amount: {bet_amount:.2f}% of balance") # Update the last actual outcome if latest_sequence: last_actual = latest_sequence[-1] # Function to predict the next occurrence def predict_next_occurrence(sequences): global last_prediction, frequency_weight, pattern_weight if not sequences: print("No sequences found.") return "Unknown", 0.0 # Flatten the sequences list flat_sequences = [item for sublist in sequences for item in sublist] # Check for specific patterns pattern_prediction = "Unknown" if len(flat_sequences) >= 5: last_five = ''.join(flat_sequences[-5:]) if last_five.endswith('TTH'): pattern_prediction = 'H' elif last_five.endswith('THT'): pattern_prediction = 'T' # Add more patterns as needed # Count occurrences of 'H' and 'T' h_count = flat_sequences.count('H') t_count = flat_sequences.count('T') # Print counts for debugging print(f"Counts - H: {h_count}, T: {t_count}") # Frequency-based prediction if h_count > t_count: frequency_prediction = 'H' elif t_count > h_count: frequency_prediction = 'T' else: frequency_prediction = "Unknown" # Combine predictions with weights if pattern_prediction == "Unknown": last_prediction = frequency_prediction return frequency_prediction, 0.65 if frequency_prediction == "Unknown": last_prediction = pattern_prediction return pattern_prediction, 0.35 # Combine predictions if frequency_prediction == pattern_prediction: last_prediction = frequency_prediction return frequency_prediction, 1.0 else: # If predictions differ, use weighted random choice import random combined_prediction = random.choices( [frequency_prediction, pattern_prediction], weights=[frequency_weight, pattern_weight] )[0] confidence = frequency_weight if combined_prediction == frequency_prediction else pattern_weight last_prediction = combined_prediction return combined_prediction, confidence # Function to calculate bet amount based on confidence def calculate_bet_amount(confidence): global balance if confidence >= 0.8: risk_level = "confident" bet_percentage = 0.2 # High bet amount elif confidence >= 0.5: risk_level = "not risky" bet_percentage = 0.1 # Medium bet amount else: risk_level = "risky" bet_percentage = 0.05 # Low bet amount bet_amount = balance * bet_percentage return bet_amount / balance * 100 # Return as percentage of balance # Function to handle folder selection def select_folder(): global folder_path, last_modified_time folder_path = filedialog.askdirectory() if folder_path: monitor_folder() # Function to monitor the folder for changes def monitor_folder(): global last_modified_time, last_prediction, last_actual, frequency_weight, pattern_weight if folder_path: try: # Get the latest file in the folder list_of_files = glob.glob(os.path.join(folder_path, '*')) latest_file = max(list_of_files, key=os.path.getmtime) current_modified_time = os.path.getmtime(latest_file) if current_modified_time != last_modified_time: with open(latest_file, 'r') as file: content = file.read().lower() text_widget.delete("1.0", tk.END) text_widget.insert(tk.END, content) update_counts() last_modified_time = current_modified_time # Adjust weights based on the last prediction and actual outcome if last_prediction and last_actual: if last_prediction != last_actual: if last_prediction == 'H': frequency_weight -= 0.05 pattern_weight += 0.05 elif last_prediction == 'T': frequency_weight += 0.05 pattern_weight -= 0.05 # Ensure weights are within bounds frequency_weight = max(0.0, min(1.0, frequency_weight)) pattern_weight = max(0.0, min(1.0, pattern_weight)) print(f"Adjusted Weights - Frequency: {frequency_weight}, Pattern: {pattern_weight}") frequency_weight_label.config(text=f"Frequency Weight: {frequency_weight:.2f}") pattern_weight_label.config(text=f"Pattern Weight: {pattern_weight:.2f}") except Exception as e: result_label.config(text=f"Error monitoring folder: {e}") root.after(1000, monitor_folder) # Schedule the function to run again after 1 second # Add a button to open the folder dialog button = tk.Button(root, text="Select a folder", command=select_folder) button.pack(pady=20) # Add a Text widget for text input text_widget = tk.Text(root, height=10, width=40) text_widget.pack(pady=20) text_widget.bind("<KeyRelease>", update_counts) # Add a label to display the result result_label = tk.Label(root, text="Heads: 0, Tails: 0") result_label.pack(pady=20) # Add a label to display the prediction prediction_label = tk.Label(root, text="Next: Unknown") prediction_label.pack(pady=20) # Add a label to display the latest sequence latest_sequence_label = tk.Label(root, text="Latest Sequence: ") latest_sequence_label.pack(pady=20) # Add a label to display the bet amount bet_label = tk.Label(root, text="Bet Amount: 0.00% of balance") bet_label.pack(pady=20) # Add labels to display the weights frequency_weight_label = tk.Label(root, text=f"Frequency Weight: {frequency_weight:.2f}") frequency_weight_label.pack(pady=20) pattern_weight_label = tk.Label(root, text=f"Pattern Weight: {pattern_weight:.2f}") pattern_weight_label.pack(pady=20) # Run the application root.mainloop()
Editor is loading...
Leave a Comment