Crossword_Generator
Crossword_generator is a library for creating crosswords from provided words. It determines the positions and directions of the words, but does not generate a finished blank crossword puzzle to solve.
Works in an async runtime.
use crossword_generator::{crossword::Crossword, generator::{CrosswordGenerationRequest, CrosswordGenerator, CrosswordGeneratorSettings}, word::Word};
use tokio_stream::StreamExt;
fn print_crossword(cw: &Crossword<u8, String>)
{
let table = cw.generate_char_table();
println!(" {} ", vec!['-'; table[0].len() * 2 - 1].into_iter().collect::<String>());
for i in 0..table.len()
{
print!("|");
for j in 0..table[0].len()
{
print!("{}", (if table[i][j] != 0 {table[i][j]} else {32}) as char);
if j != table[0].len() - 1 { print!(" "); }
}
println!("|");
}
println!(" {} ", vec!['-'; table[0].len() * 2 - 1].into_iter().collect::<String>());
}
#[tokio::main]
async fn main()
{
let mut generator = CrosswordGenerator::<u8, String>::default();
generator.settings = CrosswordGeneratorSettings::default();
generator.words = vec!["hello", "world", "foo", "raw"].into_iter().map(|s| Word::new(s.to_lowercase(), None)).collect();
let mut str = generator.crossword_stream(|s| String::from_utf8(s.to_owned()).expect("The word is not in proper utf8 format"));
str.request_crossword(CrosswordGenerationRequest::All).await;
while let Some(cw) = str.next().await
{
print_crossword(&cw);
println!("");
}
}