Clean up formatting code
This commit is contained in:
parent
d65b7616f1
commit
91fc4c279d
4 changed files with 29 additions and 31 deletions
48
src/game.rs
48
src/game.rs
|
@ -78,11 +78,11 @@ impl CardCounts {
|
|||
impl fmt::Display for CardCounts {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
for &color in COLORS.iter() {
|
||||
f.write_str(&format!("{}: ", color,))?;
|
||||
write!(f, "{}: ", color)?;
|
||||
for &value in VALUES.iter() {
|
||||
let count = self.get_count(&Card::new(color, value));
|
||||
let total = get_count_for_value(value);
|
||||
f.write_str(&format!("{}/{} {}s", count, total, value))?;
|
||||
write!(f, "{}/{} {}s", count, total, value)?;
|
||||
if value != FINAL_VALUE {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
|
@ -123,9 +123,7 @@ impl Discard {
|
|||
}
|
||||
impl fmt::Display for Discard {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// f.write_str(&format!(
|
||||
// "{}", self.cards,
|
||||
// ))?;
|
||||
// write!(f, "{}", self.cards)?;
|
||||
write!(f, "{}", self.counts)
|
||||
}
|
||||
}
|
||||
|
@ -387,35 +385,35 @@ impl BoardState {
|
|||
impl fmt::Display for BoardState {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.is_over() {
|
||||
f.write_str(&format!("Turn {} (GAME ENDED):\n", self.turn))?;
|
||||
writeln!(f, "Turn {} (GAME ENDED):", self.turn)?;
|
||||
} else {
|
||||
f.write_str(&format!(
|
||||
"Turn {} (Player {}'s turn):\n",
|
||||
self.turn, self.player
|
||||
))?;
|
||||
writeln!(f, "Turn {} (Player {}'s turn):", self.turn, self.player)?;
|
||||
}
|
||||
|
||||
f.write_str(&format!("{} cards remaining in deck\n", self.deck_size))?;
|
||||
writeln!(f, "{} cards remaining in deck", self.deck_size)?;
|
||||
if self.deck_size == 0 {
|
||||
f.write_str(&format!(
|
||||
"Deck is empty. {} turns remaining in game\n",
|
||||
writeln!(
|
||||
f,
|
||||
"Deck is empty. {} turns remaining in game",
|
||||
self.deckless_turns_remaining
|
||||
))?;
|
||||
)?;
|
||||
}
|
||||
f.write_str(&format!(
|
||||
"{}/{} hints remaining\n",
|
||||
writeln!(
|
||||
f,
|
||||
"{}/{} hints remaining",
|
||||
self.hints_remaining, self.hints_total
|
||||
))?;
|
||||
f.write_str(&format!(
|
||||
"{}/{} lives remaining\n",
|
||||
)?;
|
||||
writeln!(
|
||||
f,
|
||||
"{}/{} lives remaining",
|
||||
self.lives_remaining, self.lives_total
|
||||
))?;
|
||||
)?;
|
||||
f.write_str("Fireworks:\n")?;
|
||||
for &color in COLORS.iter() {
|
||||
f.write_str(&format!(" {}\n", self.get_firework(color)))?;
|
||||
writeln!(f, " {}", self.get_firework(color))?;
|
||||
}
|
||||
f.write_str("Discard:\n")?;
|
||||
f.write_str(&format!("{}\n", self.discard))?;
|
||||
writeln!(f, "{}\n", self.discard)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -550,16 +548,16 @@ impl fmt::Display for GameState {
|
|||
f.write_str("======\n")?;
|
||||
for player in self.board.get_players() {
|
||||
let hand = &self.hands.get(&player).unwrap();
|
||||
f.write_str(&format!("player {}:", player))?;
|
||||
write!(f, "player {}:", player)?;
|
||||
for card in hand.iter() {
|
||||
f.write_str(&format!(" {}", card))?;
|
||||
write!(f, " {}", card)?;
|
||||
}
|
||||
f.write_str("\n")?;
|
||||
}
|
||||
f.write_str("======\n")?;
|
||||
f.write_str("Board:\n")?;
|
||||
f.write_str("======\n")?;
|
||||
f.write_str(&format!("{}", self.board))?;
|
||||
write!(f, "{}", self.board)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::cmp::Eq;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::convert::From;
|
||||
use std::fmt;
|
||||
use std::fmt::{self, Write};
|
||||
use std::hash::Hash;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::slice;
|
||||
|
@ -268,7 +268,7 @@ impl fmt::Display for SimpleCardInfo {
|
|||
//}
|
||||
for &value in &VALUES {
|
||||
if self.value_info.is_possible(value) {
|
||||
string.push_str(&format!("{}", value));
|
||||
write!(string, "{}", value).unwrap();
|
||||
}
|
||||
}
|
||||
f.pad(&string)
|
||||
|
@ -401,7 +401,7 @@ impl CardInfo for CardPossibilityTable {
|
|||
impl fmt::Display for CardPossibilityTable {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
for (card, weight) in &self.possible {
|
||||
f.write_str(&format!("{} {}, ", weight, card))?;
|
||||
write!(f, "{} {}, ", weight, card)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ impl fmt::Display for Histogram {
|
|||
let mut keys = self.hist.keys().collect::<Vec<_>>();
|
||||
keys.sort();
|
||||
for val in keys {
|
||||
f.write_str(&format!("\n{}: {}", val, self.get_count(val),))?;
|
||||
write!(f, "\n{}: {}", val, self.get_count(val))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -159,14 +159,14 @@ impl CardPossibilityPartition {
|
|||
n_partitions += 1;
|
||||
}
|
||||
|
||||
// let mut s : String = "Partition: |".to_string();
|
||||
// let mut s: String = "Partition: |".to_string();
|
||||
// for i in 0..n_partitions {
|
||||
// for (card, block) in partition.iter() {
|
||||
// if *block == i {
|
||||
// s = s + &format!(" {}", card);
|
||||
// }
|
||||
// }
|
||||
// s = s + &format!(" |");
|
||||
// s.push_str(" |");
|
||||
// }
|
||||
// debug!("{}", s);
|
||||
|
||||
|
|
Loading…
Reference in a new issue