fix round robin

This commit is contained in:
ntr 2019-05-29 16:52:53 +10:00
parent 8456956f8b
commit cb49552927

View File

@ -287,7 +287,7 @@ impl Instance {
} }
fn next_round(&mut self) -> &mut Instance { fn next_round(&mut self) -> &mut Instance {
if self.win_condition() { if self.finish_condition() {
return self.finish(); return self.finish();
} }
@ -309,10 +309,13 @@ impl Instance {
self self
} }
fn win_condition(&self) -> bool { fn finish_condition(&self) -> bool {
match self.format { match self.format {
// bo5 standard
Format::Standard => self.players.iter().any(|p| p.score.wins > 2), Format::Standard => self.players.iter().any(|p| p.score.wins > 2),
Format::RoundRobin => self.rounds.len() == self.players.len() / 2,
// everybody plays each other once
Format::RoundRobin => self.rounds.len() == self.players.len() - 1,
} }
} }
@ -775,7 +778,7 @@ mod tests {
assert_eq!(instance.phase, InstancePhase::Finished); assert_eq!(instance.phase, InstancePhase::Finished);
assert_eq!(instance.rounds[0].len(), 8); assert_eq!(instance.rounds[0].len(), 8);
assert_eq!(instance.rounds.len(), 8); assert_eq!(instance.rounds.len(), 15);
} }
#[test] #[test]