time control
This commit is contained in:
parent
a3d596a9b2
commit
be427f2271
@ -57,7 +57,7 @@ function Instance(args) {
|
||||
}
|
||||
|
||||
function ScoreBoard() {
|
||||
if (instance.phase !== 'Lobby') return null;
|
||||
if (instance.phase === 'InProgress') return null;
|
||||
|
||||
const players = instance.players.map((p, i) => {
|
||||
const pText = playerText(p);
|
||||
|
||||
@ -56,23 +56,26 @@ class InstanceCreateForm extends Component {
|
||||
return (
|
||||
<div class={classes}>
|
||||
<form>
|
||||
<label>instance name</label>
|
||||
<input
|
||||
class="login-input"
|
||||
type="text"
|
||||
disabled={disabled}
|
||||
value={this.state.name}
|
||||
placeholder="game name"
|
||||
onInput={this.nameInput}
|
||||
/>
|
||||
<label htmlFor="pveSelect">vs CPU</label>
|
||||
<input id="pveSelect"
|
||||
type="checkbox"
|
||||
disabled={disabled}
|
||||
checked={this.state.pve}
|
||||
onChange={this.pveChange}
|
||||
>
|
||||
</input>
|
||||
<fieldset>
|
||||
<legend>New Instance</legend>
|
||||
<label>instance name</label>
|
||||
<input
|
||||
class="login-input"
|
||||
type="text"
|
||||
disabled={disabled}
|
||||
value={this.state.name}
|
||||
placeholder="game name"
|
||||
onInput={this.nameInput}
|
||||
/>
|
||||
<label htmlFor="pveSelect">Practice Mode - Bo10, vs CPU, 2x turn time</label>
|
||||
<input id="pveSelect"
|
||||
type="checkbox"
|
||||
disabled={disabled}
|
||||
checked={this.state.pve}
|
||||
onChange={this.pveChange}
|
||||
>
|
||||
</input>
|
||||
</fieldset>
|
||||
</form>
|
||||
<button
|
||||
onClick={this.handleSubmit}
|
||||
|
||||
@ -16,7 +16,7 @@ use rpc::{GameStateParams, GameSkillParams};
|
||||
use construct::{Construct};
|
||||
use skill::{Skill, Effect, Cast, Resolution, Event, resolution_steps};
|
||||
use player::{Player};
|
||||
use instance::{instance_game_finished};
|
||||
use instance::{TimeControl, instance_game_finished};
|
||||
|
||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||
pub enum Phase {
|
||||
@ -36,6 +36,7 @@ pub struct Game {
|
||||
pub stack: Vec<Cast>,
|
||||
pub resolved: Vec<Resolution>,
|
||||
pub instance: Option<Uuid>,
|
||||
time_control: TimeControl,
|
||||
phase_end: DateTime<Utc>,
|
||||
phase_start: DateTime<Utc>,
|
||||
}
|
||||
@ -51,11 +52,17 @@ impl Game {
|
||||
stack: vec![],
|
||||
resolved: vec![],
|
||||
instance: None,
|
||||
time_control: TimeControl::Standard,
|
||||
phase_end: Utc::now(),
|
||||
phase_start: Utc::now(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn set_time_control(&mut self, tc: TimeControl) -> &mut Game {
|
||||
self.time_control = tc;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_player_num(&mut self, size: usize) -> &mut Game {
|
||||
self.player_num = size;
|
||||
self
|
||||
@ -150,10 +157,10 @@ impl Game {
|
||||
}
|
||||
|
||||
fn skill_phase_start(mut self, num_resolutions: usize) -> Game {
|
||||
let resolution_animation_ms = num_resolutions * 2500;
|
||||
let phase_add_time_ms = 60000 + resolution_animation_ms;
|
||||
let resolution_animation_ms = num_resolutions as i64 * 2500;
|
||||
let phase_add_time_ms = self.time_control.game_time_seconds() * 1000 + resolution_animation_ms;
|
||||
self.phase_start = Utc::now()
|
||||
.checked_add_signed(Duration::milliseconds(resolution_animation_ms as i64))
|
||||
.checked_add_signed(Duration::milliseconds(resolution_animation_ms))
|
||||
.expect("could not set phase start");
|
||||
self.phase_end = Utc::now()
|
||||
.checked_add_signed(Duration::milliseconds(phase_add_time_ms as i64))
|
||||
|
||||
@ -30,12 +30,6 @@ enum InstancePhase {
|
||||
Finished,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||
enum Format {
|
||||
Standard,
|
||||
RoundRobin,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct Round {
|
||||
game_id: Option<Uuid>,
|
||||
@ -48,6 +42,28 @@ impl Round {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Copy,Serialize,Deserialize)]
|
||||
pub enum TimeControl {
|
||||
Standard,
|
||||
Practice,
|
||||
}
|
||||
|
||||
impl TimeControl {
|
||||
fn vbox_time_seconds(&self) -> i64 {
|
||||
match self {
|
||||
TimeControl::Standard => 120,
|
||||
TimeControl::Practice => 240,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn game_time_seconds(&self) -> i64 {
|
||||
match self {
|
||||
TimeControl::Standard => 60,
|
||||
TimeControl::Practice => 120,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct Instance {
|
||||
id: Uuid,
|
||||
@ -60,12 +76,11 @@ pub struct Instance {
|
||||
max_players: usize,
|
||||
max_rounds: usize,
|
||||
password: Option<String>,
|
||||
time_control: TimeControl,
|
||||
|
||||
phase: InstancePhase,
|
||||
phase_end: DateTime<Utc>,
|
||||
phase_start: DateTime<Utc>,
|
||||
|
||||
format: Format,
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
@ -79,12 +94,12 @@ impl Instance {
|
||||
max_players: 2,
|
||||
max_rounds: 5,
|
||||
name: String::new(),
|
||||
time_control: TimeControl::Standard,
|
||||
password: None,
|
||||
phase_start: Utc::now(),
|
||||
phase_end: Utc::now()
|
||||
.checked_add_signed(Duration::minutes(5))
|
||||
.expect("could not set phase end"),
|
||||
format: Format::Standard,
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,12 +112,11 @@ impl Instance {
|
||||
open: false,
|
||||
max_players: 0,
|
||||
max_rounds: 5,
|
||||
time_control: TimeControl::Standard,
|
||||
name: "Global Matchmaking".to_string(),
|
||||
password: None,
|
||||
phase_start: Utc::now(),
|
||||
phase_end: Utc::now(),
|
||||
|
||||
format: Format::Standard,
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,8 +165,13 @@ impl Instance {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn set_format(mut self, format: Format) -> Instance {
|
||||
self.format = format;
|
||||
fn set_time_control(mut self, tc: TimeControl) -> Instance {
|
||||
self.time_control = tc;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_max_rounds(mut self, rounds: usize) -> Instance {
|
||||
self.max_rounds = rounds;
|
||||
self
|
||||
}
|
||||
|
||||
@ -265,6 +284,7 @@ impl Instance {
|
||||
game
|
||||
.set_player_num(2)
|
||||
.set_player_constructs(3)
|
||||
.set_time_control(self.time_control)
|
||||
.set_instance(self.id);
|
||||
|
||||
for player in self.players.clone().into_iter() {
|
||||
@ -293,7 +313,7 @@ impl Instance {
|
||||
self.phase = InstancePhase::InProgress;
|
||||
self.phase_start = Utc::now();
|
||||
self.phase_end = Utc::now()
|
||||
.checked_add_signed(Duration::seconds(120))
|
||||
.checked_add_signed(Duration::seconds(self.time_control.vbox_time_seconds()))
|
||||
.expect("could not set phase end");
|
||||
|
||||
|
||||
@ -309,16 +329,11 @@ impl Instance {
|
||||
}
|
||||
|
||||
fn finish_condition(&self) -> bool {
|
||||
match self.format {
|
||||
// bo5 standard
|
||||
// OR condition is for forfeitures
|
||||
Format::Standard =>
|
||||
self.players.iter().any(|p| p.wins as usize >= self.max_rounds / 2 + 1)
|
||||
|| self.rounds.len() == self.max_rounds,
|
||||
|
||||
// everybody plays each other once
|
||||
Format::RoundRobin => self.rounds.len() == self.players.len() - 1,
|
||||
}
|
||||
// boN standard
|
||||
// OR condition is for forfeitures
|
||||
self.players.iter()
|
||||
.any(|p| p.wins as usize >= self.max_rounds / 2 + 1)
|
||||
|| self.rounds.len() == self.max_rounds
|
||||
}
|
||||
|
||||
fn finish(&mut self) -> &mut Instance {
|
||||
@ -625,6 +640,7 @@ pub fn instances_need_upkeep(tx: &mut Transaction) -> Result<Vec<Instance>, Erro
|
||||
pub fn instance_new(params: InstanceLobbyParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
|
||||
let mut instance = match params.pve {
|
||||
true => Instance::new()
|
||||
.set_time_control(TimeControl::Practice)
|
||||
.set_name(params.name)?
|
||||
.add_bots(),
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user