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
use crate::algorithms::{cal_probability_cells_not_mine, mark_board};
use crate::utils::is_good_chording;
use crate::videos::base_video::BaseVideo;
use crate::videos::types::Event;
use crate::MouseState;
use std::cmp::{max, min};
// 录像的事件分析。参与分析的录像必须已经计算出对应的数据。
// error: 高风险的猜雷(猜对概率0.05)√
// feature: 高难度的判雷√
// warning:vision_transfer√
// feature: 双线操作
// feature: 破空(成功率0.98)
// feature: 教科书式的FL局部(步数4)√
// error: 过于弯曲的鼠标轨迹(500%)√
// warning:弯曲的鼠标轨迹(200%)√
// warning: 可以判雷时选择猜雷√
// warning: 没有作用的操作
// suspect: 点击速度过快(0.01)
// suspect: 鼠标移动过快(2)
// suspect:mouse_trace_straight(101%)√
pub fn analyse_high_risk_guess(video: &mut BaseVideo<Vec<Vec<i32>>>) {
let mut r;
let mut c;
for ide in 2..video.video_action_state_recorder.len() {
let vas = &mut video.video_action_state_recorder[ide];
if let Some(Event::Mouse(mouse_event)) = &vas.event {
r = (mouse_event.y / video.cell_pixel_size as u16) as usize;
c = (mouse_event.x / video.cell_pixel_size as u16) as usize;
if vas.useful_level >= 2 {
let p = vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.get_poss()[r][c];
if p >= 0.51 {
vas.comments = format!(
"{}{}",
vas.comments,
format!("error:high_risk_guess:{:?};", 1.0 - p)
);
}
}
}
}
}
pub fn analyse_jump_judge(video: &mut BaseVideo<Vec<Vec<i32>>>) {
// 功能:检测左键或右键的跳判
let mut r;
let mut c;
for ide in 2..video.video_action_state_recorder.len() {
let vas = &mut video.video_action_state_recorder[ide];
if let Some(Event::Mouse(mouse_event)) = &vas.event {
r = (mouse_event.y / video.cell_pixel_size as u16) as usize;
c = (mouse_event.x / video.cell_pixel_size as u16) as usize;
if vas.useful_level >= 2 && mouse_event.mouse == "lr" {
if !vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.get_basic_not_mine()
.contains(&(r, c))
&& vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.get_enum_not_mine()
.contains(&(r, c))
{
vas.comments =
format!("{}{}", vas.comments, format!("feature:hard_judgment:left;"));
}
} else if vas.useful_level == 1 && mouse_event.mouse == "rc" {
if !vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.get_basic_is_mine()
.contains(&(r, c))
&& vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.get_enum_is_mine()
.contains(&(r, c))
{
vas.comments =
format!("{}{}", vas.comments, format!("feature:hard_judgment:flag;"));
}
}
}
}
}
// 猜雷时,假如周围5*5范围内有可判的,引发可以判雷时选择猜雷
pub fn analyse_needless_guess(video: &mut BaseVideo<Vec<Vec<i32>>>) {
let mut r;
let mut c;
'outer: for ide in 2..video.video_action_state_recorder.len() {
let vas = &mut video.video_action_state_recorder[ide];
if let Some(Event::Mouse(mouse_event)) = &vas.event {
if vas.useful_level >= 2 && mouse_event.mouse == "lr" {
r = (mouse_event.y / video.cell_pixel_size as u16) as usize;
c = (mouse_event.x / video.cell_pixel_size as u16) as usize;
if vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.get_poss()[r][c]
> 0.0
{
for m in max(2, r) - 2..min(video.height, r + 3) {
for n in max(2, c) - 2..min(video.width, c + 3) {
if vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.get_basic_not_mine()
.contains(&(m, n))
|| vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.get_enum_not_mine()
.contains(&(m, n))
{
vas.comments = format!(
"{}{}",
vas.comments,
format!("warning:needless_guess;")
);
continue 'outer;
}
}
}
}
}
}
}
}
/// 检查鼠标轨迹是否弯曲
pub fn analyse_mouse_trace(video: &mut BaseVideo<Vec<Vec<i32>>>) {
let Some(Event::Mouse(mut last_click_event)) =
video.video_action_state_recorder[0].event.clone()
else {
panic!("expected mouse event");
};
let Some(Event::Mouse(mut last_move_event)) =
video.video_action_state_recorder[0].event.clone()
else {
panic!("expected mouse event");
};
let mut comments = vec![];
let mut click_last_id = 0;
let mut path = 0.0;
for ide in 0..video.video_action_state_recorder.len() {
let vas = &mut video.video_action_state_recorder[ide];
if let Some(Event::Mouse(mouse_event)) = &vas.event {
let current_x = mouse_event.x as f64;
let current_y = mouse_event.y as f64;
path += ((last_move_event.x as f64 - current_x).powf(2.0)
+ (last_move_event.y as f64 - current_y).powf(2.0))
.sqrt();
last_move_event = mouse_event.clone();
if mouse_event.mouse == "lr" || mouse_event.mouse == "rc" || mouse_event.mouse == "rr" {
let path_straight = ((last_click_event.x as f64 - current_x).powf(2.0)
+ (last_click_event.y as f64 - current_y).powf(2.0))
.sqrt();
let k = path / path_straight;
if k > 20.0 {
comments.push((
click_last_id,
format!("error:mouse_trace_too_curved:{:?};", k * 100.0),
));
} else if k > 10.0 {
comments.push((
click_last_id,
format!("warning:mouse_trace_curved:{:?};", k * 100.0),
));
} else if k < 1.01 {
comments.push((click_last_id, "suspect:mouse_trace_straight;".to_owned()));
}
last_click_event = mouse_event.clone();
click_last_id = ide;
path = 0.0;
}
}
}
for comment in comments {
video.video_action_state_recorder[comment.0].comments = video.video_action_state_recorder
[comment.0]
.comments
.clone()
+ &comment.1;
}
}
// bug
pub fn analyse_vision_transfer(video: &mut BaseVideo<Vec<Vec<i32>>>) {
let Some(Event::Mouse(mut last_click_event)) =
video.video_action_state_recorder[0].event.clone()
else {
panic!("expected mouse event");
};
let mut comments = vec![];
let mut last_c = (last_click_event.y / video.cell_pixel_size as u16) as usize;
let mut last_r = (last_click_event.x / video.cell_pixel_size as u16) as usize;
let mut click_last_id = 0;
for ide in 0..video.video_action_state_recorder.len() {
let vas = &mut video.video_action_state_recorder[ide];
if let Some(Event::Mouse(mouse_event)) = &vas.event {
if vas.useful_level >= 2 {
if ((last_click_event.x as f64 - mouse_event.x as f64).powf(2.0)
+ (last_click_event.y as f64 - mouse_event.y as f64).powf(2.0))
.sqrt()
/ video.cell_pixel_size as f64
>= 6.0
{
let mut flag = false;
for &(xxx, yyy) in vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.get_basic_not_mine()
{
if xxx <= last_c + 3
&& xxx + 3 >= last_c
&& yyy <= last_r + 3
&& yyy + 3 >= last_r
{
flag = true;
}
}
for &(xxx, yyy) in vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.get_enum_not_mine()
{
if xxx <= last_c + 3
&& xxx + 3 >= last_c
&& yyy <= last_r + 3
&& yyy + 3 >= last_r
{
flag = true;
}
}
if flag {
comments.push((click_last_id, "warning:vision_transfer;"));
}
}
last_click_event = mouse_event.clone();
last_c = (last_click_event.y / video.cell_pixel_size as u16) as usize;
last_r = (last_click_event.x / video.cell_pixel_size as u16) as usize;
click_last_id = ide;
}
}
}
for comment in comments {
video.video_action_state_recorder[comment.0].comments = video.video_action_state_recorder
[comment.0]
.comments
.clone()
+ &comment.1;
}
}
/// 计算回放的录像的各个时刻的pluck参数
pub fn analyse_pluck(video: &mut BaseVideo<Vec<Vec<i32>>>) {
let mut pluck = 0.0;
let mut has_begin = false;
for vas in video.video_action_state_recorder.iter_mut() {
if let Some(Event::Mouse(mouse_event)) = &vas.event {
if vas.useful_level == 2 {
// 有效的左键
if !has_begin {
has_begin = true;
vas.key_dynamic_params.pluck = 0.0;
continue;
}
let r = (mouse_event.y / video.cell_pixel_size as u16) as usize;
let c = (mouse_event.x / video.cell_pixel_size as u16) as usize;
// 安全的概率
let p = 1.0
- vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.get_poss()[r][c];
if p <= 0.0 || pluck == f64::MAX {
pluck = f64::MAX;
} else if p < 1.0 {
pluck -= p.log10();
}
} else if vas.useful_level == 3 {
// 有效的双键
let r = (mouse_event.y / video.cell_pixel_size as u16) as usize;
let c = (mouse_event.x / video.cell_pixel_size as u16) as usize;
let mut game_board_clone_clean = vas
.prior_game_board
.as_ref()
.unwrap()
.borrow_mut()
.game_board
.clone();
let mut chording_cells = vec![];
for m in max(1, r) - 1..min(video.height, r + 2) {
for n in max(1, c) - 1..min(video.width, c + 2) {
if game_board_clone_clean[m][n] == 10 {
chording_cells.push((m, n));
}
}
}
let _ = mark_board(&mut game_board_clone_clean, true).unwrap();
// 安全的概率
let p = cal_probability_cells_not_mine(
&game_board_clone_clean,
video.mine_num as f64,
&chording_cells,
);
if p <= 0.0 || pluck == f64::MAX {
pluck = f64::MAX;
} else if p > 0.0 {
pluck -= p.log10();
}
} else if vas.useful_level == 4 {
pluck = f64::MAX;
}
if has_begin {
vas.key_dynamic_params.pluck = pluck;
} else {
vas.key_dynamic_params.pluck = 0.0;
}
}
}
video.video_analyse_params.pluck = pluck;
}
#[derive(Debug, PartialEq)]
pub enum SuperFLState {
NotStart, // 还没开始
StartNow, // 此处开始
StartNotOk, // 开始了,但还没满足数量
IsOk, // 满足数量了,延续
Finish, // 检测到,结束
}
pub fn analyse_super_fl_local(video: &mut BaseVideo<Vec<Vec<i32>>>) {
let mut comments = vec![];
let event_min_num = 5;
let euclidean_distance = 16;
let mut anchor = 0;
let mut counter = 0; //正在标雷、双击超过event_min_num总次数
let mut state = SuperFLState::NotStart;
let mut last_rc_num = 0; // 最后有几个右键
// let mut last_ide = 0;
let Some(Event::Mouse(mut last_event)) = video.video_action_state_recorder[0].event.clone()
else {
panic!("expected mouse event");
};
let mut last_event_mouse_state = video.video_action_state_recorder[0].mouse_state;
for ide in 1..video.video_action_state_recorder.len() {
let vas = &mut video.video_action_state_recorder[ide];
if let Some(Event::Mouse(mouse_event)) = &vas.event {
if mouse_event.mouse == "mv" {
continue;
}
let x = mouse_event.y as usize / video.cell_pixel_size as usize;
let y = mouse_event.x as usize / video.cell_pixel_size as usize;
let r_1 = last_event.y as usize / video.cell_pixel_size as usize;
let c_1 = last_event.x as usize / video.cell_pixel_size as usize;
// if mouse_event.mouse == "rc" || mouse_event.mouse == "rc"{
// println!("{:?}, {:?}, {:?}, {:?}", vas.time, vas.mouse_state, x, y);
// println!("---{:?}", video.video_action_state_recorder[ide].useful_level);
// }
if mouse_event.mouse == "rc"
&& vas.useful_level == 1
&& vas.prior_game_board.as_ref().unwrap().borrow().game_board[x][y] == 10
{
// 正确的标雷
match state {
SuperFLState::NotStart => {
state = SuperFLState::StartNow;
counter = 1;
last_rc_num = 1;
anchor = ide;
// println!("666");
}
SuperFLState::StartNow => {
state = SuperFLState::StartNotOk;
counter += 1;
last_rc_num += 1;
}
SuperFLState::StartNotOk | SuperFLState::IsOk => {
counter += 1;
last_rc_num += 1;
}
_ => {}
}
} else if vas.useful_level == 3 {
// 正确的双击
if !is_good_chording(
&vas.prior_game_board.as_ref().unwrap().borrow().game_board,
(x, y),
) {
match state {
SuperFLState::IsOk => {
counter -= last_rc_num;
state = SuperFLState::Finish;
}
_ => {
state = SuperFLState::NotStart;
counter = 0;
last_rc_num = 0;
}
}
} else {
match state {
SuperFLState::StartNow => {
state = SuperFLState::StartNotOk;
counter += 1;
last_rc_num = 0;
}
SuperFLState::StartNotOk | SuperFLState::IsOk => {
counter += 1;
last_rc_num = 0;
}
_ => {}
}
}
} else if mouse_event.mouse == "lr"
&& (last_event_mouse_state == MouseState::DownUp
|| last_event_mouse_state == MouseState::Chording)
|| mouse_event.mouse == "rr" && last_event_mouse_state == MouseState::Chording
{
// 左键或错误的右键或错误的双键
match state {
SuperFLState::IsOk => {
counter -= last_rc_num;
state = SuperFLState::Finish;
}
_ => {
state = SuperFLState::NotStart;
counter = 0;
last_rc_num = 0;
}
}
}
if (x as i32 - r_1 as i32) * (x as i32 - r_1 as i32)
+ (y as i32 - c_1 as i32) * (y as i32 - c_1 as i32)
> euclidean_distance
{
match state {
SuperFLState::StartNotOk => {
state = SuperFLState::NotStart;
counter = 0;
last_rc_num = 0;
}
SuperFLState::IsOk => {
counter -= last_rc_num;
state = SuperFLState::Finish;
}
_ => {}
}
}
if counter - last_rc_num >= event_min_num {
match state {
SuperFLState::StartNow | SuperFLState::StartNotOk => {
state = SuperFLState::IsOk;
}
_ => {}
}
}
match state {
SuperFLState::Finish => {
comments.push((anchor, format!("feature:fl_local:{};", counter)));
// video.video_action_state_recorder[anchor].comments = format!(
// "{}{}",
// video.video_action_state_recorder[anchor].comments,
// format!("feature:fl_local:{};", counter)
// );
state = SuperFLState::NotStart;
}
_ => {}
}
last_event = mouse_event.clone();
last_event_mouse_state = vas.mouse_state;
// println!("{:?}", video.video_action_state_recorder[last_ide].mouse_state);
}
}
for comment in comments {
video.video_action_state_recorder[comment.0].comments = video.video_action_state_recorder
[comment.0]
.comments
.clone()
+ &comment.1;
}
}