Skip to content

Commit

Permalink
fix: 可猜模式修改局面后应该清零扫开指针
Browse files Browse the repository at this point in the history
  • Loading branch information
eee555 committed Jul 16, 2024
1 parent faf2bf3 commit 13589ea
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
31 changes: 16 additions & 15 deletions base/src/videos/base_video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,16 @@ impl BaseVideo<SafeBoard> {
pub fn set_board(&mut self, board: Vec<Vec<i32>>) -> Result<u8, ()> {
assert!(!board.is_empty());
match self.game_board_state {
GameBoardState::Playing | GameBoardState::Ready | GameBoardState::PreFlaging => {
GameBoardState::Ready | GameBoardState::PreFlaging => {
if self.width != board[0].len() || self.height != board.len() {
return Err(());
}
}
GameBoardState::Playing => {
if self.mode != 9 && self.mode != 10 {
println!("{:?}", self.mode);
return Err(());
}
if self.width != board[0].len() || self.height != board.len() {
return Err(());
}
Expand All @@ -674,7 +683,8 @@ impl BaseVideo<SafeBoard> {
self.level = 6;
}
self.board = SafeBoard::new(board);
self.minesweeper_board.board = self.board.clone();
// self.minesweeper_board.board = self.board.clone();
self.minesweeper_board.set_board(self.board.clone());
Ok(0)
}
}
Expand Down Expand Up @@ -773,18 +783,7 @@ impl<T> BaseVideo<T> {
T::Output: std::ops::Index<usize, Output = i32>,
{
let step_instant = Instant::now();
// match self.game_board_state {
// GameBoardState::Ready | GameBoardState::PreFlaging => {
// let mut time_ms = step_instant
// .duration_since(self.video_start_instant)
// .as_millis() as u32;
// let mut time = time_ms as f64 / 1000.0;
// }
// }
// 这是和录像时间戳有关
// let mut time_ms = step_instant
// .duration_since(self.video_start_instant)
// .as_millis() as u32;

let mut time_ms = time_ms_between(step_instant, self.video_start_instant);
let mut time = time_ms as f64 / 1000.0;
let old_state = self.minesweeper_board.game_board_state;
Expand Down Expand Up @@ -865,7 +864,7 @@ impl<T> BaseVideo<T> {
self.start_time = self.end_time.clone();
self.game_start_ms = time_ms;
// println!("334")
}
}
let t_ms = time_ms - self.game_start_ms;
self.is_completed = true;
let t = t_ms as f64 / 1000.0;
Expand Down Expand Up @@ -1278,9 +1277,11 @@ impl<T> BaseVideo<T> {
self.is_fair = is_fair;
Ok(0)
}
/// 可猜模式必须在ready时设置模式,其它模式扫完再设置也可以
pub fn set_mode(&mut self, mode: u16) -> Result<u8, ()> {
if self.game_board_state != GameBoardState::Loss
&& self.game_board_state != GameBoardState::Win
&& self.game_board_state != GameBoardState::Ready
{
return Err(());
};
Expand Down
6 changes: 6 additions & 0 deletions base/src/videos/minesweeper_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ impl MinesweeperBoard<SafeBoard> {
..MinesweeperBoard::<SafeBoard>::default()
}
}
/// 两种情况调用:游戏开始前、可猜模式(不做检查)
pub fn set_board(&mut self, board: SafeBoard) {
self.board = board;
self.pointer_x = 0;
self.pointer_y = 0;
}
}

impl<T> MinesweeperBoard<T> {
Expand Down
44 changes: 43 additions & 1 deletion base/tests/test_analyse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 测试录像分析模块
use ms_toollib::{AvfVideo, BaseVideo, EvfVideo, MinesweeperBoard, MvfVideo, RmvVideo};
use ms_toollib::{AvfVideo, BaseVideo, EvfVideo, MinesweeperBoard, MvfVideo, RmvVideo, SafeBoard};
use std::thread;

#[test]
Expand Down Expand Up @@ -809,4 +809,46 @@ fn BaseVideo_works_5_1bv() {
println!("时间毫秒:{:?}", video.get_rtime_ms());
println!("时间毫秒:{:?}", video.get_bbbv_s());

}


#[test]
fn BaseVideo_works_set_board() {
let board = vec![
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 1, 1],
vec![ 0, 0, 0, 0, 0, 0, 1, -1],
];
let board2 = vec![
vec![ -1, 1, 0, 0, 0, 0, 0, 0],
vec![ 1, 1, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
vec![ 0, 0, 0, 0, 0, 0, 0, 0],
];
let mut video = BaseVideo::<SafeBoard>::new_before_game(board, 16);
video.set_mode(9).unwrap();
video.step("lc", (97, 97)).unwrap();
thread::sleep_ms(200);
video.step("lr", (97, 97)).unwrap();
video.set_board(board2).unwrap();
video.step("lc", (77, 77)).unwrap();
thread::sleep_ms(200);
video.step("lr", (77, 77)).unwrap();

// video.generate_evf_v0_raw_data();
// video.set_checksum([8; 32]).unwrap();
// video.save_to_evf_file("test");

println!("局面:{:?}", video.get_game_board());
println!("局面状态:{:?}", video.game_board_state);

}

0 comments on commit 13589ea

Please sign in to comment.