1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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,
}
}
}