mirror of
https://github.com/tig-pool-nk/tig-monorepo.git
synced 2026-02-21 17:17:22 +08:00
Add clone trait and pub qualifiers to tig-challenges.
This commit is contained in:
parent
afe04c7233
commit
f4c233aeb4
@ -33,12 +33,12 @@ impl crate::DifficultyTrait<2> for Difficulty {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Solution {
|
||||
pub sub_solutions: Vec<SubSolution>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct SubSolution {
|
||||
pub items: Vec<usize>,
|
||||
}
|
||||
@ -53,14 +53,14 @@ impl TryFrom<Map<String, Value>> for Solution {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Challenge {
|
||||
pub seed: [u8; 32],
|
||||
pub difficulty: Difficulty,
|
||||
pub sub_instances: Vec<SubInstance>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct SubInstance {
|
||||
pub seed: [u8; 32],
|
||||
pub difficulty: Difficulty,
|
||||
@ -135,7 +135,7 @@ impl crate::ChallengeTrait<Solution, Difficulty, 2> for Challenge {
|
||||
}
|
||||
|
||||
impl SubInstance {
|
||||
fn generate_instance(
|
||||
pub fn generate_instance(
|
||||
rng: &mut SmallRng,
|
||||
seed: [u8; 32],
|
||||
difficulty: &Difficulty,
|
||||
@ -335,7 +335,7 @@ impl SubInstance {
|
||||
})
|
||||
}
|
||||
|
||||
fn verify_solution(&self, solution: &SubSolution) -> Result<u32> {
|
||||
pub fn verify_solution(&self, solution: &SubSolution) -> Result<u32> {
|
||||
let selected_items: HashSet<usize> = solution.items.iter().cloned().collect();
|
||||
if selected_items.len() != solution.items.len() {
|
||||
return Err(anyhow!("Duplicate items selected."));
|
||||
|
||||
@ -41,7 +41,7 @@ impl crate::DifficultyTrait<2> for Difficulty {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Solution {
|
||||
#[serde(with = "bool_vec_as_u8")]
|
||||
pub variables: Vec<bool>,
|
||||
@ -57,7 +57,7 @@ impl TryFrom<Map<String, Value>> for Solution {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Challenge {
|
||||
pub seed: [u8; 32],
|
||||
pub difficulty: Difficulty,
|
||||
|
||||
@ -34,7 +34,7 @@ impl DifficultyTrait<2> for Difficulty {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Solution {
|
||||
pub indexes: Vec<usize>,
|
||||
}
|
||||
@ -49,7 +49,7 @@ impl TryFrom<Map<String, Value>> for Solution {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Challenge {
|
||||
pub seed: [u8; 32],
|
||||
pub difficulty: Difficulty,
|
||||
|
||||
@ -34,12 +34,12 @@ impl crate::DifficultyTrait<2> for Difficulty {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Solution {
|
||||
pub sub_solutions: Vec<SubSolution>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct SubSolution {
|
||||
pub routes: Vec<Vec<usize>>,
|
||||
}
|
||||
@ -54,14 +54,14 @@ impl TryFrom<Map<String, Value>> for Solution {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Challenge {
|
||||
pub seed: [u8; 32],
|
||||
pub difficulty: Difficulty,
|
||||
pub sub_instances: Vec<SubInstance>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct SubInstance {
|
||||
pub seed: [u8; 32],
|
||||
pub difficulty: Difficulty,
|
||||
@ -139,7 +139,7 @@ impl crate::ChallengeTrait<Solution, Difficulty, 2> for Challenge {
|
||||
}
|
||||
|
||||
impl SubInstance {
|
||||
fn generate_instance(
|
||||
pub fn generate_instance(
|
||||
rng: &mut SmallRng,
|
||||
seed: [u8; 32],
|
||||
difficulty: &Difficulty,
|
||||
@ -275,7 +275,7 @@ impl SubInstance {
|
||||
})
|
||||
}
|
||||
|
||||
fn verify_solution(&self, solution: &SubSolution) -> Result<i32> {
|
||||
pub fn verify_solution(&self, solution: &SubSolution) -> Result<i32> {
|
||||
if solution.routes.len() > self.fleet_size {
|
||||
return Err(anyhow!(
|
||||
"Number of routes ({}) exceeds fleet size ({})",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user