Skip to content

Commit

Permalink
修改了判断成功方法, 发布了1.0版
Browse files Browse the repository at this point in the history
  • Loading branch information
chanble committed Mar 3, 2021
1 parent 48e27cc commit 5a49a66
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "num-huarongdao"
version = "0.2.0"
version = "1.0.0"
authors = ["chen <[email protected]>"]
edition = "2018"
description = "fifteen puzzle lib"
Expand Down
18 changes: 3 additions & 15 deletions src/num_hrd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ impl NumHrd {
pub fn new(s: &u8) -> Self {
let mut nums:Vec<Num> = Vec::new();
let nums_len: usize = (s * s).into();
for i in 0..nums_len {
for i in 1..nums_len {
let num = Num::new(&i);
nums.push(num);
}
nums.push(Num::new(&0));
Self {
size: *s,
nums,
Expand Down Expand Up @@ -161,20 +162,7 @@ impl NumHrd {
/// 判断是否成功
///
pub fn is_win(&self) -> bool {
let mut res = false;
let len = self.len();
for i in 1..len {
if let Some(&num) = self.num_by_index(&(i - 1)) {
res = num.n as usize == i;
if !res {
break
}
} else {
res = false;
break
}
}
res
self.nums == Self::new(&self.size).nums
}

pub fn len(&self) -> usize {
Expand Down

0 comments on commit 5a49a66

Please sign in to comment.