def alpha_beta(board, depth, player, alpha, beta, maxim): if depth == 0 or utils.lastMove(board, player): return utils.score(board, player), -1 valid = utils.get_moves(board, player) if maxim: v = -99999 for move in valid: (tmp_board, tot) = utils.move(move % 8, int(move / 8), player, copy.deepcopy(board)) v = max( alpha_beta(tmp_board, depth - 1, utils.opponent(player), alpha, beta, False)[0], v) alpha = max(alpha, v) if beta <= alpha: break return v, move else: # minimizingPlayer v = 99999 for move in valid: (tmp_board, tot) = utils.move(move % 8, int(move / 8), player, copy.deepcopy(board)) v = min( alpha_beta(tmp_board, depth - 1, utils.opponent(player), alpha, beta, True)[0], v) beta = min(beta, v) if beta <= alpha: break return v, move
def get_playbook_component(component, message, lang): key, _content = get_key_and_content_from_message(message) msg = message.content usr = message.author.display_name s3_client = get_s3_client() char_info = info_from_s3(key, s3_client) json_array = get_moves(lang) playbook_re = get_translation(lang, 'playbooks.playbook_re') #this case deals with if we have a character created, but waits to make sure they haven't passed a playbook in anyway result1 = re.search(playbook_re, msg) found = 0 if result1 is not None: for p in json_array['playbooks']: if p['name'] == result1.group(1): mot = p['mot'] cel = p['celebrate'] wek = p['weakness'] img = p['img'] found = 1 if found != 1: if char_info: playbook = char_info['playbook'] charactername = char_info['characterName'] for p in json_array['playbooks']: if p['name'] == playbook: mot = p['mot'] cel = p['celebrate'] wek = p['weakness'] img = p['img'] usr = charactername found = 1 if found == 1: description = get_translation(lang, 'description') if component == 'mot': embed = discord.Embed(title=get_translation(lang, 'playbooks.moment_of_truth'), colour=5450873) embed.set_author(name=get_translation(lang, 'playbooks.this_is_mot')(usr)) embed.add_field(name=description, value=mot) elif component == 'celebrate': embed = discord.Embed(title=get_translation(lang, 'playbooks.celebrate')) embed.set_author(name=get_translation(lang, 'playbooks.this_is_celebrate')(usr)) embed.add_field(name=description, value=cel) elif component == 'weakness': embed = discord.Embed(title=get_translation(lang, 'playbooks.weakness')) embed.set_author(name=get_translation(lang, 'playbooks.this_is_weakness')(usr)) embed.add_field(name=description, value=wek) embed.set_thumbnail(url=img) embed.set_footer(text=" ") response = embed return response else: response = 0
def get_playbooks(lang): json_array = get_moves(lang) playbooks = get_translation(lang, 'playbooks.playbooks') embed = discord.Embed(title=playbooks) available = get_translation(lang, 'playbooks.available') embed.set_author(name=available) for s in json_array['sources']: line = "" for p in json_array['playbooks']: if s['source'] == p['source']: line = line + p['name'].capitalize() + ", " line = line.rstrip(', ') embed.add_field(name=f"{s['name']}", value=f"{line}", inline=False) embed.set_footer(text=" ") response = embed return response
def get_playbook_component_slash(component, ctx, lang, playbook): key = get_key_from_ctx(ctx) usr = ctx.author.display_name s3_client = get_s3_client() char_info = info_from_s3(key, s3_client) json_array = get_moves(lang) playbook_re = get_translation(lang, 'playbooks.playbook_re') #this case deals with if we have a character created, but waits to make sure they haven't passed a playbook in anyway if playbook is not None: for p in json_array['playbooks']: if p['name'] == playbook: mot = p['mot'] cel = p['celebrate'] wek = p['weakness'] img = p['img'] found = 1 elif char_info: playbook = char_info['playbook'] charactername = char_info['characterName'] for p in json_array['playbooks']: if p['name'] == playbook: mot = p['mot'] cel = p['celebrate'] wek = p['weakness'] img = p['img'] usr = charactername found = 1 description = get_translation(lang, 'description') if component == 'mot': embed = discord.Embed(title=get_translation(lang, 'playbooks.moment_of_truth'), colour=5450873) embed.set_author(name=get_translation(lang, 'playbooks.this_is_mot')(usr)) embed.add_field(name=description, value=mot) if component == 'celebrate': embed = discord.Embed(title=get_translation(lang, 'playbooks.celebrate')) embed.set_author(name=get_translation(lang, 'playbooks.this_is_celebrate')(usr)) embed.add_field(name=description, value=cel) if component == 'weakness': embed = discord.Embed(title=get_translation(lang, 'playbooks.weakness')) embed.set_author(name=get_translation(lang, 'playbooks.this_is_weakness')(usr)) embed.add_field(name=description, value=wek) embed.set_thumbnail(url=img) embed.set_footer(text=" ") response = embed return response
def on_ready(data): print('ready') best = 0 bm = 0 validMoves = utils.get_moves(data['board'], data['player_turn_id']) print(validMoves) print(np.array(data['board']).reshape((8, 8))) value, move = othello_player.alpha_beta(data['board'], 4, data['player_turn_id'], -99999, 99999, True) print(np.array(data['board']).reshape((8, 8))) print(bm) sio.emit( 'play', { 'player_turn_id': data['player_turn_id'], 'tournament_id': tournamentID, 'game_id': data['game_id'], 'movement': move, })
def min_max(board, depth, player, maxim): if depth == 0 or utils.lastMove(board, player): return utils.score(board, player) valid = utils.get_moves(board, player) if maxim: bestValue = -99999 for move in valid: (tmp_board, tot) = utils.move(move, player, copy.deepcopy(board)) v = min_max(tmp_board, depth - 1, utils.opponent(player), False) bestValue = max(bestValue, v) # print(np.array(tmp_board).reshape((8,8))) return bestValue else: # minimizingPlayer bestValue = 99999 for move in valid: (tmp_board, tot) = utils.move(move, player, copy.deepcopy(board)) v = min_max(tmp_board, depth - 1, utils.opponent(player), True) bestValue = min(bestValue, v) # print(np.array(tmp_board).reshape((8,8))) return bestValue
def calculate_moves(self, b): t, a = self.type, self.ally if not t in 'RNBQKP': return [] p = self.pos d = -1 if a == 'W' else 1 if t in 'QK': offs = [-9, -8, -7, -1, 1, 7, 8, 9] elif t == 'R': offs = [-8, -1, 1, 8] elif t == 'B': offs = [-9, -7, 7, 9] elif t == 'N': offs = [-17, -15, -10, -6, 6, 10, 15, 17] else: offs = [i * d for i in [7, 8, 9, 16]] moves = [ list(utils.get_moves(b, self, p + o, o, t in 'RBQ')) for o in offs if utils.valid(p + o) and not self.has_exclusion(p, o) ] return reduce(lambda a, b: [*a, *b], moves, [])
def move(self): next_move = "" try: next_move = next(self.g) except: self.g = utils.get_moves(100) next_move = next(self.g) if next_move == "up": self.y -= 1 elif next_move == "down": self.y += 1 elif next_move == "right": self.x += 1 elif next_move == "left": self.x -= 1 else: raise ValueError("Not found: {}".format(next_move)) if self.x < 0: self.x = 0 if self.y < 0: self.y = 0 if self.x > self.TILES_WIDE: self.x = self.TILES_WIDE if self.y > self.TILES_HEIGH: self.y = self.TILES_HEIGH
def get_moment_of_truth(message, lang): msg = message.content usr = message.author.display_name json_array = get_moves(lang) found = 0 msg = msg.lower() playbook_re = get_translation(lang, 'playbooks.playbook_re') result1 = re.search(playbook_re, msg) for p in json_array['playbooks']: if p['name'] == result1.group(1): mot = p['mot'] img = p['img'] found = 1 if found == 1: embed = discord.Embed(title=get_translation(lang, 'playbooks.moment_of_truth')) embed.set_author(name=get_translation(lang, 'playbooks.this_is_mot')(usr)) embed.set_thumbnail(url=img) description = get_translation(lang, 'description') embed.add_field(name=description, value=mot) embed.set_footer(text=" ") response = embed else: response = 0 return response
def mad_parse(message): msg = message.content user = message.author.display_name blob = "" capital = "" phrase = "" word = "" mod = "" num = int(0) quiet = 0 match = 0 # parse command into parts msg = msg.lower() searchStr1 = r'[a-z]+' searchStr2 = r'[\+\-]' searchStr3 = r'[1234567890]' log_line = '' result1 = re.search(searchStr1, msg) if result1: log_line = log_line + result1.group(0) word = result1.group(0) else: log_line = log_line + "no cmd " result2 = re.search(searchStr2, msg) if result2: log_line = log_line + result2.group() mod = result2.group(0) else: log_line = log_line + "no mod " result3 = re.search(searchStr3, msg) if result3: log_line = log_line + result3.group(0) num = int(result3.group(0)) else: log_line = log_line + "no num " lang = get_raw_lang(message) json_array = get_moves(lang) # figure out which type of modifier it is# num_calc = get_modified_num(mod, num) # lookup a table for the big blob of text and a wee blob# for p in json_array['moves']: if p['shortName'] == word: blob = p['blob'] capital = p['capital'] phrase = p['phrase'] img = p['img'] roll = p['requiresRolling'] match = 1 #Quiet mode searchStr4 = r'!!' result4 = re.search(searchStr4, msg) if result4: quiet = 1 #Ugly format blob!# if match == 1: #lets us ignore ! prefix commands that aren't in our list embed = discord.Embed(title=f"{capital}") embed.set_author(name=f"{user} {phrase}") embed.set_thumbnail(url=img) desc = get_translation(lang, 'description') if quiet == 0: embed.add_field( name=desc, value=f"{blob}" ) # don't include the blob if we're in quiet mode (!!) if roll: add_result(embed, num_calc, mod, lang) embed.set_footer(text=" ") return embed else: return 0
def generate_all_moves(task_root, splits=SPLITS, image_categories='all'): if task_root != '' and not os.path.exists(task_root): try: os.makedirs(task_root) except: print('Cannot create folder {}'.format(task_root)) quit(1) banned_turkers = set(['onboarding', 'vcirik']) image_set = set(CAT2LOC.keys()) if image_categories != 'all': image_set = set(image_categories.split(',')) for image in image_set: if image not in CAT2LOC: raise NotImplementedError( 'Image Category {} is not in the dataset'.format(image)) for split in splits: instances = json.load(open('../data/{}.json'.format(split), 'r')) pbar = tqdm(instances) for ii, instance in enumerate(pbar): if instance['turkerid'] not in banned_turkers: if 'ann_cat' in instance and instance[ 'ann_cat'] == 'M' and split == 'train': continue latitude, longitude = rad2degree(instance['latitude'], instance['longitude'], adjust=True) img_category = '_'.join(instance['imageurl'].split('/') [-1].split('.')[0].split('_')[2:]) pano_name = "_".join(instance['imageurl'].split('/')[-1].split( '.')[0].split('_')[:2]) + ".jpg" if img_category not in CAT2LOC or img_category not in image_set: continue img_loc = CAT2LOC[img_category] image_path = '../data/refer360images/{}/{}/{}'.format( img_loc, img_category, pano_name) sentences = [] for refexp in instance['refexp'].replace('\n', '').split('|||')[1:]: if refexp[-1] not in ['.', '!', '?', '\'']: refexp += '.' sentences.append(refexp.split()) err, all_moves, move_ids = get_moves(instance, latitude, longitude, len(sentences)) if err or all_moves == [] or len( all_moves[0]) != len(sentences): continue generate_gt_moves(image_path, all_moves, move_ids, fov_root=task_root)
def mad_parse(message): msg = message.content user = message.author.display_name blob = "" capital = "" phrase = "" word = "" mod = "" num = int(0) quiet = 0 match = 0 # parse command into parts msg = msg.lower() searchStr1 = r'[a-z]+' searchStr2 = r'[\+\-]' searchStr3 = r'[1234567890]' log_line = '' result1 = re.search(searchStr1, msg) if result1: log_line = log_line + result1.group(0) word = result1.group(0) else: log_line = log_line + "no cmd " result2 = re.search(searchStr2, msg) if result2: log_line = log_line + result2.group() mod = result2.group(0) else: log_line = log_line + "no mod " result3 = re.search(searchStr3, msg) if result3: log_line = log_line + result3.group(0) num = int(result3.group(0)) else: log_line = log_line + "no num " lang = get_raw_lang(message) json_array = get_moves(lang) # figure out which type of modifier it is# # lookup a table for the big blob of text and a wee blob# for p in json_array['moves']: if p['shortName'] == word: blob = p['blob'] capital = p['capital'] phrase = p['phrase'] img = p['img'] roll = p['requiresRolling'] label = p['label'] condition = p.get('condition', '') match = 1 #Quiet mode searchStr4 = r'!!' result4 = re.search(searchStr4, msg) if result4: quiet = 1 if "?" in msg: roll = False quiet = 0 #Find out if user has dicedisplay set to false dicedisplay = True dicedisplay = get_dicedisplay(message, lang) #Ugly format blob!# if match == 1 : #lets us ignore ! prefix commands that aren't in our list character = get_character(message) embed=discord.Embed(title=f"{capital}", colour=5450873) embed.set_footer(text=" ") if character: user = character['characterName'] embed.set_author(name=f"{user} {phrase}") #embed.set_author(name=f"{user} {phrase}") embed.set_thumbnail(url=img) desc = get_translation(lang, 'description') if quiet == 0: embed.add_field(name=desc, value=f"{blob}") # don't include the blob if we're in quiet mode (!!) addendum = None if roll: addendum = handle_roll(character, message, embed, num, mod, lang, label, condition, user) # embed.set_footer(text=" ") # embed.set_author(name=f"{user} {phrase}") if dicedisplay: return (embed, addendum) return (embed, '') else: return None