|
@@ -13,6 +13,7 @@ from tasks.Quiz.debug import Debugger, remove_symbols
|
|
|
|
|
|
|
|
from module.logger import logger
|
|
from module.logger import logger
|
|
|
from module.exception import TaskEnd
|
|
from module.exception import TaskEnd
|
|
|
|
|
+from module.base.timer import Timer
|
|
|
from module.atom.image_grid import ImageGrid
|
|
from module.atom.image_grid import ImageGrid
|
|
|
from module.atom.image import RuleImage
|
|
from module.atom.image import RuleImage
|
|
|
from module.atom.click import RuleClick
|
|
from module.atom.click import RuleClick
|
|
@@ -88,6 +89,8 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
|
|
|
continue
|
|
continue
|
|
|
self.last_select_1, self.last_select_2, self.last_select_3, self.last_select_4 = '', '', '', ''
|
|
self.last_select_1, self.last_select_2, self.last_select_3, self.last_select_4 = '', '', '', ''
|
|
|
|
|
|
|
|
|
|
+ quiz_timer = Timer(1.4)
|
|
|
|
|
+ quiz_timer.start()
|
|
|
while 1:
|
|
while 1:
|
|
|
self.screenshot()
|
|
self.screenshot()
|
|
|
|
|
|
|
@@ -103,40 +106,40 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
|
|
|
logger.info('Quiz Victory and exit')
|
|
logger.info('Quiz Victory and exit')
|
|
|
self.ui_click(self.I_UI_BACK_RED, self.I_START)
|
|
self.ui_click(self.I_UI_BACK_RED, self.I_START)
|
|
|
break
|
|
break
|
|
|
- self._deal_quiz()
|
|
|
|
|
|
|
+ if quiz_timer.reached():
|
|
|
|
|
+ quiz_timer.reset()
|
|
|
|
|
+ self._deal_quiz()
|
|
|
|
|
+ continue
|
|
|
self.close_fn()
|
|
self.close_fn()
|
|
|
|
|
|
|
|
def detect_new(self, select_1, select_2, select_3, select_4) -> bool:
|
|
def detect_new(self, select_1, select_2, select_3, select_4) -> bool:
|
|
|
- if self.last_select_1 != select_1 or \
|
|
|
|
|
|
|
+ new = True if self.last_select_1 != select_1 or \
|
|
|
self.last_select_2 != select_2 or \
|
|
self.last_select_2 != select_2 or \
|
|
|
self.last_select_3 != select_3 or \
|
|
self.last_select_3 != select_3 or \
|
|
|
- self.last_select_4 != select_4:
|
|
|
|
|
- return True
|
|
|
|
|
- return False
|
|
|
|
|
|
|
+ self.last_select_4 != select_4 else False
|
|
|
|
|
+ self.last_select_1, self.last_select_2, self.last_select_3, self.last_select_4 = \
|
|
|
|
|
+ select_1, select_2, select_3, select_4
|
|
|
|
|
+ return new
|
|
|
|
|
|
|
|
def _deal_quiz(self):
|
|
def _deal_quiz(self):
|
|
|
- answer_1 = self.O_ANSWER1.detect_text(self.device.image)
|
|
|
|
|
- answer_2 = self.O_ANSWER2.detect_text(self.device.image)
|
|
|
|
|
- answer_3 = self.O_ANSWER3.detect_text(self.device.image)
|
|
|
|
|
- answer_4 = self.O_ANSWER4.detect_text(self.device.image)
|
|
|
|
|
|
|
+ countdown = self.O_COUNTDOWN.ocr(self.device.image)
|
|
|
|
|
+ if countdown < 2 or countdown > 5:
|
|
|
|
|
+ # 最后两秒钟的时候 进行选择
|
|
|
|
|
+ return False
|
|
|
|
|
+ question, answer_1, answer_2, answer_3, answer_4 = self.detect_question_and_answers()
|
|
|
if answer_1 == '' and answer_2 == '' and answer_3 == '' and answer_4 == '':
|
|
if answer_1 == '' and answer_2 == '' and answer_3 == '' and answer_4 == '':
|
|
|
return False
|
|
return False
|
|
|
|
|
+ question = remove_symbols(question)
|
|
|
|
|
+
|
|
|
new_question = self.detect_new(answer_1, answer_2, answer_3, answer_4)
|
|
new_question = self.detect_new(answer_1, answer_2, answer_3, answer_4)
|
|
|
- if not new_question and\
|
|
|
|
|
- not self.ocr_appear(self.O_COUNTDOWN) and\
|
|
|
|
|
- not self.ocr_appear(self.O_COUNTDOWN3):
|
|
|
|
|
- # 第一次换题目的时候 和 最后两秒钟的时候 进行选择
|
|
|
|
|
- return False
|
|
|
|
|
if new_question:
|
|
if new_question:
|
|
|
self.answer_cnt += 1
|
|
self.answer_cnt += 1
|
|
|
logger.info(f'Question count: {self.answer_cnt}')
|
|
logger.info(f'Question count: {self.answer_cnt}')
|
|
|
|
|
|
|
|
- self.last_select_1, self.last_select_2, self.last_select_3, self.last_select_4 = \
|
|
|
|
|
- answer_1, answer_2, answer_3, answer_4
|
|
|
|
|
- questions = self.O_QUESTION.detect_and_ocr(self.device.image)
|
|
|
|
|
- question = ''.join([q.ocr_text for q in questions])
|
|
|
|
|
- question = question.replace('?', '').replace('?', '').replace(' ', '').replace(',', ',')
|
|
|
|
|
- question = remove_symbols(question)
|
|
|
|
|
|
|
+ # questions = self.O_QUESTION.detect_and_ocr(self.device.image)
|
|
|
|
|
+ # question = ''.join([q.ocr_text for q in questions])
|
|
|
|
|
+ # question = question.replace('?', '').replace('?', '').replace(' ', '').replace(',', ',')
|
|
|
|
|
+ # question = remove_symbols(question)
|
|
|
|
|
|
|
|
index = self.anwser.answer_one(question=question, options=[answer_1, answer_2, answer_3, answer_4])
|
|
index = self.anwser.answer_one(question=question, options=[answer_1, answer_2, answer_3, answer_4])
|
|
|
if index is None:
|
|
if index is None:
|
|
@@ -151,11 +154,35 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
|
|
|
index_options.remove(index)
|
|
index_options.remove(index)
|
|
|
index = random.choice(list(index_options))
|
|
index = random.choice(list(index_options))
|
|
|
logger.info(f'Question: {question}, Answer: {index}')
|
|
logger.info(f'Question: {question}, Answer: {index}')
|
|
|
- self.click(self.click_options[index-1])
|
|
|
|
|
|
|
+ self.click(self.click_options[index-1], interval=1)
|
|
|
self.device.click_record_clear()
|
|
self.device.click_record_clear()
|
|
|
return True
|
|
return True
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ def detect_question_and_answers(self) -> tuple:
|
|
|
|
|
+ results = self.O_QUESTION_AND_ANSWER.detect_and_ocr(self.device.image)
|
|
|
|
|
+ question = ''
|
|
|
|
|
+ answer_1 = ''
|
|
|
|
|
+ answer_2 = ''
|
|
|
|
|
+ answer_3 = ''
|
|
|
|
|
+ answer_4 = ''
|
|
|
|
|
+ for result in results:
|
|
|
|
|
+ # box 是四个点坐标 左上, 右上, 右下, 左下
|
|
|
|
|
+ # x1, y1, x2, y2 = result.box[0][0], result.box[0][1], result.box[2][0], result.box[2][1]
|
|
|
|
|
+ # w, h = x2 - x1, y2 - y1
|
|
|
|
|
+ y_start = result.box[0][1]
|
|
|
|
|
+ y_end = result.box[2][1]
|
|
|
|
|
+ text = result.ocr_text
|
|
|
|
|
+ if y_start >= 0 and y_end <= 150:
|
|
|
|
|
+ question += text
|
|
|
|
|
+ elif y_start > 150 and y_end <= 240:
|
|
|
|
|
+ answer_1 += text
|
|
|
|
|
+ elif y_start > 240 and y_end <= 370:
|
|
|
|
|
+ answer_2 += text
|
|
|
|
|
+ elif y_start > 370 and y_end <= 470:
|
|
|
|
|
+ answer_3 += text
|
|
|
|
|
+ elif y_start > 470 and y_end <= 600:
|
|
|
|
|
+ answer_4 += text
|
|
|
|
|
+ return question, answer_1, answer_2, answer_3, answer_4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|