Use variables directly in format expressions (Clippy lint)
This commit is contained in:
parent
ae4f671740
commit
bed45135d5
3 changed files with 20 additions and 21 deletions
14
src/game.rs
14
src/game.rs
|
@ -20,7 +20,7 @@ pub fn get_count_for_value(value: Value) -> u32 {
|
||||||
2 | 3 | 4 => 2,
|
2 | 3 | 4 => 2,
|
||||||
5 => 1,
|
5 => 1,
|
||||||
_ => {
|
_ => {
|
||||||
panic!("Unexpected value: {}", value);
|
panic!("Unexpected value: {value}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,11 +78,11 @@ impl CardCounts {
|
||||||
impl fmt::Display for CardCounts {
|
impl fmt::Display for CardCounts {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
for &color in COLORS.iter() {
|
for &color in COLORS.iter() {
|
||||||
write!(f, "{}: ", color)?;
|
write!(f, "{color}: ")?;
|
||||||
for &value in VALUES.iter() {
|
for &value in VALUES.iter() {
|
||||||
let count = self.get_count(&Card::new(color, value));
|
let count = self.get_count(&Card::new(color, value));
|
||||||
let total = get_count_for_value(value);
|
let total = get_count_for_value(value);
|
||||||
write!(f, "{}/{} {}s", count, total, value)?;
|
write!(f, "{count}/{total} {value}s")?;
|
||||||
if value != FINAL_VALUE {
|
if value != FINAL_VALUE {
|
||||||
f.write_str(", ")?;
|
f.write_str(", ")?;
|
||||||
}
|
}
|
||||||
|
@ -188,10 +188,10 @@ impl fmt::Display for Hinted {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Hinted::Color(color) => {
|
Hinted::Color(color) => {
|
||||||
write!(f, "{}", color)
|
write!(f, "{color}")
|
||||||
}
|
}
|
||||||
Hinted::Value(value) => {
|
Hinted::Value(value) => {
|
||||||
write!(f, "{}", value)
|
write!(f, "{value}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -537,9 +537,9 @@ impl fmt::Display for GameState {
|
||||||
f.write_str("======\n")?;
|
f.write_str("======\n")?;
|
||||||
for player in self.board.get_players() {
|
for player in self.board.get_players() {
|
||||||
let hand = &self.hands.get(&player).unwrap();
|
let hand = &self.hands.get(&player).unwrap();
|
||||||
write!(f, "player {}:", player)?;
|
write!(f, "player {player}:")?;
|
||||||
for card in hand.iter() {
|
for card in hand.iter() {
|
||||||
write!(f, " {}", card)?;
|
write!(f, " {card}")?;
|
||||||
}
|
}
|
||||||
f.write_str("\n")?;
|
f.write_str("\n")?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,7 +268,7 @@ impl fmt::Display for SimpleCardInfo {
|
||||||
//}
|
//}
|
||||||
for &value in &VALUES {
|
for &value in &VALUES {
|
||||||
if self.value_info.is_possible(value) {
|
if self.value_info.is_possible(value) {
|
||||||
write!(string, "{}", value).unwrap();
|
write!(string, "{value}").unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.pad(&string)
|
f.pad(&string)
|
||||||
|
@ -304,7 +304,7 @@ impl CardPossibilityTable {
|
||||||
let weight = self
|
let weight = self
|
||||||
.possible
|
.possible
|
||||||
.get_mut(card)
|
.get_mut(card)
|
||||||
.unwrap_or_else(|| panic!("Decrementing weight for impossible card: {}", card));
|
.unwrap_or_else(|| panic!("Decrementing weight for impossible card: {card}"));
|
||||||
*weight -= 1;
|
*weight -= 1;
|
||||||
*weight == 0
|
*weight == 0
|
||||||
};
|
};
|
||||||
|
@ -401,7 +401,7 @@ impl CardInfo for CardPossibilityTable {
|
||||||
impl fmt::Display for CardPossibilityTable {
|
impl fmt::Display for CardPossibilityTable {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
for (card, weight) in &self.possible {
|
for (card, weight) in &self.possible {
|
||||||
write!(f, "{} {}, ", weight, card)?;
|
write!(f, "{weight} {card}, ")?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -34,7 +34,7 @@ impl log::Log for SimpleLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_usage(program: &str, opts: Options) {
|
fn print_usage(program: &str, opts: Options) {
|
||||||
print!("{}", opts.usage(&format!("Usage: {} [options]", program)));
|
print!("{}", opts.usage(&format!("Usage: {program} [options]")));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -115,7 +115,7 @@ fn main() {
|
||||||
"error" => log::LogLevelFilter::Error,
|
"error" => log::LogLevelFilter::Error,
|
||||||
_ => {
|
_ => {
|
||||||
print_usage(&program, opts);
|
print_usage(&program, opts);
|
||||||
panic!("Unexpected log level argument {}", log_level_str);
|
panic!("Unexpected log level argument {log_level_str}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ fn sim_games(
|
||||||
4 => 4,
|
4 => 4,
|
||||||
5 => 4,
|
5 => 4,
|
||||||
_ => {
|
_ => {
|
||||||
panic!("There should be 2 to 5 players, not {}", n_players);
|
panic!("There should be 2 to 5 players, not {n_players}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ fn sim_games(
|
||||||
"info" => Box::new(strategies::information::InformationStrategyConfig::new())
|
"info" => Box::new(strategies::information::InformationStrategyConfig::new())
|
||||||
as Box<dyn strategy::GameStrategyConfig + Sync>,
|
as Box<dyn strategy::GameStrategyConfig + Sync>,
|
||||||
_ => {
|
_ => {
|
||||||
panic!("Unexpected strategy argument {}", strategy_str);
|
panic!("Unexpected strategy argument {strategy_str}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
simulator::simulate(
|
simulator::simulate(
|
||||||
|
@ -206,13 +206,12 @@ fn get_results_table() -> String {
|
||||||
let n_threads = 8;
|
let n_threads = 8;
|
||||||
|
|
||||||
let intro = format!(
|
let intro = format!(
|
||||||
"On the first {} seeds, we have these scores and win rates (average ± standard error):\n\n",
|
"On the first {n_trials} seeds, we have these scores and win rates (average ± standard error):\n\n"
|
||||||
n_trials
|
|
||||||
);
|
);
|
||||||
let format_name = |x| format!(" {:7} ", x);
|
let format_name = |x| format!(" {x:7} ");
|
||||||
let format_players = |x| format!(" {}p ", x);
|
let format_players = |x| format!(" {x}p ");
|
||||||
let format_percent = |x, stderr| format!(" {:05.2} ± {:.2} % ", x, stderr);
|
let format_percent = |x, stderr| format!(" {x:05.2} ± {stderr:.2} % ");
|
||||||
let format_score = |x, stderr| format!(" {:07.4} ± {:.4} ", x, stderr);
|
let format_score = |x, stderr| format!(" {x:07.4} ± {stderr:.4} ");
|
||||||
let space = String::from(" ");
|
let space = String::from(" ");
|
||||||
let dashes = String::from("---------");
|
let dashes = String::from("---------");
|
||||||
let dashes_long = String::from("------------------");
|
let dashes_long = String::from("------------------");
|
||||||
|
@ -288,7 +287,7 @@ time cargo run --release -- --write-results-table
|
||||||
let readme_init = {
|
let readme_init = {
|
||||||
let parts = readme_contents.splitn(2, separator).collect::<Vec<_>>();
|
let parts = readme_contents.splitn(2, separator).collect::<Vec<_>>();
|
||||||
if parts.len() != 2 {
|
if parts.len() != 2 {
|
||||||
panic!("{} has been modified in the Results section!", readme);
|
panic!("{readme} has been modified in the Results section!");
|
||||||
}
|
}
|
||||||
parts[0]
|
parts[0]
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue