For me this kind of achievement poor student is impossible to rely on knowledge to play turn head king, so how should programmer play 👿?

Let’s take a look at the small program brain king play

Two people participate in each game, five questions, in the case of no props, a correct answer to a maximum of 200 points, the slower the less points, no points for wrong answers.

If you answer correctly in the first second, you get 200 points; if you use one second (9 seconds left), you get 180 points; if you have 8 seconds left, you get 160 points; and so on.

Double the score for the last question, i.e. 400, 380, 360… That’s a theoretical maximum of 1,200 points.

After analyzing the gameplay, we need to analyze our implementation flow

What we need for the process
  1. Open computer, connect USB, make sure to connect 📱
  2. Screenshots, reference WeChat used to WDA, jump jump plugin installation see testerhome.com/topics/1046…

    WDA is a set of iOS testing framework developed by Facebook, which is used as an auxiliary really 💦

  3. Ocr

    • Local OCR service

      Using native tesserocR, I tried it, didn’t train it, and the recognition was too bad

    • Online OCR service

      Baidu like only 500 times a day?

      tencent

  4. Baidu (omnipotent 🤷♂️)

In the code
  • Open the mobile phone to enter the answer interface, ⌛️ user key input, automatic screenshots
Import wda import tx_api2 as tx_api c = wda.client () def screenshot(): print(" start screenshot......" ) pic_name = '1.png' c.screenshot(pic_name) tx_api.analysis(pic_name) while True: Input ("****** ⌛️ ⌛ ⌛ ****** ****** ******Copy the code
  • Cut the rectangle of questions and answers
def cut_pic(pic_path, left, upper, right, lower, desc):
    print(desc)
    im = Image.open(pic_path)
    region = im.crop((left, upper, right, lower))  # iPhone 7
    img_byte_arr = io.BytesIO()
    region.save(img_byte_arr, format='PNG')
    image_data = img_byte_arr.getvalue()
    image_data_base64 = base64.b64encode(image_data).decode('ascii')
    return image_data_base64Copy the code
  • OCR recognition (multithreading here for speed)
def ocr(pic_path, left, upper, right, lower, desc): image_data_base64 = cut_pic(pic_path, left, upper, right, lower, desc) return youtu.generalocr(image_data_base64) with futures.ThreadPoolExecutor(max_workers=2) as executor: future_ocr_dict['question'] = executor.submit(ocr, pic_path, 75, 295, 700, 500, '🚕 cut answer rectangle ') future_ocr_dict['question_selection'] = Executor.submit (OCR, pic_path, 130, 600, 620, 1200,'🚕 cut answer rectangle ')Copy the code
  • Baidu 🔍 (use the question ➕ answer to get the most matched record, the same multi-threaded save ⌚️)
def match_count(keyword): path = "http://www.baidu.com/s?tn=ichuner&lm=-1&word={0}&rn=1".format( parse.quote(keyword)) res = request.urlopen(path) Read_line = "search_str =" for line in res.readlines(): line_str = line.decode('utf-8') if (search_str in line_str): Start = line_str. Index (search_str) + 11 line_str = line_str[start:] end = line_str. Index (" ") read_line = line_str[0:end] break read_line = read_line.replace(",", "") return int(read_line) with futures.ThreadPoolExecutor(max_workers=len(items)) as executor: for item in items: Search_str = question_str + item[' itemString '] print("🚥 :{0}". Format (search_str)) future_to_search[item[' itemString ']] = executor.submit(match_count, search_str)Copy the code
  • To get the results
for future_key in future_to_search: cache_search[future_key] = future_to_search[future_key].result() print("match<{0}>:\033[1;31; 40m{1}\33[0m".format(question_str + future_key, STR (cache_search[future_key])) print(' execute with 🔍 completed ') cache_search = sorted(cache_search.items(), key=lambda d: d[1], reverse=True) if(len(cache_search) > 0): Print (" 🎉 🎉 🎉 best answer :\033[1;31; 40m{}\33[0m". Format (next(iter(cache_search))[0])) end_time = time.time() print(" time {0}s" start_time)))Copy the code
The result is 🎉 🎉 🎉


Conclusion: After most of the tests, many answers are ❌. You may still need to use the ElasticSearch item library for an exact match. All right! I still can’t play this 🎮, honest move brick, if have better idea can leave a message.