Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ solver = { path = "crates/solver" }
solvers = { path = "crates/solvers" }
solvers-dto = { path = "crates/solvers-dto" }
testlib = { path = "crates/testlib" }
winner-selection = { path = "crates/winner-selection" }
time = "0.3.37"
tiny-keccak = "2.0.2"
tower = "0.4"
Expand Down
1 change: 1 addition & 0 deletions crates/autopilot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ tower-http = { workspace = true, features = ["trace"] }
tracing = { workspace = true }
url = { workspace = true }
web3 = { workspace = true }
winner-selection = { workspace = true }

[dev-dependencies]
mockall = { workspace = true }
Expand Down
76 changes: 18 additions & 58 deletions crates/autopilot/src/domain/competition/participant.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use {super::Score, crate::infra, std::sync::Arc};
pub use state::{RankType, Unscored};
use {super::Score, crate::infra, ::winner_selection::state, std::sync::Arc};
pub type Scored = state::Scored<Score>;
pub type Ranked = state::Ranked<Score>;

#[derive(Clone)]
pub struct Participant<State = Ranked> {
Expand All @@ -7,27 +10,6 @@ pub struct Participant<State = Ranked> {
state: State,
}

#[derive(Clone)]
pub struct Unscored;

#[derive(Clone)]
pub struct Scored {
pub(super) score: Score,
}

#[derive(Clone)]
pub struct Ranked {
pub(super) rank_type: RankType,
pub(super) score: Score,
}

#[derive(Clone)]
pub enum RankType {
Winner,
NonWinner,
FilteredOut,
}

impl<T> Participant<T> {
pub fn solution(&self) -> &super::Solution {
&self.solution
Expand All @@ -38,51 +20,29 @@ impl<T> Participant<T> {
}
}

impl Participant<Unscored> {
pub fn new(solution: super::Solution, driver: Arc<infra::Driver>) -> Self {
Self {
solution,
driver,
state: Unscored,
}
}
impl<State> state::WithState for Participant<State> {
type State = State;
type WithState<NewState> = Participant<NewState>;

pub fn with_score(self, score: Score) -> Participant<Scored> {
fn with_state<NewState>(self, state: NewState) -> Self::WithState<NewState> {
Participant {
solution: self.solution,
driver: self.driver,
state: Scored { score },
state,
}
}
}

impl Participant<Scored> {
pub fn score(&self) -> Score {
self.state.score
}

pub fn rank(self, rank_type: RankType) -> Participant<Ranked> {
Participant {
solution: self.solution,
driver: self.driver,
state: Ranked {
rank_type,
score: self.state.score,
},
}
fn state(&self) -> &Self::State {
&self.state
}
}

impl Participant<Ranked> {
pub fn score(&self) -> Score {
self.state.score
}

pub fn is_winner(&self) -> bool {
matches!(self.state.rank_type, RankType::Winner)
}

pub fn filtered_out(&self) -> bool {
matches!(self.state.rank_type, RankType::FilteredOut)
impl Participant<Unscored> {
pub fn new(solution: super::Solution, driver: Arc<infra::Driver>) -> Self {
Self {
solution,
driver,
state: Unscored,
}
}
}
Loading
Loading