def search_for_words(found_words, population, dic, puzzles, search_range): whole_value = 0 for inhabitant in population: value = 0 for i in range(random.randint(1, search_range // 2), search_range + 1): word = inhabitant.get_str_gene(i) found = dic.find(word) if found: if found.val != 0 and word not in found_words: found_words.append(word) value += calculate_value(word, puzzles) for i in range(random.randint(1, search_range // 2), search_range + 1): word = inhabitant.get_str_gene(i)[::-1] found = dic.find(word) if found: if found.val != 0 and word not in found_words: found_words.append(word) value += calculate_value(word, puzzles) if value > 0: inhabitant.value = value whole_value += value return whole_value
def search_for_words(population, dic, puzzles, search_range): for inhabitant in population: for i in range(1, search_range + 1): word = inhabitant.get_str_gene(i) found = dic.find(word) val = calculate_value(word, puzzles) if found: if found.val != 0 and val > inhabitant.value: inhabitant.value = val
def search_for_words(population, dic, puzzles, best_word=("", 0)): for inhabitant in population: for i in range(1, len(inhabitant) + 1): word = inhabitant.get_str_gene(i) found = dic.find(word) val = calculate_value(word, puzzles) if found: if found.val != 0 and val > inhabitant.value: inhabitant.value = val if val >= best_word[1]: best_word = (word, val) return best_word
def search_for_words(population, dic, puzzles, search_range): for inhabitant in population: value = 0 for i in range(1, search_range + 1): word = inhabitant.get_str_gene(i) found = dic.find(word) val = calculate_value(word, puzzles) if found: if found.val != 0: chrom_value += val if word not in found_words: found_words.append(word) value += val if chrom_value > 0: inhabitant.value = chrom_value
def post_game(): """ Create a new game --- tags: - game definitions: - schema: id: Game properties: id: type: string description: Unique identifier of the game status: type: string description: Any of playing, win or lost. board: type: array items: type: object properties: has_mine: type: boolean description: Indicates if there is a mine in this cell exploded: type: boolean description: Indicates if there is this cell has exploded. revealed: type: boolean description: Indicates if there is this cell has revealed. flagged: type: boolean description: Indicates if there is this cell has been flagged. value: type: integer description: After its revealed, it indicates the number of adjacent mines. description: 2D array of the game cells parameters: - in: body name: body schema: id: GameRequest properties: rows: type: integer description: Number of rows cols: type: integer description: Number of cols mines: type: integer description: Number of mines (not to exceed 50% ratio) responses: 200: description: Game created schema: $ref: '#/definitions/Game' """ params = request.json check_create_params(params) new_game = { 'rows': params.get('rows', DEFAULT_ROWS) if params else DEFAULT_ROWS, 'cols': params.get('cols', DEFAULT_COLS) if params else DEFAULT_COLS, 'mines': params.get('mines', DEFAULT_MINES) if params else DEFAULT_MINES, 'status': 'playing' } validate_game(new_game) generate_board(new_game) add_mines(new_game) calculate_value(new_game) games_col.insert_one(new_game) return dumps(create_view(new_game))