forked from whhxmwhh/auto-xxqg
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquestionCommon.js
1297 lines (1219 loc) · 57.3 KB
/
questionCommon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var tikuCommonZsy = require("./tikuCommon-zsy.js");
var tikuCommon = require("./tikuCommon.js");
storage = storages.create("data");
var delaytime1 = storage.get("questionAswerLowSpeed", 520);
var delaytime2 = storage.get("questionAswerHighSpeed", 620);
var delaytime3 = storage.get("questionAswerAddSpeed", 1000);
var delaytime3 = Number(delaytime3);
delaytime2 = Number(delaytime2);
delaytime1 = Number(delaytime1);
var oldaquestion; //四人赛(争上游)和对战答题循环,定义旧题目对比新题目用20201022
var ZiXingArray = ["选择词语的正确词形。", "选择正确的读音。", "下列不属于二十四史的是。", "下列不属于“十三经”的是。", "下列说法正确的是。", "下列词形正确的是。", "下列读音正确的是。", ];
//特殊题,特点:题目一样,答案不同
var chutiIndexArray = ["(出题:", "(出题单位:", "推荐单位:", "出题:", "来源:《", "(来源:", "来源:", "(推荐:", "推荐:"]; //去除题目中尾巴(非题目内容)
var opabcd = ["A", "B", "C", "D"];
var oU = storage.get('oU', 'http://127.0.0.1:34567');
//var qCount = random(5, 7);//挑战答题每轮答题数(5~7随机)
/*************************************************公共部分******************************************************/
/**
* @description: 延时函数
* @param: seconds-延迟秒数
* @return: null
*/
function delay(seconds) {
sleep(1000 * seconds); //sleep函数参数单位为毫秒所以乘1000
}
/**
* @description: 生成从minNum到maxNum的随机数
* @param: minNum-较小的数
* @param: maxNum-较大的数
* @return: null
*/
function randomNum(minNum, maxNum) {
switch (arguments.length) {
case 1:
return parseInt(Math.random() * minNum + 1, 10);
case 2:
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
default:
return 0;
}
}
/**
* @description: 返回字段首字母序号
* @param: str
* @return: int 字母序号
*/
function indexFromChar(str) {
return str.charCodeAt(0) - "A".charCodeAt(0);
}
/**
* @description: 返回字段首字母
* @param: int 字母序号
* @return: str
*/
function charFromIndex(int) {
return String.fromCharCode("A".charCodeAt(0) + int);
}
/*************************************************挑战答题部分******************************************************/
/**
* @description: 答错后查找正确答案
* @param: delayTime, myColor, myThreshold, listArray, options
* @return: correctAns 正确答案
*/
function findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options) {
console.hide(); //隐藏console控制台窗口
sleep(delayTime); //等待截屏
var img = captureScreen(); //截个屏
// let imgName = "/sdcard/好好学习/ddd" + new Date().getTime() + ".png";
// let imgName = "/sdcard/好好学习/ddd.png";
// captureScreen(imgName);//截个屏
// var img = images.read(imgName);
// toastLog(imgName);
console.show(); //显示console控制台窗口
//delay(3);
// 查找绿色答案#f24650
var correctAns = new Array();
listArray.some(item => {
var listBounds = item.bounds();
// console.log(listBounds);
var point = findColor(img, myColor, {
region: [listBounds.left, listBounds.top, listBounds.right - listBounds.left, listBounds.bottom - listBounds.top],
threshold: myThreshold
});
if (point) {
correctAns.push(options[listArray.indexOf(item)]);
correctAns.push(charFromIndex(listArray.indexOf(item)));
toastLog(correctAns);
return true;
} else {
// console.log("没找到");
}
});
return correctAns;
}
/**
* @description: 每次答题循环
* @param: conNum 连续答对的次数
* @return: null
*/
function challengeQuestionLoop(conNum, qCount) {
delaytime4 = randomNum(delaytime1 + delaytime3, delaytime2 + delaytime3) //随机延迟增加设定毫秒数
console.log("延时:" + delaytime4);
sleep(delaytime4);
if (conNum >= qCount) //答题次数足够退出,每轮5次
{
let listArray = className("ListView").findOnce().children(); //题目选项列表
let i = random(0, listArray.length - 1);
console.log("本轮次数足够,随机点击一个答案,答错进入下一轮");
listArray[i].child(0).click(); //随意点击一个答案
console.log("----------------------------------");
return;
}
if (className("ListView").exists()) {
var question = className("ListView").findOnce().parent().child(0).text();
console.log((conNum + 1).toString() + ".题目:" + question);
} else {
console.error("提取题目失败!");
let listArray = className("ListView").findOnce().children(); //题目选项列表
let i = random(0, listArray.length - 1);
console.log("随机点击一个");
listArray[i].child(0).click(); //随意点击一个答案
return;
}
var chutiIndex = question.lastIndexOf("出题单位");
if (chutiIndex != -1) {
question = question.substring(0, chutiIndex - 2);
}
question = question.replace(/\s/g, "");
var options = []; //选项列表
if (className("ListView").exists()) {
className("ListView").findOne().children().forEach(child => {
var answer_q = child.child(0).child(1).text();
options.push(answer_q);
});
} else {
console.error("答案获取失败!");
return;
}
//特殊情况外理
ZiXingArray.forEach(item => { //特殊题目+来源
if (question.indexOf(item) > -1) {
question = question + options[0];
}
});
var answer = tikuCommon.getAnswer(question, 'tiku');
/* if (answer.length == 0) { //tiku表中没有则到tikuNet表中搜索答案
answer = getAnswer(question, 'tikuNet');
} */
if (/^[a-zA-Z]{1}$/.test(answer)) { //如果为ABCD形式
var indexAnsTiku = indexFromChar(answer.toUpperCase());
answer = options[indexAnsTiku];
toastLog("answer from char=" + answer);
}
let hasClicked = false;
var listArray = className("ListView").findOnce().children(); //题目选项列表
if ((answer == "") || !textEndsWith(answer).exists()) //如果没找到答案
{
let i = random(0, listArray.length - 1);
console.error("没有找到答案,随机点击一个");
listArray[i].child(0).click(); //随意点击一个答案
var delayTime = 120;
var myColor = "#44BF78";
var myThreshold = 4;
var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
console.info("正确答案是:" + correctAns[0]);
hasClicked = true;
// 更新题库
// delay(1);
if (correctAns == "" || correctAns == null || correctAns == undefined) //如果答案不是null,就更新题库
{
console.error("没有准确得到答案,跳过更新题库。");
} else {
if (answer == "") {
var sql = "INSERT INTO tiku (question, option, answer, wrongAnswer) VALUES ('" + question + "','" + correctAns[1] + "','" + correctAns[0] + "','')";
} else {
var sql = "UPDATE tiku SET answer='" + correctAns[0] + "' option='" + correctAns[1] + "' WHERE question LIKE '" + question + "'";
}
// console.log(correctAns);
tikuCommon.insertOrUpdate(sql);
console.log("更新题库答案...");
updateToServer(question, correctAns[0]);
}
} else //如果找到了答案
{
/* listArray.some(item => {
var listDescStr = item.child(0).child(1).text();
console.error(deleteNO(listDescStr));
if (deleteNO(listDescStr) == answer) {
item.child(0).click(); //点击答案
hasClicked = true;
rightCount++;
console.log("-------------------------------");
return true;
}
}); */
console.info("答案:" + answer);
var optletters = charFromIndex(options.indexOf(answer));
// toastLog(optletters);
var sql = "UPDATE tiku SET option='" + optletters + "' WHERE question LIKE '" + question + "'";
tikuCommon.insertOrUpdate(sql);
// console.log("更新题库答案...");
text(answer).click();
hasClicked = true;
console.log("-------------------------------");
/* var delayTime = 120;
var myColor = "#44BF78";
var myThreshold = 4;
var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
delay(1);
if (text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
"RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists()) //遇到❌号,则答错了,不再通过结束本局字样判断
{
// var sql = "DELETE FROM tiku WHERE question = '" + question + "'";
// tikuCommon.insertOrUpdate(sql);
// toastLog("答案有误,删除此题!");
console.info("正确答案是:" + correctAns);
let sql = "UPDATE tiku SET answer='" + correctAns + "' WHERE question LIKE '" + question + "'";
tikuCommon.tikuCommon.insertOrUpdate(sql);
toastLog("答案有误,已更正答案!");
} */
}
if (!hasClicked) //如果没有点击成功
{
console.error("未能成功点击,随机点击一个");
let i = random(0, listArray.length - 1);
listArray[i].child(0).click(); //随意点击一个答案
console.log("-------------------------------");
}
}
/*************************************************挑战答题部分 2021.4.28新循环***************************************************/
/**
* @description: 挑战答题循环
* @param: conNum 连续答对的次数
* @return: null
*/
function challengeQuestionLoopnew(conNum) {
try {
let ClickAnswer; //定义已点击答案
if (conNum >= qCount) //答题次数足够退出,每轮qCount=5+随机1-3次
{
let listArray = className("ListView").findOnce().children(); //题目选项列表
let i = random(0, listArray.length - 1);
console.log("本轮答题数足够,随机点击答案");
var question = className("ListView").findOnce().parent().child(0).text();
question = question.replace(/\s/g, "");
var options = []; //选项列表
if (className("ListView").exists()) {
className("ListView").findOne().children().forEach(child => {
var answer_q = child.child(0).child(1).text();
options.push(answer_q);
});
} else {
console.error("答案获取失败!");
return;
} //20201217添加 极低概率下,答题数足够,下一题随机点击,碰到字形题
ZiXingArray.forEach(item => { //特殊题目+来源
if (question.indexOf(item) > -1) {
question = question + options[0];
}
});
console.log((conNum + 1).toString() + ".随机点击题目:" + question);
delay(random(0.5, 1)); //随机延时0.5-1秒
listArray[i].child(0).click(); //随意点击一个答案
ClickAnswer = listArray[i].child(0).child(1).text();; //记录已点击答案
console.log("随机点击:" + ClickAnswer);
//如果随机点击答案正确,则更新到本地题库tiku表
delay(0.5); //等待0.5秒,是否出现X
if (!text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
"RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists() || text("再来一局").exists()) //遇到❌号,则答错了,不再通过结束本局字样判断
{
console.log("更新本地题库答案...");
checkAndUpdate(question, answer, ClickAnswer);
updateToServer(question, answer);
}
console.log("-------------");
return;
}
if (className("ListView").exists()) {
var question = className("ListView").findOnce().parent().child(0).text();
} else {
console.error("提取题目失败!");
let listArray = className("ListView").findOnce().children(); //题目选项列表
let i = random(0, listArray.length - 1);
console.log("随机点击");
delay(random(0.5, 1)); //随机延时0.5-1秒
listArray[i].child(0).click(); //随意点击一个答案
return;
}
var chutiIndex = question.lastIndexOf("出题单位");
if (chutiIndex != -1) {
question = question.substring(0, chutiIndex - 2);
}
question = question.replace(/\s/g, "");
var options = []; //选项列表
if (className("ListView").exists()) {
className("ListView").findOne().children().forEach(child => {
var answer_q = child.child(0).child(1).text();
options.push(answer_q);
});
} else {
console.error("答案获取失败!");
return;
}
// if (question == ZiXingTi.replace(/\s/g, "") || question == DuYinTi.replace(/\s/g, "") || question == ErShiSiShi.replace(/\s/g, "") || question == ZiXingTi1.replace(/\s/g, "") || question == DuYinTi1.replace(/\s/g, "") || question == Shisanjing.replace(/\s/g, "")) {
// question = question + options[0]; //字形题 读音题 在题目后面添加第一选项
// }
ZiXingArray.forEach(item => { //特殊题目+来源
if (question.indexOf(item) > -1) {
question = question + options[0];
}
});
console.log((conNum + 1).toString() + "搜库题目:" + question);
var answer = tikuCommon.getAnswer(question, 'tiku');
//if (answer.length == 0) {//tiku表中没有则到tikuNet表中搜索答案
// answer = tikuCommon.getAnswer(question, 'tikuNet');
//}
console.info("答案:" + answer);
if (/^[a-zA-Z]{1}$/.test(answer)) { //如果为ABCD形式
var indexAnsTiku = indexFromChar(answer.toUpperCase());
answer = options[indexAnsTiku];
toastLog("answer from char=" + answer);
}
let hasClicked = false;
let listArray = className("ListView").findOnce().children(); //题目选项列表
if (answer == "") //如果没找到答案
{
let i = random(0, listArray.length - 1);
console.error("没有找到答案,随机点击");
delay(random(0.5, 1)); //随机延时0.5-1秒
listArray[i].child(0).click(); //随意点击一个答案
/*******以下代码为获取提示的答案并保存题库 2021.4.29修改 */
var delayTime = 120;
var myColor = "#44BF78";
var myThreshold = 4;
var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
console.info(correctAns);
console.info("正确答案是:" + correctAns[0]);
hasClicked = true;
// 更新题库
// delay(1);
if (correctAns == "" || correctAns == null || correctAns == undefined) //如果答案不是null,就更新题库
{
console.error("没有准确得到答案,跳过更新题库。");
} else {
if (answer == "") {
var sql = "INSERT INTO tiku (question, option, answer, wrongAnswer) VALUES ('" + question + "','" + correctAns[1] + "','" + correctAns[0] + "','')";
} else {
var sql = "UPDATE tiku SET answer='" + correctAns[0] + "' option='" + correctAns[1] + "' WHERE question LIKE '" + question + "'";
}
// console.log(correctAns);
tikuCommon.insertOrUpdate(sql);
console.log("更新题库答案...");
updateToServer(question, correctAns[0]);
}
/*******代码为获取提示的答案并保存题库代码结束 */
{
/*}原代码屏蔽
ClickAnswer = listArray[i].child(0).child(1).text();;//记录已点击答案
hasClicked = true;
console.log("随机点击:"+ClickAnswer);//如果随机点击答案正确,则更新到本地题库tiku表
delay(0.5);//等待0.5秒,是否出现X
if (!text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
"RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists() || text("再来一局").exists())//遇到❌号,则答错了,不再通过结束本局字样判断
{ console.log("更新本地题库答案...");
checkAndUpdate(question, answer, ClickAnswer);
}
*/
}
console.log("-------------");
} else //如果找到了答案
{
listArray.forEach(item => {
var listDescStr = item.child(0).child(1).text();
if (listDescStr == answer) {
delay(random(0.5, 1)); //随机延时0.5-1秒
item.child(0).click(); //点击答案
hasClicked = true;
delay(0.5); //等待0.5秒,是否出现X
if (!text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
"RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists() || text("再来一局").exists()) //遇到❌号,则答错了,不再通过结束本局字样判断
{
console.log("题库答案正确……");
}
if (text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
"RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists() || text("再来一局").exists()) //遇到❌号,则答错了,不再通过结束本局字样判断
{
console.error("题库答案错误!!!");
/*checkAndUpdate(question, answer, ClickAnswer);*/
}
console.log("-------------");
}
});
}
if (!hasClicked) //如果没有点击成功
{ //因导致不能成功点击问题较多,故该部分不更新题库,大部分问题是题库题目适配为填空题或多选题或错误选项
console.error("未能成功点击,随机点击");
let i = random(0, listArray.length - 1);
delay(random(0.5, 1)); //随机延时0.5-1秒
listArray[i].child(0).click(); //随意点击一个答案
console.log("随机点击:" + ClickAnswer);
delay(0.5); //等待0.5秒,是否出现X
if (!text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
"RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists() || text("再来一局").exists()) //遇到❌号,则答错了,不再通过结束本局字样判断
{
console.log("随机点击正确……");
}
if (text("v5IOXn6lQWYTJeqX2eHuNcrPesmSud2JdogYyGnRNxujMT8RS7y43zxY4coWepspQkvw" +
"RDTJtCTsZ5JW+8sGvTRDzFnDeO+BcOEpP0Rte6f+HwcGxeN2dglWfgH8P0C7HkCMJOAAAAAElFTkSuQmCC").exists() || text("再来一局").exists()) //遇到❌号,则答错了,不再通过结束本局字样判断
{
console.error("随机点击错误!!!");
/*checkAndUpdate(question, answer, ClickAnswer);*/
}
console.log("-------------");
}
} catch (e) {
console.error("挑战答题错误,请手动处理!!");
return;
}
}
/*************************************************争上游、双人对战部分*************************************************/
/**
* @description: 答题争上游、双人对战,去掉题目和答案前面的序号
* @param: str 问题或答案
* @return: 去掉序号后的题目或答案
*/
function deleteNO(str) {
/* if (className("android.view.View").textStartsWith("距离答题结束").exists()) {
// console.log(str.slice(3));
return str.slice(3);
} else {
return str;
} */
return str.slice(3);
}
/*************************************************争上游答题部分******************************************************/
/**
* @description: 双人对战答题循环
* @param: conNum 连续答对的次数
* @return: null
*/
function competitionLoop() {
log("competitionLoop");
delaytime4 = randomNum(delaytime1, delaytime2)
sleep(200);
var question = "";
while (question == "") {
if (text("100").depth(24).exists() || text("继续挑战").exists()) {
toastLog("好像有人100了");
return;
}
try {
if (!className("RadioButton").exists() || className("android.view.View").text("继续挑战").exists() || textContains("继续挑战").exists() /*|| !textContains("距离答题结束").exists()*/ ) { //不存在本局结束标志 继续挑战,则执行 20201225界面变化,距离答题结束 删除
return;
}
//while (!className("RadioButton").exists()); //@KB64ba建议使用while判断
//if (className("android.view.View").depth(29).exists() && !text("继续挑战").exists()) {
if (className("RadioButton").exists() || className("android.view.View").depth(29).exists()) {
bquestion = className("android.view.View").depth(29).indexInParent(4).findOnce();
if (bquestion !== null) {
for (i = 0; i < 6; i++) {
question = question + className("ListView").findOnce().parent().child(i).text();
}
n = 0;
while (className("ListView").findOnce().parent().child(0).text() == null) { //如果没有获取到序号,再获取题目一次。
question = "";
for (i = 0; i < 6; i++) {
question = question + className("ListView").findOnce().parent().child(i).text();
}
if (n = 3) {
continue
} //最多循环3次
}
} else {
question = className("android.view.View").depth(29).findOnce().text();
}
if (question !== oldaquestion) {
oldaquestion = question;
console.log("题目:" + question);
question = deleteNO(question);
var chutiIndex = question.lastIndexOf("出题单位");
if (chutiIndex != -1) {
question = question.substring(0, chutiIndex - 2);
}
question = question.replace(/\s/g, "");
console.log("延时:" + delaytime4);
sleep(delaytime4);
// className("ListView").waitFor();
var listArray = className("ListView").findOnce().children(); //题目选项列表
//特殊情况外理
ZiXingArray.forEach(item => { //特殊题目+来源
if (question.indexOf(item) > -1) {
question = question + deleteNO(listArray[0].child(0).child(1).text());
}
});
log("awa");
var answer = getAnswer(question, 'tiku');
/* if (answer.length == 0) { //tiku表中没有则到tikuNet表中搜索答案
answer = getAnswer(question, 'tikuNet');
} */
log("awa");
/*
if (/^[a-zA-Z]{1}$/.test(answer)) { //如果为ABCD形式
var indexAnsTiku = indexFromChar(answer.toUpperCase());
answer = listArray[indexAnsTiku].child(0).child(1).text();
answer = deleteNO(answer);
toastLog("answer from char=" + answer);
} */
if (question == "") {
console.error("提取题目失败!");
let i = random(0, listArray.length - 1);
console.log("随机点击");
listArray[i].child(0).click(); //随意点击一个答案
return false;
}
if (text("100").depth(24).exists() || text("继续挑战").exists()) {
toastLog("好像有人100了");
return;
}
let hasClicked = false;
// let listArray = className("ListView").findOnce().children(); //题目选项列表
if (answer == "") //如果没找到答案
{
let i = random(0, listArray.length - 1);
console.error("没有找到答案,随机点击一个");
listArray[i].child(0).click(); //随意点击一个答案
hasClicked = true;
ClickAnswer = listArray[i].child(0).child(1).text(); //记录已点击答案
console.log("随机点击:" + ClickAnswer);
console.log("-------------");
var options = []; //选项列表
while (options.length == 0) {
if (className("ListView").exists()) {
className("ListView").findOne().children().forEach(child => {
var answer_q = child.child(0).child(1).text();
options.push(answer_q);
});
} else {
console.error("答案列表获取失败!");
return false;
}
}
var delayTime = 1055;
var myColor = "#2BC87E";
var myThreshold = 25;
var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
// 更新题库
// delay(1);
if (correctAns) //如果答案不是null,就更新题库
{
correctAns[0] = deleteNO(correctAns[0]);
console.info("正确答案是:" + correctAns[0]);
var sql = "INSERT INTO tiku (question, option, answer, wrongAnswer) VALUES ('" + question + "','" + correctAns[1] + "','" + correctAns[0] + "','')";
// console.log(correctAns);
tikuCommon.insertOrUpdate(sql);
console.log("更新题库答案...");
}
// if (correctAns[0] == deleteNO(options[i])) { //listArray[i].child(0).child(1).text()
// return true;
// }
if (correctAns[0] == deleteNO(ClickAnswer)) { //listArray[i].child(0).child(1).text()
return true;
} else {
console.log("-------------------------------");
hasClicked = true;
return false;
}
} else //如果找到了答案
{
console.info("答案:" + answer);
/* listArray.some(item => {
var listDescStr = item.child(0).child(1).text();
console.error(deleteNO(listDescStr));
if (deleteNO(listDescStr) == answer) {
item.child(0).click(); //点击答案
hasClicked = true;
rightCount++;
console.log("-------------------------------");
return true;
}
}); */
if (textEndsWith(answer).exists()) {
/* var optletters = textEndsWith(answer).findOnce().text();
optletters = optletters[0];
toastLog(optletters); */
sleep(30)
log("imhere");
textEndsWith(answer).click();
hasClicked = true;
if (!textContains(answer).exists()) { //如果列表里没有找到的答案,说明题库答案错误
console.error("题库答案错误,请手动修改题库!随意点击一个答案。");
let i = random(0, listArray.length - 1);
listArray[i].child(0).click(); //随意点击一个答案
}
console.log("-------------------------------");
return true;
}
}
//console.error(hasClicked);
if (!hasClicked) //如果没有点击成功
{
console.error("未能成功点击,随机点击一个");
let i = random(0, listArray.length - 1);
listArray[i].child(0).click(); //随意点击一个答案
console.log("-------------------------------");
}
return false;
}
question = "";
} else {
// console.error("提取题目失败!");
let listArray = className("ListView").findOnce().children(); //题目选项列表
let i = random(0, listArray.length - 1);
console.log("随机点击一个");
listArray[i].child(0).click(); //随意点击一个答案
return false;
}
} catch (e) {
return false;
}
// delay(0.1);
}
}
/*************************************************降胜率循环部分******************************************************/
/**
* @description: 降胜率答题循环
* @param: conNum 连续答对的次数
* @return: null
*/
function competitionLoopnew(conNum) {
delaytime4 = randomNum(delaytime1, delaytime2)
sleep(20);
var question = "";
while (question == "") {
if (text("100").depth(24).exists() || text("继续挑战").exists()) {
toastLog("好像有人100了");
return;
}
try {
if (!className("RadioButton").exists() || className("android.view.View").text("继续挑战").exists() || textContains("继续挑战").exists() /*|| !textContains("距离答题结束").exists()*/ ) { //不存在本局结束标志 继续挑战,则执行 20201225界面变化,距离答题结束 删除
return;
}
if (className("RadioButton").exists() || className("android.view.View").depth(29).exists()) {
bquestion = className("android.view.View").depth(29).indexInParent(4).findOnce();
if (bquestion !== null) {
for (i = 0; i < 6; i++) {
question = question + className("ListView").findOnce().parent().child(i).text();
}
n = 0;
while (className("ListView").findOnce().parent().child(0).text() == null) { //如果没有获取到序号,再获取题目一次。
question = "";
for (i = 0; i < 6; i++) {
question = question + className("ListView").findOnce().parent().child(i).text();
}
if (n = 3) {
continue
} //最多循环3次
}
//console.error("来源题:"+question);
//sleep(2000);
} else {
question = className("android.view.View").depth(29).findOnce().text();
}
if (question !== oldaquestion) {
oldaquestion = question;
console.log("题目:" + question);
question = deleteNO(question);
var chutiIndex = question.lastIndexOf("出题单位");
if (chutiIndex != -1) {
question = question.substring(0, chutiIndex - 2);
}
question = question.replace(/\s/g, "");
// className("ListView").waitFor();
console.log("延时:" + delaytime4);
sleep(delaytime4);
var listArray = className("ListView").findOnce().children(); //题目选项列表
//特殊情况外理
ZiXingArray.forEach(item => { //特殊题目+来源
if (question.indexOf(item) > -1) {
question = question + deleteNO(listArray[0].child(0).child(1).text());
}
});
var answer = tikuCommon.getAnswer(question, 'tiku');
if (!textContains(answer).exists()) { //如果列表里没有找到的答案,说明题库答案错误
hasClicked = false;
console.error("题库答案错误,请手动修改题库,删除该题!");
}
if (question == "") {
console.error("提取题目失败!");
let i = random(0, listArray.length - 1);
console.log("随机点击");
listArray[i].child(0).click(); //随意点击一个答案
return;
}
if (text("100").depth(24).exists() || text("继续挑战").exists()) {
toastLog("好像有人100了");
return;
}
let hasClicked = false;
// let listArray = className("ListView").findOnce().children(); //题目选项列表
if (answer == "") //如果没找到答案
{
let i = random(0, listArray.length - 1);
console.error("没有找到答案,随机点击一个");
listArray[i].child(0).click(); //随意点击一个答案
hasClicked = true;
ClickAnswer = listArray[i].child(0).child(1).text();; //记录已点击答案
console.log("随机点击:" + ClickAnswer);
console.log("-------------");
var options = []; //选项列表
while (options.length == 0) {
if (className("ListView").exists()) {
className("ListView").findOne().children().forEach(child => {
var answer_q = child.child(0).child(1).text();
options.push(answer_q);
});
} else {
console.error("答案列表获取失败!");
return false;
}
}
var delayTime = 1055;
var myColor = "#2BC87E";
var myThreshold = 25;
var correctAns = findCorrectAnswer(delayTime, myColor, myThreshold, listArray, options);
// 更新题库
// delay(1);
if (correctAns) //如果答案不是null,就更新题库
{
correctAns[0] = deleteNO(correctAns[0]);
console.info("正确答案是:" + correctAns[0]);
var sql = "INSERT INTO tiku (question, option, answer, wrongAnswer) VALUES ('" + question + "','" + correctAns[1] + "','" + correctAns[0] + "','')";
// console.log(correctAns);
tikuCommon.insertOrUpdate(sql);
console.log("更新题库答案...");
updateToServer(question, correctAns[0]);
}
if (correctAns[0] == deleteNO(ClickAnswer)) { //listArray[i].child(0).child(1).text()
return true;
} else {
hasClicked = true;
return false;
}
} else //如果找到了答案
{
console.info("答案:" + answer);
if (text("100").depth(24).exists() || text("继续挑战").exists()) {
toastLog("好像有人100了");
return;
}
console.warn("---降胜率:我就乱点---");
let listArray = className("ListView").findOnce().children(); //题目选项列表
let i = random(0, listArray.length - 1);
listArray[i].child(0).click(); //随意点击一个答案
ClickAnswer = listArray[i].child(0).child(1).text();; //记录已点击答案
if (answer == deleteNO(ClickAnswer)) {
return true;
} else {
hasClicked = true;
return false;
}
}
}
} else {
return false;
}
} catch (e) {
return false;
}
// delay(0.1);
}
if (text("100").depth(24).exists() || text("继续挑战").exists()) {
toastLog("好像有人100了");
return;
}
}
/************************** 2021.4.28使用新循环****************************************** */
function getQuestion(img) {
var imgClip = images.inRange(img, '#000000', '#444444');
var imgBase = images.toBase64(imgClip);
//img.recycle(); //回收图片,防止内存泄露,但是我发现加上后速度更慢,因此注释。
toastLog("I'm getting ocr text!");
//获取ocr结果
let resobj = OCR.Ocr(imgClip);
log(resobj);
var timu = "";
var words_list = resobj;
for (var i in words_list) {
// 如果是选项则后面不需要读取
if (words_list[i].label[0] == "A") break;
// 如果两词块之间有分割线,则不读取
// 利用location之差判断是否之中有分割线
/**
* rect:
* 识别到的文字块的区域位置信息,列表形式,
* 分别表示文字块4个顶点的(x,y)坐标;采用图像坐标系,
* 图像坐标原点为图像左上角,x轴沿水平方向,y轴沿竖直方向。
*
判断条件: Math.abs(words_list[i].rect[0][0] - words_list[i - 1].rect[0][0]) > 100
*/
if (words_list[0].label[1] == '.' && i > 0) break;
timu += words_list[i].label;
}
timu = timu.slice(timu.indexOf('.') + 1);
timu = timu.replace(/\s*/g, "");
timu = timu.replace(/,/g, ",");
timu = timu.replace(/o/g, "。");
timu = timu.replace(/O/g, "。");
timu = timu.replace(/"/, "“");
timu = timu.replace(/"/g, "”");
timu = timu.replace(/'/, "“");
timu = timu.replace(/'/g, "”");
timu = timu.replace(/\(/g, "(");
timu = timu.replace(/\)/g, ")");
return timu;
}
/**
* @description: 争上游答题 双人对战答题循环
* @param: null
* @return: null
*/
function zsyQuestionLoop() {
let ClickAnswer;
try { //20201025使用try catch(e)语句处理错误,去除前后置0.5s延时
/*delay(0.5);*/ //4-0.5,前置0.5延时判断结束标志
if (!className("RadioButton").exists() || className("android.view.View").text("继续挑战").exists() || textContains("继续挑战").exists() /*|| !textContains("距离答题结束").exists()*/ ) { //不存在本局结束标志 继续挑战,则执行 20201225界面变化,距离答题结束 删除
/*console.info("答题结束!");*/ //配合20201225界面变化 距离答题结束 去除,本语句去除
return;
} else {
log("开始获取题目");
while (!className("RadioButton").exists()); //@KB64ba建议使用while判断
if (className("RadioButton").exists() || question.length == 0) {
// var bounds = className("ListView").findOnce().parent().bounds();
// var imgScreen = captureScreen(); //请求截取当前屏幕
// var imgclip = images.clip(imgScreen, bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top);
// var question = getQuestion(imgclip);
var question = getQuestion(captureScreen());
}
log("获取完题目了");
console.log("题目:" + question);
var answer_list = getAnswer(question, 'tiku');
var answer = answer_list[1];
var answer_content = answer_list[0];
console.info("答案:" + answer_content);
if (answer == ' ') {
let i = random(0, listArray.length - 1);
console.error("没有找到答案,随机点击");
className('android.widget.RadioButton').depth(32).findOne().click();
console.log("随机点击");
console.log("-------------");
} else { //如果找到了答案 该部分问题: 选项带A.B.C.D.,题库返回答案不带,char返回答案带
log("本地答案:" + answer_content);
//等待选项加载
className('android.widget.RadioButton').depth(32).waitFor();
try {
className('android.widget.RadioButton').depth(32).findOnce(answer.charCodeAt(0) - 65).click();
log("点击成功");
log("---------------");
} catch (error) {
// 如果选项不存在,则点击第一个
if (className('android.widget.RadioButton').depth(32).exists()) {
log("答案:选项不存在,点击A");
className('android.widget.RadioButton').depth(32).findOne().click();
log("点击成功");
log("---------------");
}
}
}
// 等待下一题加载
do {
var point = findColor(captureScreen(), '#555AB6', {
region: [device.width * distance1 / width, device.height * distance2 / height,
device.width * (1 - 2 * distance1 / width), device.height * (1 - distance2 / height - distance3 / height)
],
threshold: 10,
});
} while (!point);
delay(0.1);
}
} catch (e) {
//console.log("错误捕获(不用管):" + e)
delay(3);
if (!className("RadioButton").exists() || className("android.view.View").text("继续挑战").exists() || textContains("继续挑战").exists() /*|| !textContains("距离答题结束").exists()*/ ) { //不存在本局结束标志 继续挑战,则执行
/*console.info("答题结束!");*/ //配合20201225界面变化 距离答题结束 删除,本语句删除
return;
}
}
}
/*************************************************每日答题部分***************************************************/
/**
* @description: 获取填空题题目数组
* @param: null
* @return: questionArray
*/
function getFitbQuestion() {
var questionCollections = className("EditText").findOnce().parent().parent();
var questionArray = [];
var findBlank = false;
var blankCount = 0;
var blankNumStr = "";
var i = 0;
questionCollections.children().forEach(item => {
if (item.className() != "android.widget.EditText") {
if (item.text() != "") { //题目段
if (findBlank) {
blankNumStr = "|" + blankCount.toString();
questionArray.push(blankNumStr);
findBlank = false;
}
questionArray.push(item.text());
} else {
findBlank = true;
blankCount = (className("EditText").findOnce(i).parent().childCount() - 1);
i++;
}
}
});
/* questionArray.forEach( item=> {
console.log(item);
}) */
return questionArray;
}
/**
* @description: 获取选择题题目数组
* @param: null
* @return: questionArray
*/
function getChoiceQuestion() {
var questionCollections = className("ListView").findOnce().parent().child(1);
var questionArray = [];
questionArray.push(questionCollections.text());
return questionArray;
}
/**
* @description: 获取提示字符串
* @param: null
* @return: tipsStr
*/
function getTipsStr() {
var tipsStr = "";