keep max rounds around

This commit is contained in:
ntr 2019-06-10 20:07:12 +10:00
parent f22a033230
commit 9a6d75486e
2 changed files with 18 additions and 10 deletions

View File

@ -37,9 +37,9 @@ function Instance(args) {
if (!instance) return false; if (!instance) return false;
const instanceClasses = `instance ${nav === 'constructs' ? 'constructs-visible' : ''}`; const instanceClasses = `instance ${nav === 'constructs' ? 'constructs-visible' : ''}`;
const lobbyInfo = (instance.phase === 'Lobby') const lobbyInfo = (instance.phase === 'InProgress')
? <ScoreBoard /> ? null
: null; : <ScoreBoard />;
return ( return (
<main class={instanceClasses} onMouseOver={() => setInfo(null)} > <main class={instanceClasses} onMouseOver={() => setInfo(null)} >

View File

@ -101,6 +101,7 @@ pub struct Instance {
open: bool, open: bool,
max_players: usize, max_players: usize,
max_rounds: usize,
password: Option<String>, password: Option<String>,
time_control: TimeControl, time_control: TimeControl,
@ -120,6 +121,7 @@ impl Instance {
phase: InstancePhase::Lobby, phase: InstancePhase::Lobby,
open: true, open: true,
max_players: 2, max_players: 2,
max_rounds: 5,
name: String::new(), name: String::new(),
time_control: TimeControl::Standard, time_control: TimeControl::Standard,
password: None, password: None,
@ -137,6 +139,7 @@ impl Instance {
phase: InstancePhase::InProgress, phase: InstancePhase::InProgress,
open: false, open: false,
max_players: 0, max_players: 0,
max_rounds: 5,
time_control: TimeControl::Standard, time_control: TimeControl::Standard,
name: "Global Matchmaking".to_string(), name: "Global Matchmaking".to_string(),
password: None, password: None,
@ -199,6 +202,11 @@ impl Instance {
self self
} }
fn set_max_rounds(mut self, rounds: usize) -> Instance {
self.max_rounds = rounds;
self
}
fn add_bots(mut self) -> Instance { fn add_bots(mut self) -> Instance {
self.open = false; self.open = false;
iter::repeat_with(|| { iter::repeat_with(|| {
@ -355,11 +363,6 @@ impl Instance {
return false; return false;
} }
// both players afk
if self.players.iter().all(|p| p.wins == 0) {
return true;
}
// tennis // tennis
for player in self.players.iter() { for player in self.players.iter() {
if player.wins >= 4 && player.wins >= player.losses + 2 { if player.wins >= 4 && player.wins >= player.losses + 2 {
@ -368,6 +371,11 @@ impl Instance {
} }
} }
// both players afk
if self.players.iter().all(|p| p.wins == 0) {
return true;
}
return false; return false;
// boN // boN
@ -712,6 +720,7 @@ pub fn instance_new(params: InstanceLobbyParams, tx: &mut Transaction, account:
let mut instance = match params.pve { let mut instance = match params.pve {
true => Instance::new() true => Instance::new()
.set_time_control(TimeControl::Practice) .set_time_control(TimeControl::Practice)
.set_max_rounds(10)
.set_name(params.name)? .set_name(params.name)?
.add_bots(), .add_bots(),
@ -798,8 +807,7 @@ mod tests {
instance.player_ready(player_account).unwrap(); instance.player_ready(player_account).unwrap();
assert_eq!(instance.phase, InstancePhase::Finished); assert_eq!(instance.phase, InstancePhase::Finished);
println!("{:#?}", instance); assert!(instance.players.iter().any(|p| p.wins as usize == instance.max_rounds / 2 + 1));
// assert!(instance.players.iter().any(|p| p.wins as usize == instance.max_rounds / 2 + 1));
} }
#[test] #[test]