use rand::seq::SliceRandom;
pub struct EightBall {
pub answers: Vec<Answer>,
}
impl EightBall {
pub fn new() -> Self {
EightBall {
answers: vec![
Answer::new("It is certain.", AnswerType::Affirmative),
Answer::new("It is decidedly so.", AnswerType::Affirmative),
Answer::new("Without a doubt.", AnswerType::Affirmative),
Answer::new("Yes - definitely.", AnswerType::Affirmative),
Answer::new("You may rely on it.", AnswerType::Affirmative),
Answer::new("As I see it, yes.", AnswerType::Affirmative),
Answer::new("Most likely.", AnswerType::Affirmative),
Answer::new("Outlook good.", AnswerType::Affirmative),
Answer::new("Yes.", AnswerType::Affirmative),
Answer::new("Signs point to yes.", AnswerType::Affirmative),
Answer::new("Reply hazy, try again.", AnswerType::NonCommittal),
Answer::new("Ask again later.", AnswerType::NonCommittal),
Answer::new("Better not tell you now.", AnswerType::NonCommittal),
Answer::new("Cannot predict now.", AnswerType::NonCommittal),
Answer::new("Concentrate and ask again.", AnswerType::NonCommittal),
Answer::new("Don't count on it.", AnswerType::Negative),
Answer::new("My reply is no.", AnswerType::Negative),
Answer::new("My sources say no.", AnswerType::Negative),
Answer::new("Outlook not so good.", AnswerType::Negative),
Answer::new("Very doubtful.", AnswerType::Negative),
],
}
}
pub fn with_answers(answers: Vec<Answer>) -> Self {
EightBall { answers }
}
pub fn ask(&self, _question: &str) -> Option<Answer> {
if self.answers.is_empty() {
return None;
}
Some(*self.answers.choose(&mut rand::thread_rng()).unwrap())
}
}
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone, Hash)]
pub enum AnswerType {
Affirmative,
NonCommittal,
Negative,
}
impl Default for AnswerType {
fn default() -> Self {
AnswerType::Affirmative
}
}
#[derive(Debug, Default, Ord, PartialOrd, Eq, PartialEq, Copy, Clone, Hash)]
pub struct Answer {
pub content: &'static str,
pub answer_type: AnswerType,
}
impl Answer {
pub const fn new(content: &'static str, answer_type: AnswerType) -> Self {
Answer {
content,
answer_type,
}
}
}