fixed bots

This commit is contained in:
Mashy 2019-07-22 19:55:57 +10:00
parent 36ce1385da
commit 8a60a181d1
2 changed files with 21 additions and 4 deletions

View File

@ -136,12 +136,19 @@ impl Player {
} }
// get 2 colours and something else // get 2 colours and something else
if self.vbox.free[0].len() < 2 { let free_colours = self.vbox.free[0].iter().fold(0, |count, item| {
match item.is_some() {
true => count + 1,
false => count
}
});
if free_colours < 2 {
break; break;
} }
self.vbox_accept(0, 0).expect("could't accept colour 0"); debug!("Looping");
self.vbox_accept(0, 0).expect("could't accept colour 1"); self.bot_vbox_accept(0).expect("could't accept colour 0");
self.vbox_accept(group_i, 0).expect("could't accept group 0"); self.bot_vbox_accept(0).expect("could't accept colour 1");
self.bot_vbox_accept(group_i).expect("could't accept group 0");
} }
// info!("{:?}", self.vbox.bound); // info!("{:?}", self.vbox.bound);
@ -168,6 +175,11 @@ impl Player {
Ok(self) Ok(self)
} }
pub fn bot_vbox_accept(&mut self, group: usize) -> Result<&mut Player, Error> {
self.vbox.bot_accept(group)?;
Ok(self)
}
pub fn vbox_accept(&mut self, group: usize, index: usize) -> Result<&mut Player, Error> { pub fn vbox_accept(&mut self, group: usize, index: usize) -> Result<&mut Player, Error> {
self.vbox.accept(group, index)?; self.vbox.accept(group, index)?;
Ok(self) Ok(self)

View File

@ -128,6 +128,11 @@ impl Vbox {
Ok(self) Ok(self)
} }
pub fn bot_accept(&mut self, i: usize) -> Result<&mut Vbox, Error> {
let buy_index = self.free[i].iter().position(|item| item.is_some());
self.accept(i, buy_index.expect("no valid buys"))
}
pub fn reclaim(&mut self, i: usize) -> Result<&mut Vbox, Error> { pub fn reclaim(&mut self, i: usize) -> Result<&mut Vbox, Error> {
self.bound.get(i).ok_or(format_err!("no item at index {:?}", i))?; self.bound.get(i).ok_or(format_err!("no item at index {:?}", i))?;
let reclaimed = self.bound.remove(i); let reclaimed = self.bound.remove(i);