Skip to content

Commit

Permalink
Fix VCF bug (#120)
Browse files Browse the repository at this point in the history
* cargo update

* add test

* fix warning

* fix bug arround finding forced move when the last move is none
  • Loading branch information
yubessy authored Mar 10, 2024
1 parent ef631d5 commit d8bdf3c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 48 deletions.
77 changes: 34 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/board/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl FromStr for Line {
}
let mut line = Self::new(size as u8);
for (i, c) in chars.into_iter().enumerate() {
Player::try_from(c).map_or((), |p| line.put_mut(p, i as u8));
let _ = Player::try_from(c).map_or((), |p| line.put_mut(p, i as u8));
}
Ok(line)
}
Expand Down
6 changes: 5 additions & 1 deletion src/mate/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ impl Game {
.flat_map(|r| r.eyes());
Self::take_distinct_two(last_four_eyes)
} else {
(None, None)
let four_eyes = self
.board
.structures(self.turn.opponent(), Four)
.flat_map(|r| r.eyes());
Self::take_distinct_two(four_eyes)
}
}

Expand Down
32 changes: 29 additions & 3 deletions src/mate/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ fn validate(board: &Board, attacker: Player) -> Result<(), Option<Mate>> {
if board.structures(Black, OverFive).next().is_some() {
return Err(None);
}
if board.structures(attacker.opponent(), Four).next().is_some() {
return Err(None);
}
if board.structures(attacker, Four).next().is_some() {
return Err(Some(Mate::new(Unknown, vec![])));
}
Expand Down Expand Up @@ -260,6 +257,35 @@ mod tests {
Ok(())
}

#[test]
fn test_vcf_counter() -> Result<(), String> {
let board = "
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . x . . . . . . .
. . . . . . . o . o o x . . .
. . . . . . . . o x . o . . .
. . . . . . . . o . x . . . .
. . . . . . . . x . . x . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
"
.parse::<Board>()?;

let solution: String = "I8,G8,I10,I9,J9".split_whitespace().collect();

let result = solve(VCFDFS, u8::MAX, &board, Black, 0);
assert_eq!(path_string(result), solution);

Ok(())
}

#[test]
fn test_vct_black() -> Result<(), String> {
// No. 02 from 5-moves-to-end problems by Hiroshi Okabe
Expand Down

0 comments on commit d8bdf3c

Please sign in to comment.