Răsfoiți Sursa

Merge pull request #1463 from FLAG12321/Quiz_pr

优化答题
huangrunheng 8 luni în urmă
părinte
comite
0b59a6042e

+ 57 - 10
tasks/DemonEncounter/data/answer.py

@@ -23,6 +23,9 @@ class Answer:
     def __init__(self):
     def __init__(self):
         self.data: dict[str, list] = {}
         self.data: dict[str, list] = {}
         self.data_options: dict[str, list] = {}
         self.data_options: dict[str, list] = {}
+        # 添加缓存以确保相同问题的答案一致性
+        # 修改:缓存存储答案字符串而不是索引,避免选项顺序变化的影响
+        self.question_cache: dict[str, str] = {}
         file = str(Path(__file__).parent / 'data.csv')
         file = str(Path(__file__).parent / 'data.csv')
         with open(file, newline='', encoding='utf-8-sig') as csvfile:
         with open(file, newline='', encoding='utf-8-sig') as csvfile:
             reader = csv.reader(csvfile)
             reader = csv.reader(csvfile)
@@ -39,12 +42,26 @@ class Answer:
 
 
     def answer_one(self, question: str, options: list[str]) -> int|None:
     def answer_one(self, question: str, options: list[str]) -> int|None:
         """
         """
-
         每一个问题有三个选项, 返回选项的序号(1、2、3)
         每一个问题有三个选项, 返回选项的序号(1、2、3)
         :param question:
         :param question:
         :param options:
         :param options:
         :return:
         :return:
         """
         """
+        
+        # 检查缓存,如果已经处理过类似问题,直接返回结果
+        # 修改:现在缓存的是答案字符串,需要在选项中查找对应的索引
+        for cached_q, cached_answer_str in self.question_cache.items():
+            similarity = difflib.SequenceMatcher(None, question, cached_q).ratio()
+            if similarity >= 0.9:  # 如果问题相似度超过90%,直接返回缓存的答案
+                # 在当前选项中查找缓存的答案字符串
+                for idx, option in enumerate(options):
+                    if option == cached_answer_str:
+                        return idx + 1  # 返回选项索引(从1开始)
+                # 如果缓存的答案在当前选项中不存在,则尝试模糊匹配
+                for idx, option in enumerate(options):
+                    if difflib.SequenceMatcher(None, option, cached_answer_str).ratio() >= 0.9:
+                        logger.info(f"Fuzzy match cache: '{cached_answer_str}' ~ '{option}'")
+                        return idx + 1
         def decide_by_question_foreach(ques: str, ops: list[str]):
         def decide_by_question_foreach(ques: str, ops: list[str]):
             # 这个是最耗时的操作,遍历数据库中的所有题目,找到最相识的题目和选项
             # 这个是最耗时的操作,遍历数据库中的所有题目,找到最相识的题目和选项
             for key, values in self.data.items():
             for key, values in self.data.items():
@@ -58,7 +75,10 @@ class Answer:
                             logger.warning('The worst case: no match found for question and option')
                             logger.warning('The worst case: no match found for question and option')
                             logger.warning('Now traversing the entire database to find the most similar question and option')
                             logger.warning('Now traversing the entire database to find the most similar question and option')
                             logger.warning(f'Most similar question: {key} and most similar option: {value}')
                             logger.warning(f'Most similar question: {key} and most similar option: {value}')
-                            return index + 1
+                            result_index = index + 1
+                            # 修改:缓存问题和答案字符串
+                            self.question_cache[ques] = ops[index]
+                            return result_index
             return None
             return None
 
 
         def decide_by_options(question: str, ops: list[str]):
         def decide_by_options(question: str, ops: list[str]):
@@ -75,7 +95,10 @@ class Answer:
                 opts = sorted(matches.items(), key=lambda x: x[1], reverse=True)
                 opts = sorted(matches.items(), key=lambda x: x[1], reverse=True)
                 logger.warning('No match found for question,\n Now traversing the entire database to find the most similar question')
                 logger.warning('No match found for question,\n Now traversing the entire database to find the most similar question')
                 logger.warning(f'Most similar answer: {opts[0][0]}, and similarity char number is {opts[0][1]}')
                 logger.warning(f'Most similar answer: {opts[0][0]}, and similarity char number is {opts[0][1]}')
-                return opts[0][0]
+                result_index = opts[0][0]
+                # 修改:缓存问题和答案字符串
+                self.question_cache[question] = ops[result_index - 1]
+                return result_index
             index = decide_by_question_foreach(question, ops)
             index = decide_by_question_foreach(question, ops)
             return index if index else None
             return index if index else None
 
 
@@ -86,7 +109,11 @@ class Answer:
 
 
         for index, option in enumerate(options):
         for index, option in enumerate(options):
             if option == '其余选项皆对':
             if option == '其余选项皆对':
-                return index + 1
+                result_index = index + 1
+                # 特殊选项才缓存
+                # 修改:缓存问题和答案字符串
+                self.question_cache[question] = option
+                return result_index
 
 
         question_matches: list = []
         question_matches: list = []
         try:
         try:
@@ -94,12 +121,17 @@ class Answer:
         except Exception as e:
         except Exception as e:
             # 没有出现题目,从选项反入手
             # 没有出现题目,从选项反入手
             logger.error('Exception: %s', e)
             logger.error('Exception: %s', e)
-            return decide_by_options(question=question, ops=options)
+            result = decide_by_options(question=question, ops=options)
+            if result is not None:
+                # 只有在使用模糊匹配的情况下才缓存结果
+                # 修改:缓存问题和答案字符串
+                self.question_cache[question] = options[result - 1]
+            return result
         # 出现了题目,开始对答案
         # 出现了题目,开始对答案
         for index, option in enumerate(options):
         for index, option in enumerate(options):
             for match in question_matches:
             for match in question_matches:
                 if match == option:
                 if match == option:
-                    return index + 1
+                    return index + 1  # 精确匹配,不缓存,直接返回
         # 可能选项识别某一个字错误
         # 可能选项识别某一个字错误
         if all(options):
         if all(options):
             for index, option in enumerate(options):
             for index, option in enumerate(options):
@@ -108,7 +140,7 @@ class Answer:
                         continue
                         continue
                     if len(match) - count_intersection(match, option) <= 1 :
                     if len(match) - count_intersection(match, option) <= 1 :
                         logger.warning('Option is not match: %s, %s', match, option)
                         logger.warning('Option is not match: %s, %s', match, option)
-                        return index + 1
+                        return index + 1  # 这也是精确匹配的一种,不缓存,直接返回
         # 最保守策略,答案匹配度最高
         # 最保守策略,答案匹配度最高
         opts = {}
         opts = {}
         for index, option in enumerate(options):
         for index, option in enumerate(options):
@@ -122,14 +154,29 @@ class Answer:
         if opts:
         if opts:
             opts = sorted(opts.items(), key=lambda x: x[1], reverse=True)
             opts = sorted(opts.items(), key=lambda x: x[1], reverse=True)
             logger.warning(f'Use SequenceMatcher and get answers: {opts[0][0]}, score: {opts[0][1]}')
             logger.warning(f'Use SequenceMatcher and get answers: {opts[0][0]}, score: {opts[0][1]}')
-            return opts[0][0]
+            result_index = opts[0][0]
+            # 只有在这种情况下才缓存
+            # 修改:缓存问题和答案字符串
+            self.question_cache[question] = options[result_index - 1]
+            return result_index
 
 
         # 选项一个都对不上可能是,正确答案检测为空
         # 选项一个都对不上可能是,正确答案检测为空
         for index, option in enumerate(options):
         for index, option in enumerate(options):
             if option == '':
             if option == '':
                 logger.error('Option is empty: %s', options)
                 logger.error('Option is empty: %s', options)
-                return index + 1
-        return None
+                result_index = index + 1
+                # 只有在这种情况下才缓存
+                # 修改:缓存问题和答案字符串
+                self.question_cache[question] = option
+                return result_index
+                
+        # 如果所有方法都失败,尝试使用decide_by_options
+        result = decide_by_options(question=question, ops=options)
+        if result is not None:
+            # 只有在使用模糊匹配的情况下才缓存结果
+            # 修改:缓存问题和答案字符串
+            self.question_cache[question] = options[result - 1]
+        return result
 
 
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":

+ 12 - 1
tasks/DemonEncounter/data/data.csv

@@ -1646,4 +1646,15 @@ SP阶式神可以通过多少个对应的式神碎片召喚获得,60
 妖刀姬施放满级杀戮时每次转换攻击目标攻击次数会增加几次,2
 妖刀姬施放满级杀戮时每次转换攻击目标攻击次数会增加几次,2
 以下哪位式神的稀有度与其他选项的式神不同,巫蛊师
 以下哪位式神的稀有度与其他选项的式神不同,巫蛊师
 剧情中凤凰火请求晴明将谁从孔雀林中帶走,八百比丘尼
 剧情中凤凰火请求晴明将谁从孔雀林中帶走,八百比丘尼
-通过小动物三花猫可以获得的加成效果是,御魂材料加成
+通过小动物三花猫可以获得的加成效果是,御魂材料加成
+挑战日轮之陨可以获得几种不同种类的御魂,6
+式神觉醒需要什么材料,觉醒材料
+百鬼夜行可以获得什么,式神碎片
+吸血姬的乳名是什么,幸子
+吸血姬讨厌下列哪些东西,阳光
+吸血姬最喜欢的食物是,紫苏牛肉
+蝙蝠是什么种类的动物,哺乳动物
+蝙蝠依靠什么在飞行时定位,超声波
+烬天玉藻前施放焚天九尾进行多少次攻击,12
+跳跳妹妹的特长是,和小动物交流
+以下哪个不是跳跳一家的成员,炒蛋

BIN
tasks/DemonEncounter/data/鬼灭联动活动·题库.xlsx


+ 23 - 10
tasks/Quiz/assets.py

@@ -10,35 +10,48 @@ from module.atom.list import RuleList
 class QuizAssets: 
 class QuizAssets: 
 
 
 
 
+	# Click Rule Assets
+	# description 
+	C_ANSWER_ENSURE_1 = RuleClick(roi_front=(1219,185,21,34), roi_back=(1218,184,23,37), name="answer_ensure_1")
+	# description 
+	C_ANSWER_ENSURE_2 = RuleClick(roi_front=(1223,298,19,26), roi_back=(1222,297,22,29), name="answer_ensure_2")
+	# description 
+	C_ANSWER_ENSURE_3 = RuleClick(roi_front=(1224,414,18,23), roi_back=(1223,413,21,26), name="answer_ensure_3")
+	# description 
+	C_ANSWER_ENSURE_4 = RuleClick(roi_front=(1226,524,13,29), roi_back=(1224,523,15,31), name="answer_ensure_4")
+
+
 	# Image Rule Assets
 	# Image Rule Assets
 	# description 
 	# description 
-	I_ENTRY = RuleImage(roi_front=(143,363,40,128), roi_back=(119,246,100,326), threshold=0.8, method="Template matching", file="./tasks/Quiz/quiz/quiz_entry.png")
+	I_ENTRY = RuleImage(roi_front=(770,373,33,139), roi_back=(745,281,142,329), threshold=0.8, method="Template matching", file="./tasks/Quiz/quiz/entry.png")
 	# 开始 
 	# 开始 
 	I_START = RuleImage(roi_front=(1149,608,66,41), roi_back=(1136,574,100,100), threshold=0.8, method="Template matching", file="./tasks/Quiz/quiz/quiz_start.png")
 	I_START = RuleImage(roi_front=(1149,608,66,41), roi_back=(1136,574,100,100), threshold=0.8, method="Template matching", file="./tasks/Quiz/quiz/quiz_start.png")
 	# 标志 
 	# 标志 
-	I_MESSAGE = RuleImage(roi_front=(75,488,58,41), roi_back=(50,460,100,100), threshold=0.8, method="Template matching", file="./tasks/Quiz/quiz/quiz_message.png")
+	I_MESSAGE = RuleImage(roi_front=(73,483,53,46), roi_back=(51,450,170,136), threshold=0.8, method="Template matching", file="./tasks/Quiz/quiz/message.png")
 	# 失败然后离开 
 	# 失败然后离开 
-	I_FAIL_QUIT = RuleImage(roi_front=(416,529,183,45), roi_back=(354,502,275,100), threshold=0.8, method="Template matching", file="./tasks/Quiz/quiz/quiz_fail_quit.png")
+	I_FAIL_QUIT = RuleImage(roi_front=(612,534,67,31), roi_back=(375,484,524,163), threshold=0.8, method="Template matching", file="./tasks/Quiz/quiz/fail_quit.png")
 	# 结算分享 
 	# 结算分享 
 	I_SHARE = RuleImage(roi_front=(1171,625,53,44), roi_back=(1152,592,100,100), threshold=0.8, method="Template matching", file="./tasks/Quiz/quiz/quiz_share.png")
 	I_SHARE = RuleImage(roi_front=(1171,625,53,44), roi_back=(1152,592,100,100), threshold=0.8, method="Template matching", file="./tasks/Quiz/quiz/quiz_share.png")
+	# description 
+	I_ALONE_ENSURE = RuleImage(roi_front=(1216,405,30,41), roi_back=(1138,148,140,435), threshold=0.7, method="Template matching", file="./tasks/Quiz/quiz/alone_ensure.png")
 
 
 
 
 	# Ocr Rule Assets
 	# Ocr Rule Assets
 	# Ocr-description 
 	# Ocr-description 
-	O_QUESTION = RuleOcr(roi=(903,32,322,101), area=(903,32,322,101), mode="Single", method="Default", keyword="", name="question")
+	O_QUESTION = RuleOcr(roi=(903,32,322,101), area=(0,0,100,100), mode="Full", method="Default", keyword="", name="question")
 	# Ocr-description 
 	# Ocr-description 
-	O_ANSWER1 = RuleOcr(roi=(906,178,320,53), area=(906,178,320,53), mode="Single", method="Default", keyword="", name="answer1")
+	O_ANSWER1 = RuleOcr(roi=(951,188,228,31), area=(949,187,231,34), mode="Single", method="Default", keyword="", name="answer1")
 	# Ocr-description 
 	# Ocr-description 
-	O_ANSWER2 = RuleOcr(roi=(905,289,319,51), area=(905,289,319,51), mode="Single", method="Default", keyword="", name="answer2")
+	O_ANSWER2 = RuleOcr(roi=(960,301,208,26), area=(959,300,211,29), mode="Single", method="Default", keyword="", name="answer2")
 	# Ocr-description 
 	# Ocr-description 
-	O_ANSWER3 = RuleOcr(roi=(906,399,320,55), area=(906,399,320,55), mode="Single", method="Default", keyword="", name="answer3")
+	O_ANSWER3 = RuleOcr(roi=(955,417,228,26), area=(953,415,231,29), mode="Single", method="Default", keyword="", name="answer3")
 	# Ocr-description 
 	# Ocr-description 
-	O_ANSWER4 = RuleOcr(roi=(909,511,316,54), area=(909,511,316,54), mode="Single", method="Default", keyword="", name="answer4")
+	O_ANSWER4 = RuleOcr(roi=(964,527,208,23), area=(963,526,211,26), mode="Single", method="Default", keyword="", name="answer4")
 	# 倒计时 
 	# 倒计时 
-	O_COUNTDOWN = RuleOcr(roi=(1045,6,27,30), area=(1045,6,27,30), mode="Digit", method="Default", keyword="4", name="countdown")
+	O_COUNTDOWN = RuleOcr(roi=(1030,9,61,25), area=(1029,7,63,27), mode="Digit", method="Default", keyword="4", name="countdown")
 	# 倒计时 
 	# 倒计时 
 	O_COUNTDOWN3 = RuleOcr(roi=(1045,6,27,30), area=(1045,6,27,30), mode="Digit", method="Default", keyword="3", name="countdown3")
 	O_COUNTDOWN3 = RuleOcr(roi=(1045,6,27,30), area=(1045,6,27,30), mode="Digit", method="Default", keyword="3", name="countdown3")
 	# Ocr-description 
 	# Ocr-description 
-	O_QUESTION_AND_ANSWER = RuleOcr(roi=(902,34,325,534), area=(902,34,325,534), mode="Full", method="Default", keyword="", name="question_and_answer")
+	O_QUESTION_AND_ANSWER = RuleOcr(roi=(902,34,325,534), area=(0,0,100,100), mode="Full", method="Default", keyword="", name="question_and_answer")
 
 
 
 

BIN
tasks/Quiz/quiz/alone_ensure.png


+ 26 - 0
tasks/Quiz/quiz/click.json

@@ -0,0 +1,26 @@
+[
+  {
+    "itemName": "answer_ensure_1",
+    "roiFront": "1219,185,21,34",
+    "roiBack": "1218,184,23,37",
+    "description": "description"
+  },
+  {
+    "itemName": "answer_ensure_2",
+    "roiFront": "1223,298,19,26",
+    "roiBack": "1222,297,22,29",
+    "description": "description"
+  },
+  {
+    "itemName": "answer_ensure_3",
+    "roiFront": "1224,414,18,23",
+    "roiBack": "1223,413,21,26",
+    "description": "description"
+  },
+  {
+    "itemName": "answer_ensure_4",
+    "roiFront": "1226,524,13,29",
+    "roiBack": "1224,523,15,31",
+    "description": "description"
+  }
+]

BIN
tasks/Quiz/quiz/entry.png


BIN
tasks/Quiz/quiz/fail_quit.png


+ 27 - 9
tasks/Quiz/quiz/image.json

@@ -1,9 +1,9 @@
 [
 [
   {
   {
     "itemName": "entry",
     "itemName": "entry",
-    "imageName": "quiz_entry.png",
-    "roiFront": "143,363,40,128",
-    "roiBack": "119,246,100,326",
+    "imageName": "entry.png",
+    "roiFront": "770,373,33,139",
+    "roiBack": "745,281,142,329",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "description"
     "description": "description"
@@ -19,18 +19,18 @@
   },
   },
   {
   {
     "itemName": "message",
     "itemName": "message",
-    "imageName": "quiz_message.png",
-    "roiFront": "75,488,58,41",
-    "roiBack": "50,460,100,100",
+    "imageName": "message.png",
+    "roiFront": "73,483,53,46",
+    "roiBack": "51,450,170,136",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "标志"
     "description": "标志"
   },
   },
   {
   {
     "itemName": "fail_quit",
     "itemName": "fail_quit",
-    "imageName": "quiz_fail_quit.png",
-    "roiFront": "416,529,183,45",
-    "roiBack": "354,502,275,100",
+    "imageName": "fail_quit.png",
+    "roiFront": "612,534,67,31",
+    "roiBack": "375,484,524,163",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "失败然后离开"
     "description": "失败然后离开"
@@ -43,5 +43,23 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "结算分享"
     "description": "结算分享"
+  },
+  {
+    "itemName": "alone_ensure",
+    "roiFront": "1216,405,30,41",
+    "roiBack": "1138,148,140,435",
+    "description": "description",
+    "imageName": "alone_ensure.png",
+    "method": "Template matching",
+    "threshold": "0.7"
+  },
+  {
+    "itemName": "alone_ensure_2",
+    "roiFront": "1215,294,22,30",
+    "roiBack": "1167,162,107,427",
+    "description": "description",
+    "imageName": "alone_ensure_2.png",
+    "method": "Template matching",
+    "threshold": "0.7"
   }
   }
 ]
 ]

BIN
tasks/Quiz/quiz/message.png


+ 13 - 13
tasks/Quiz/quiz/ocr.json

@@ -2,16 +2,16 @@
   {
   {
     "itemName": "question",
     "itemName": "question",
     "roiFront": "903,32,322,101",
     "roiFront": "903,32,322,101",
-    "roiBack": "903,32,322,101",
-    "mode": "Single",
+    "roiBack": "0,0,100,100",
+    "mode": "Full",
     "method": "Default",
     "method": "Default",
     "keyword": "",
     "keyword": "",
     "description": "Ocr-description"
     "description": "Ocr-description"
   },
   },
   {
   {
     "itemName": "answer1",
     "itemName": "answer1",
-    "roiFront": "906,178,320,53",
-    "roiBack": "906,178,320,53",
+    "roiFront": "951,188,228,31",
+    "roiBack": "949,187,231,34",
     "mode": "Single",
     "mode": "Single",
     "method": "Default",
     "method": "Default",
     "keyword": "",
     "keyword": "",
@@ -19,8 +19,8 @@
   },
   },
   {
   {
     "itemName": "answer2",
     "itemName": "answer2",
-    "roiFront": "905,289,319,51",
-    "roiBack": "905,289,319,51",
+    "roiFront": "960,301,208,26",
+    "roiBack": "959,300,211,29",
     "mode": "Single",
     "mode": "Single",
     "method": "Default",
     "method": "Default",
     "keyword": "",
     "keyword": "",
@@ -28,8 +28,8 @@
   },
   },
   {
   {
     "itemName": "answer3",
     "itemName": "answer3",
-    "roiFront": "906,399,320,55",
-    "roiBack": "906,399,320,55",
+    "roiFront": "955,417,228,26",
+    "roiBack": "953,415,231,29",
     "mode": "Single",
     "mode": "Single",
     "method": "Default",
     "method": "Default",
     "keyword": "",
     "keyword": "",
@@ -37,8 +37,8 @@
   },
   },
   {
   {
     "itemName": "answer4",
     "itemName": "answer4",
-    "roiFront": "909,511,316,54",
-    "roiBack": "909,511,316,54",
+    "roiFront": "964,527,208,23",
+    "roiBack": "963,526,211,26",
     "mode": "Single",
     "mode": "Single",
     "method": "Default",
     "method": "Default",
     "keyword": "",
     "keyword": "",
@@ -46,8 +46,8 @@
   },
   },
   {
   {
     "itemName": "countdown",
     "itemName": "countdown",
-    "roiFront": "1045,6,27,30",
-    "roiBack": "1045,6,27,30",
+    "roiFront": "1030,9,61,25",
+    "roiBack": "1029,7,63,27",
     "mode": "Digit",
     "mode": "Digit",
     "method": "Default",
     "method": "Default",
     "keyword": "4",
     "keyword": "4",
@@ -65,7 +65,7 @@
   {
   {
     "itemName": "question_and_answer",
     "itemName": "question_and_answer",
     "roiFront": "902,34,325,534",
     "roiFront": "902,34,325,534",
-    "roiBack": "902,34,325,534",
+    "roiBack": "0,0,100,100",
     "mode": "Full",
     "mode": "Full",
     "method": "Default",
     "method": "Default",
     "keyword": "",
     "keyword": "",

BIN
tasks/Quiz/quiz/quiz_entry.png


BIN
tasks/Quiz/quiz/quiz_fail_quit.png


BIN
tasks/Quiz/quiz/quiz_message.png


BIN
tasks/Quiz/quiz/quiz_share.png


BIN
tasks/Quiz/quiz/quiz_start.png


+ 65 - 20
tasks/Quiz/script_task.py

@@ -2,6 +2,7 @@
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
 import random
 import random
+import time
 from cached_property import cached_property
 from cached_property import cached_property
 
 
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.game_ui import GameUi
@@ -17,6 +18,7 @@ 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
+from module.device.screenshot import Screenshot
 
 
 class NoTicket(Exception):
 class NoTicket(Exception):
     pass
     pass
@@ -28,6 +30,9 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
     last_select_2 = ''
     last_select_2 = ''
     last_select_3 = ''
     last_select_3 = ''
     last_select_4 = ''
     last_select_4 = ''
+    # 添加倒计时状态变量
+    last_countdown = None
+    runalone = False
 
 
     @cached_property
     @cached_property
     def anwser(self) -> Answer:
     def anwser(self) -> Answer:
@@ -77,6 +82,8 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
         logger.hr('Quiz', 3)
         logger.hr('Quiz', 3)
         start_cnt = 0
         start_cnt = 0
         self.answer_cnt = 0
         self.answer_cnt = 0
+        # 重置倒计时状态
+        self.last_countdown = None
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
             if self.appear(self.I_MESSAGE):
             if self.appear(self.I_MESSAGE):
@@ -113,28 +120,54 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
         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:
-        new = True if self.last_select_1 != select_1 or \
-                self.last_select_2 != select_2 or \
-                self.last_select_3 != select_3 or \
-                self.last_select_4 != select_4 else False
+        # 计算不同答案的数量
+        diff_count = 0
+        if self.last_select_1 != select_1:
+            diff_count += 1
+        if self.last_select_2 != select_2:
+            diff_count += 1
+        if self.last_select_3 != select_3:
+            diff_count += 1
+        if self.last_select_4 != select_4:
+            diff_count += 1
+            
+        # 如果有3个或以上答案不同,则认为是新问题
+        new = diff_count >= 3
+        
         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 = \
             select_1, select_2, select_3, select_4
             select_1, select_2, select_3, select_4
         return new
         return new
 
 
     def _deal_quiz(self):
     def _deal_quiz(self):
         countdown = self.O_COUNTDOWN.ocr(self.device.image)
         countdown = self.O_COUNTDOWN.ocr(self.device.image)
-        if countdown < 2 or countdown > 5:
-            # 最后两秒钟的时候 进行选择
+        
+        """  # 检查倒计时状态变化:从大于0变为0时进入下一题
+        if self.last_countdown is not None and self.last_countdown > 0 and countdown == 0:
+            logger.info("Countdown changed from greater than 0 to 0, moving to next question")
             return False
             return False
+        
+        self.last_countdown = countdown """
+        
+        if countdown <1 or countdown > 3:
+            # 最后两秒钟的时候 进行选择
+            if countdown >100:
+                self.runalone = True
+            else:
+                return False
+
         question, answer_1, answer_2, answer_3, answer_4 = self.detect_question_and_answers()
         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)
         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 new_question:
-            self.answer_cnt += 1
-            logger.info(f'Question count: {self.answer_cnt}')
+        if not new_question:
+            if self.runalone:
+                self.appear_then_click(self.I_ALONE_ENSURE, interval=1)
+                pass
+            return False
+        self.answer_cnt += 1
+        logger.info(f'Question count: {self.answer_cnt}')
 
 
         # questions = self.O_QUESTION.detect_and_ocr(self.device.image)
         # questions = self.O_QUESTION.detect_and_ocr(self.device.image)
         # question = ''.join([q.ocr_text for q in questions])
         # question = ''.join([q.ocr_text for q in questions])
@@ -153,18 +186,38 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
             index_options = {1, 2, 3, 4}
             index_options = {1, 2, 3, 4}
             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}{[answer_1, answer_2, answer_3, answer_4]}')
         self.click(self.click_options[index-1], interval=1)
         self.click(self.click_options[index-1], interval=1)
+        time.sleep(0.5)
+        if index == 1:
+            self.click(self.C_ANSWER_ENSURE_1)
+        if index == 2:
+            self.click(self.C_ANSWER_ENSURE_2)
+        if index == 3:
+            self.click(self.C_ANSWER_ENSURE_3)
+        if index == 4:
+            self.click(self.C_ANSWER_ENSURE_4)
         self.device.click_record_clear()
         self.device.click_record_clear()
         return True
         return True
 
 
     def detect_question_and_answers(self) -> tuple:
     def detect_question_and_answers(self) -> tuple:
-        results = self.O_QUESTION_AND_ANSWER.detect_and_ocr(self.device.image)
+        results = self.O_QUESTION.detect_and_ocr(self.device.image)
         question = ''
         question = ''
         answer_1 = ''
         answer_1 = ''
         answer_2 = ''
         answer_2 = ''
         answer_3 = ''
         answer_3 = ''
         answer_4 = ''
         answer_4 = ''
+        answer_1 = self.O_ANSWER1.ocr(self.device.image)
+        answer_2 = self.O_ANSWER2.ocr(self.device.image)
+        answer_3 = self.O_ANSWER3.ocr(self.device.image)
+        answer_4 = self.O_ANSWER4.ocr(self.device.image)    
+        
+        # 过滤answer中的符号'.', '''
+        answer_1 = answer_1.replace('.', '').replace("'", '').replace(':', '').replace(' ', '') if answer_1 else ''
+        answer_2 = answer_2.replace('.', '').replace("'", '').replace(':', '').replace(' ', '') if answer_2 else ''
+        answer_3 = answer_3.replace('.', '').replace("'", '').replace(':', '').replace(' ', '') if answer_3 else ''
+        answer_4 = answer_4.replace('.', '').replace("'", '').replace(':', '').replace(' ', '') if answer_4 else ''
+        
         for result in results:
         for result in results:
             # box 是四个点坐标 左上, 右上, 右下, 左下
             # box 是四个点坐标 左上, 右上, 右下, 左下
             # x1, y1, x2, y2 = result.box[0][0], result.box[0][1], result.box[2][0], result.box[2][1]
             # x1, y1, x2, y2 = result.box[0][0], result.box[0][1], result.box[2][0], result.box[2][1]
@@ -174,21 +227,13 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
             text = result.ocr_text
             text = result.ocr_text
             if y_start >= 0 and y_end <= 150:
             if y_start >= 0 and y_end <= 150:
                 question += text
                 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
         return question, answer_1, answer_2, answer_3, answer_4
 
 
 
 
 
 
 
 
 
 
-
 if __name__ == '__main__':
 if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config
     from module.device.device import Device
     from module.device.device import Device