def cond3Stop_p1w_p2w(fn, ngames, alpha=0.05, delta=0.05, newData=False): # returns x,y data of p1wins vs p2wins using condition 1 stopping for a max number of games read = False filename = f"data/{ngames}_{alpha}_{delta}_{fn.__name__}_C3.csv" W1x = [] W1y = [] import os if not newData and os.path.exists( filename): # then read the file so I dont have to generate again print(f"Loading Data for C3 {filename}") import csv with open(filename, 'r') as csvfile: spamreader = csv.reader(csvfile, delimiter=',') for row in spamreader: if row == []: continue x, y = row W1x.append(int(x)) W1y.append(int(y)) read == True # don't save it, cause I didnt create anything. else: print(f"Creating new Data for C3 {filename}") for p2w in range(0, ngames): for p1w in range(0, ngames): n = p1w + p2w ###Cond1 L, U, mean = fn(p1w, n, alpha) shouldI1, type = shouldIStop(1, L, U, mean, n, delta=delta) L, U, mean = fn(n - p1w, n, alpha) shouldI1P2, type = shouldIStop(1, L, U, mean, n, delta=delta) if shouldI1P2 != shouldI1: print("Method is assymetric Cond 1") if shouldI1: #dont draw over condition1 stopping. #print(f"({p2w},{p1w})") continue #NB This is for C3 Data. If C1 would stop then C3 doesnt activate. L, U, mean = fn(p1w, n, alpha / 2.0) shouldI, type = shouldIStop(3, L, U, mean, n, delta=delta) L, U, mean = fn(n - p1w, n, alpha / 2.0) shouldIP2, type = shouldIStop(3, L, U, mean, n, delta=delta) if shouldIP2 != shouldI: print("Method is assymetric Cond 3") if shouldI: W1x.append(p1w) W1y.append(n - p1w) if not read: #then write the file so I dont have to generate again import csv with open(filename, 'w', newline='') as csvfile: spamwriter = csv.writer(csvfile, delimiter=',') xyval = zip(W1x, W1y) for xy in xyval: x, y = [*zip(xy)] spamwriter.writerow(list(xy)) print(f"Data written {filename}") return W1x, W1y
def oldC2cond3Stop_p1w_p2w(fn, ngames, alpha=0.05, delta=0.05, newData=False): #returns x,y data of p1wins vs p2wins using condition 1 stopping for a max number of games read = False filename = f"data/{ngames}_{alpha}_{delta}_{fn.__name__}_C2old.csv" W1x = [] W1y = [] W2x = [] W2y = [] probs = [] minX = 0 import os if not newData and os.path.exists( filename): #then read the file so I dont have to generate again print(f"Loading Data for C2 {filename}") import csv with open(filename, 'r') as csvfile: spamreader = csv.reader(csvfile, delimiter=',') for row in spamreader: if row == []: continue x, y = row W1x.append(int(x)) W1y.append(int(y)) read = True #don't save it, cause I didnt create anything. else: print(f"Creating new Data for C2 {filename}") for p2w in range(0, ngames): for p1w in range(0, ngames): if p1w < minX: continue n = p1w + p2w ###Cond1 L, U, mean = fn(p1w, n, alpha) shouldI1, type = shouldIStop(1, L, U, mean, n, delta=delta) if shouldI1: pass #type 1 wouldve stopped this so dont check next. #continue L, U, mean = fn(p1w, n, alpha / 2.0) shouldI, type = shouldIStop(3, L, U, mean, n, delta=delta) if shouldI: W1x.append(p1w) W1y.append(n - p1w) if not read: #then write the file so I dont have to generate again import csv with open(filename, 'w', newline='') as csvfile: spamwriter = csv.writer(csvfile, delimiter=',') xyval = zip(W1x, W1y) for xy in xyval: x, y = [*zip(xy)] spamwriter.writerow(list(xy)) print(f"Data written {filename}") return W1x, W1y
def cond1Stop_X_nY(fn, ngames): W1x = [] W1y = [] W2x = [] W2y = [] probs = [] minX = 0 for p2w in range(0, ngames): stop = False WStop1 = False for p1w in range(0, ngames): #if p1w < minX: # continue n = p1w + p2w ###Cond1 L, U, mean = fn(p1w, n, 0.05) shouldI, type = shouldIStop(1, L, U, mean, n, delta=0.1) if shouldI and not WStop1: p = p1w / n W1x.append(p) W1y.append(n) probs.append(p) #WStop1 = True if WStop1: minX = p1w stop = True break if stop: stop = False continue return W1x, W1y
def cond1Stop_p1w_p2w(fn, ngames, alpha=0.05, delta=0.05, newData=False): #returns x,y data of p1wins vs p2wins using condition 1 stopping for a max number of games read = False filename = f"data/{ngames}_{alpha}_{delta}_{fn.__name__}_C1.csv" W1x = [] W1y = [] import os if not newData and os.path.exists( filename): #then read the file so I dont have to generate again print(f"Loading Data for C1 {filename}") import csv with open(filename, 'r') as csvfile: spamreader = csv.reader(csvfile, delimiter=',') for row in spamreader: if row == []: continue x, y = row W1x.append(int(x)) W1y.append(int(y)) read == True #don't save it, cause I didnt create anything. else: #have to create the data print(f"Creating new Data for C1 {filename}") for p2w in range(0, ngames): for p1w in range(0, ngames): n = p1w + p2w ###Cond1 L, U, mean = fn(p1w, n, alpha) shouldI, type = shouldIStop(1, L, U, mean, n, delta=delta) if shouldI: W1x.append(p1w) W1y.append(n - p1w) ##write to file so I don't have to keep re-running it. if not read: #then write the file so I dont have to generate again import csv with open(filename, 'w', newline='') as csvfile: spamwriter = csv.writer(csvfile, delimiter=',') xyval = zip(W1x, W1y) for xy in xyval: x, y = [*zip(xy)] spamwriter.writerow(list(xy)) print(f"Data written {filename}") return W1x, W1y