formats
This commit is contained in:
parent
7f422ce8e8
commit
ff496cd537
@ -33,6 +33,7 @@ enum InstancePhase {
|
||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||
enum Format {
|
||||
Standard,
|
||||
RoundRobin,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
@ -45,18 +46,21 @@ struct Round {
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct Instance {
|
||||
id: Uuid,
|
||||
pub name: String,
|
||||
|
||||
players: Vec<Player>,
|
||||
phase: InstancePhase,
|
||||
rounds: Vec<Vec<Round>>,
|
||||
|
||||
open: bool,
|
||||
max_players: usize,
|
||||
max_rounds: usize,
|
||||
password: Option<String>,
|
||||
pub name: String,
|
||||
|
||||
format: Format,
|
||||
phase: InstancePhase,
|
||||
phase_end: DateTime<Utc>,
|
||||
phase_start: DateTime<Utc>,
|
||||
|
||||
format: Format,
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
@ -74,7 +78,7 @@ impl Instance {
|
||||
phase_end: Utc::now(),
|
||||
phase_start: Utc::now(),
|
||||
|
||||
format: Format::Standard,
|
||||
format: Format::RoundRobin,
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,12 +149,8 @@ impl Instance {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn set_max_rounds(mut self, rounds: usize) -> Result<Instance, Error> {
|
||||
if rounds == 0 {
|
||||
return Err(err_msg("max rounds must be nonzero"));
|
||||
}
|
||||
|
||||
self.max_rounds = rounds;
|
||||
fn set_format(mut self, format: Format) -> Result<Instance, Error> {
|
||||
self.format = format;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
@ -311,7 +311,8 @@ impl Instance {
|
||||
|
||||
fn win_condition(&self) -> bool {
|
||||
match self.format {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
@ -753,7 +754,7 @@ mod tests {
|
||||
fn instance_pve_test() {
|
||||
let mut instance = Instance::new()
|
||||
.set_max_players(16).expect("unable to set max players")
|
||||
.set_max_rounds(2).expect("max rounds failure")
|
||||
.set_format(Format::RoundRobin).expect("format failure")
|
||||
.add_bots();
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
@ -768,12 +769,12 @@ mod tests {
|
||||
|
||||
assert_eq!(instance.phase, InstancePhase::Finished);
|
||||
assert_eq!(instance.rounds[0].len(), 8);
|
||||
assert_eq!(instance.rounds.len(), 2);
|
||||
assert_eq!(instance.rounds.len(), 8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn instance_bot_vbox_test() {
|
||||
let instance = Instance::new();
|
||||
let _instance = Instance::new();
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let _player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
|
||||
@ -823,8 +824,8 @@ mod tests {
|
||||
#[test]
|
||||
fn instance_upkeep_test() {
|
||||
let mut instance = Instance::new()
|
||||
.set_max_players(2)
|
||||
.expect("could not create instance");
|
||||
.set_max_players(2).expect("could not create instance")
|
||||
.set_format(Format::Standard).expect("format err");
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user