Skip to content

Commit

Permalink
Also check the inital assignment for duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
julianschuler committed Mar 8, 2025
1 parent 3499176 commit f2f817a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
20 changes: 14 additions & 6 deletions tools/pepsi/src/deploy_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use argument_parsers::{
use nao::Network;
use repository::Repository;

use crate::player_number::{player_number, Arguments};
use crate::player_number::{check_for_duplication, player_number, Arguments};

#[derive(Deserialize)]
pub struct DeployConfig {
Expand Down Expand Up @@ -62,8 +62,8 @@ impl DeployConfig {
branch_name
}

pub fn playing_naos(&self) -> Vec<NaoAddress> {
self.assignments().into_values().collect()
pub fn playing_naos(&self) -> Result<Vec<NaoAddress>> {
Ok(self.assignments()?.into_values().collect())
}

pub fn all_naos(&self) -> Vec<NaoAddress> {
Expand All @@ -84,7 +84,7 @@ impl DeployConfig {
player_number(
Arguments {
assignments: self
.assignments()
.assignments()?
.into_iter()
.map(|(player_number, nao_address)| {
nao_address
Expand Down Expand Up @@ -120,7 +120,15 @@ impl DeployConfig {
Ok(())
}

fn assignments(&self) -> HashMap<PlayerNumber, NaoAddress> {
fn assignments(&self) -> Result<HashMap<PlayerNumber, NaoAddress>> {
let inital_assignments = self
.assignments
.iter()
.copied()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()?;
check_for_duplication(&inital_assignments)?;

let mut assignments: HashMap<_, _> = self
.assignments
.iter()
Expand All @@ -131,7 +139,7 @@ impl DeployConfig {
assignments.insert(substitution.player_number, substitution.nao_address);
}

assignments
Ok(assignments)
}
}

Expand Down
6 changes: 3 additions & 3 deletions tools/pepsi/src/player_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ pub async fn player_number(arguments: Arguments, repository: &Repository) -> Res
Ok(())
}

fn check_for_duplication(assignments: &[NaoNumberPlayerAssignment]) -> Result<()> {
// Check if two NaoNumbers are assigned to the same PlayerNumber
// or if a NaoNumber is assigned to multiple PlayerNumbers
/// Check if two NaoNumbers are assigned to the same PlayerNumber
/// or if a NaoNumber is assigned to multiple PlayerNumbers
pub fn check_for_duplication(assignments: &[NaoNumberPlayerAssignment]) -> Result<()> {
let mut existing_player_numbers = HashSet::new();
let mut existing_nao_numbers = HashSet::new();

Expand Down
2 changes: 1 addition & 1 deletion tools/pepsi/src/pre_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub async fn pre_game(arguments: Arguments, repository: &Repository) -> Result<(
config.recording_intervals = HashMap::from_iter(recording_intervals.iter().cloned());
}

let playing_naos = config.playing_naos();
let playing_naos = config.playing_naos()?;
let naos = if let Some(naos) = &arguments.pre_game.naos {
for nao in naos {
if !playing_naos.contains(nao) {
Expand Down

0 comments on commit f2f817a

Please sign in to comment.