Skip to content

Commit

Permalink
some cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiaha committed Aug 17, 2023
1 parent b624ec8 commit e58e99e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ impl TryFrom<&str> for TimeControl {
type Error = &'static str;

fn try_from(s: &str) -> Result<Self, Self::Error> {
let mut result = Err("Unable to parse go parameters.");
if s.is_empty() {
return Ok(TimeControl::Infinite)
}

if s.is_empty() {
return Ok(Self::Infinite);
Expand All @@ -54,14 +56,14 @@ impl TryFrom<&str> for TimeControl {
let mut split = s.split_whitespace();
while let Some(key) = split.next() {
match key {
"infinite" => result = Ok(Self::Infinite),
"infinite" => return Ok(Self::Infinite),
"movetime" => {
result = Ok(Self::FixedDuration(Duration::from_millis(
return Ok(Self::FixedDuration(Duration::from_millis(
Self::parse_next(&mut split)?,
)))
}
"nodes" => result = Ok(Self::FixedNodes(Self::parse_next(&mut split)?)),
"depth" => result = Ok(Self::FixedDepth(Self::parse_next(&mut split)?)),
"nodes" => return Ok(Self::FixedNodes(Self::parse_next(&mut split)?)),
"depth" => return Ok(Self::FixedDepth(Self::parse_next(&mut split)?)),
"wtime" => wtime = Some(Duration::from_millis(Self::parse_next(&mut split)?)),
"btime" => btime = Some(Duration::from_millis(Self::parse_next(&mut split)?)),
"winc" => winc = Some(Duration::from_millis(Self::parse_next(&mut split)?)),
Expand All @@ -76,15 +78,15 @@ impl TryFrom<&str> for TimeControl {
}

if let (Some(wtime), Some(btime)) = (wtime, btime) {
result = Ok(Self::Variable {
return Ok(Self::Variable {
wtime,
btime,
winc,
binc,
moves_to_go,
});
}
result
Err("Unable to parse go parameters.")
}
}

Expand Down

0 comments on commit e58e99e

Please sign in to comment.