Created
February 10, 2019 15:23
-
-
Save JPMoresmau/4c301e6e03bd1b4da283b5cca17ac63e to your computer and use it in GitHub Desktop.
Lovecraft: solve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use std::collections::VecDeque; | |
pub fn solve(grid: Grid) -> Vec<Pos> { | |
if is_solved(grid){ | |
return vec!(); | |
} | |
let mut ret = None; | |
let mut seen=HashMap::new(); | |
seen.insert(grid,Vec::new()); | |
let mut todo=VecDeque::new(); | |
todo.push_back(grid); | |
while ret.is_none(){ | |
match todo.pop_front(){ | |
Some(g)=> { | |
ret = try_all(&g,&mut seen,&mut todo); | |
}, | |
None=>panic!("no more grids to do"), | |
} | |
} | |
ret.expect("no result!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment