Commit ece670ec authored by Éloïs's avatar Éloïs
Browse files

exo1: solution

parent 91835824
use std::cmp::Ordering;
pub struct Ia {
// Put your fields here
min: u32,
max: u32,
}
impl Default for Ia {
fn default() -> Self {
// Init your IA here
todo!()
Self { min: 0, max: 0 }
}
}
impl Ia {
pub fn think(&mut self, message: Message) -> u32 {
// Code your intelligence here
todo!()
match message {
Message::NewGame { max } => {
self.min = 1;
self.max = max;
}
Message::Response(ord) => match ord {
Ordering::Less => {
self.max = ((self.max - self.min) / 2) + self.min;
}
Ordering::Equal => unreachable!(),
Ordering::Greater => {
self.min = ((self.max - self.min) / 2) + self.min;
}
},
}
((self.max - self.min) / 2) + self.min
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment