def old_action(target, coins): targetLoc = getLocation(target) pocket = util.nearest_pocket(target) pocketLoc = getLocation(pocket) y = util.startpos_y x = target[0] + float(target[0] - pocket[0]) / float( target[1] - pocket[1]) * (y - target[1]) if x < 170 or x > 630: x = 400 posValid = True while not util.isPosValid((x, util.startpos_y), coins): x = random.randrange(170, 630) posValid = False angle = 180 / util.pi * math.atan2(target[1] - y, target[0] - x) if angle < -45: angle = angle + 360 force = random.randrange(80, 100) force = force / 100.0 force = 1 return x, angle, force, posValid
def highPrecision(coins, redLocation, BWcoins, allCoins): targets = directShotAvl(coins, allCoins) print('Direct shot available for %d coins' % len(targets)) print(targets) if(len(targets) == 0): print('-----------Choosing a random coin------------') targets = coins random.shuffle(targets) if(len(BWcoins) <= 3 and len(redLocation) > 0 and random.random() < 0.5 + 1.0/(len(coins))): print('Running behind the queen') targets = redLocation # Choose a target and the value of x for the striker for target in targets: pocket = util.nearest_pocket(target) x_loc, directShot = getPosition(target, pocket) # Break if the striker can be placed if(util.isPosValid((x_loc, util.startpos_y), coins)): break # If no more candidate targets available, choose a random valid position while not util.isPosValid((x_loc, util.startpos_y), coins): x_loc = random.randrange(170, 630) # Find the angle corresponding to the target and x found above angle, angChange = getAngle(target, x_loc, pocket) force, angChange = getForce(target, x_loc, pocket, directShot, coins, angChange) print('Changing angle by %d' % angChange) angle += angChange print("FINAL TARGET", target, 'at pocket', pocket) return x_loc, angle, force
def highForce(coins): n_neighbors_max = 0 targets = [] for coin in coins: temp, _ = num_neighbors(coin, coins, 100) if temp > n_neighbors_max: n_neighbors_max = temp for coin in coins: if num_neighbors(coin, coins, 100)[0] == n_neighbors_max: targets.append(coin) # Choose a target and the value of x for the striker for target in targets: pocket = util.nearest_pocket(target) x_loc, directShot = getPosition(target, pocket) # Break if the striker can be placed if (util.isPosValid((x_loc, util.startpos_y), coins)): break # If no more candidate targets available, choose a random valid position while not util.isPosValid((x_loc, util.startpos_y), coins): x_loc = random.randrange(170, 630) # Find the angle corresponding to the target and x found above angle, angChange = getAngle(target, x_loc, pocket) force = forceBase print('Changing angle by %d' % angChange) angle += angChange print("FINAL TARGET", target, 'at pocket', pocket) return x_loc, angle, force
def best_action(target, coins): # y=145 is the location of line from which to strike and it stretches from x=170 to x=630 pocket = util.nearest_pocket(target) #striker to start from (x,y) y = 145 x = target[0] + float(target[0] - pocket[0]) / float( target[1] - pocket[1]) * (y - target[1]) if x < 170 or x > 630: x = 400 while not util.isPosValid((x, 145), coins): x = random.randrange(170, 630) angle = 180 / util.pi * math.atan2(target[1] - y, target[0] - x) if angle < -45: angle = angle + 360 force = 1 # distance = dist(target, pocket) # force = distance/(800*math.sqrt(2))*.25 # force = distance/(400*math.sqrt(2))*.25 return (x, angle, force)