Guest User

Random Ballmer

a guest
Sep 6th, 2024
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | Gaming | 0 0
  1. def choose_random_optimal(n_min, n_max):
  2.    
  3.     n_guesses_left = math.ceil(math.log2(n_max - n_min + 2))
  4.    
  5.     guess_min = max(n_max-2**(n_guesses_left-1)+1, n_min-1+2**(n_guesses_left-2))
  6.     guess_max = min(n_min-1+2**(n_guesses_left-1), n_max-2**(n_guesses_left-2)+1)
  7.  
  8.     return np.random.randint(guess_min, guess_max+1)
  9.  
  10. def choose_random_suboptimal(n_min, n_max):
  11.     n_guesses_left = math.ceil(math.log2(n_max - n_min + 2))
  12.    
  13.     guess_min = max(n_max-2**(n_guesses_left-1)+1, n_min-1+2**(n_guesses_left-2))
  14.     guess_max = min(n_min-1+2**(n_guesses_left-1), n_max-2**(n_guesses_left-2)+1)
  15.    
  16.     n_extra = (n_max - n_min) - (guess_max - guess_min)
  17.    
  18.     if np.random.uniform() > 0.99**n_extra:
  19.         guess = np.random.randint(n_extra) + n_min
  20.         if guess >= guess_min:
  21.             guess+=guess_max-guess_min+1
  22.         return guess
  23.            
  24.     else:
  25.         return np.random.randint(guess_min, guess_max+1)
  26.  
  27. def prepare_strategies(n):
  28.     named_strategies = {}
  29.    
  30.     named_strategies.update({f'random optimal {np.random.randint(1e9)}':
  31.                              predict_wins_binsearch(n, choose_random_optimal(0,99), choose_random_optimal) for x in range(10000)})
  32.     named_strategies.update({f'random suboptimal{np.random.randint(1e9)}':
  33.                              predict_wins_binsearch(n, choose_random_suboptimal(0,99), choose_random_suboptimal) for x in range(10000)})
  34.  
  35.     strategy_names = {}
  36.     strategies = []
  37.     for name, wins in named_strategies.items():
  38.         strategy_names[tuple(wins)] = name
  39.         strategies.append(wins)
  40.  
  41.     return strategies, strategy_names
Advertisement
Add Comment
Please, Sign In to add comment