Skip to content

Commit

Permalink
Merge branch 'dev' into dev-solver
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfierrog committed May 15, 2024
2 parents 6bdaa8a + 9d9d1f1 commit 996a31f
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 268 deletions.
28 changes: 12 additions & 16 deletions src/database/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ impl fmt::Display for DatabaseError {
if let Some(t) = table {
write!(
f,
"The attribute name '{}' was observed more than once \
while deserializing the schema of table '{}'.",
name, t,
"The attribute name '{name}' was observed more than \
once while deserializing the schema of table '{t}'.",
)
} else {
write!(
f,
"Attempted to build a schema with more than one \
attribute named '{}'.",
name,
attribute named '{name}'.",
)
}
},
Expand All @@ -71,8 +69,7 @@ impl fmt::Display for DatabaseError {
write!(
f,
"Encountered empty attribute name while deserializing \
the schema of table '{}'.",
t,
the schema of table '{t}'.",
)
} else {
write!(
Expand All @@ -87,8 +84,7 @@ impl fmt::Display for DatabaseError {
write!(
f,
"Encountered zero-sized attribute while deserializing \
the schema of table '{}'.",
t,
the schema of table '{t}'.",
)
} else {
write!(
Expand Down Expand Up @@ -117,17 +113,17 @@ impl fmt::Display for DatabaseError {
write!(
f,
"Encountered an attribute with inconsistent datatype \
and size while deserializing the schema of table '{}'. \
The attribute '{}' was found to have size {}, but \
attributes of type '{}' should have a size {}.",
t, name, size, data, rule,
and size while deserializing the schema of table \
'{t}'. The attribute '{name}' was found to have size \
{size}, but attributes of type '{data}' should have a \
size {rule}.",
)
} else {
write!(
f,
"The attribute '{}' was found to have size {}, but \
attributes of type '{}' should have a size {}.",
name, size, data, rule,
"The attribute '{name}' was found to have size {size}, \
but attributes of type '{data}' should have a size \
{rule}.",
)
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/database/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Display for Datatype {
Datatype::ENUM => "Enumeration",
Datatype::BOOL => "Boolean",
};
write!(f, "{}", content)
write!(f, "{content}")
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/game/crossteaser/variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ fn check_variant_pattern(variant: &str) -> Result<(), GameError> {
Err(GameError::VariantMalformed {
game_name: NAME,
hint: format!(
"String does not match the pattern '{}'.",
VARIANT_PATTERN
"String does not match the pattern '{VARIANT_PATTERN}'.",
),
})
} else {
Expand Down
22 changes: 10 additions & 12 deletions src/game/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,31 @@ impl fmt::Display for GameError {
Self::SolverNotFound { input_game_name } => {
write!(
f,
"The variant you specified for the game {} has no solvers \
associated with it.",
input_game_name
"The variant you specified for the game {input_game_name} \
has no solvers associated with it.",
)
},
Self::VariantMalformed { game_name, hint } => {
write!(
f,
"{}\n\nMore information on how the game expects you to \
format variant encodings can be found with 'nova info {}'.",
hint, game_name
"{hint}\n\nMore information on how the game expects you to \
format variant encodings can be found with 'nova info \
{game_name}'.",
)
},
Self::StateMalformed { game_name, hint } => {
write!(
f,
"{}\n\nMore information on how the game expects you to \
format state encodings can be found with 'nova info {}'.",
hint, game_name
"{hint}\n\nMore information on how the game expects you to \
format state encodings can be found with 'nova info \
{game_name}'.",
)
},
Self::InvalidHistory { game_name, hint } => {
write!(
f,
"{}\n\nMore information on the game's rules can be found \
with 'nova info {}'.",
hint, game_name
"{hint}\n\nMore information on the game's rules can be \
found with 'nova info {game_name}'.",
)
},
}
Expand Down
56 changes: 19 additions & 37 deletions src/game/mock/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! #### Authorship
//! - Max Fierro, 3/31/2024 (maxfierro@gmail.com)

use anyhow::anyhow;
use anyhow::bail;
use anyhow::Result;
use petgraph::Direction;
use petgraph::{graph::NodeIndex, Graph};
Expand Down Expand Up @@ -80,14 +80,12 @@ impl<'a> SessionBuilder<'a> {
/// count that is incompatible with existing nodes.
pub fn edge(mut self, from: &'a Node, to: &'a Node) -> Result<Self> {
if let Node::Terminal(_) = from {
Err(anyhow! {
format!(
bail! {
"There was an attempt to add a terminal node on the \
outgoing side of an edge during the construction of the \
game '{}'.",
self.name,
),
})?
}
}

self.update_player_count(from)?;
Expand Down Expand Up @@ -119,14 +117,12 @@ impl<'a> SessionBuilder<'a> {
self.start = Some(index);
Ok(self)
} else {
Err(anyhow! {
format!(
bail! {
"There was an attempt to set the start state of mock game \
'{}', but the indicated start node has not been added to \
the game yet.",
self.name,
),
})?
}
}
}

Expand Down Expand Up @@ -159,15 +155,13 @@ impl<'a> SessionBuilder<'a> {
Node::Terminal(vector) => {
let result = vector.len();
if result == 0 {
Err(anyhow! {
format!(
bail! {
"While constructing the game '{}', there was an \
attempt to add a terminal node with containing no \
utility entries. Games with no players are not \
allowed.",
self.name,
),
})?
}
};
result
},
Expand All @@ -176,31 +170,26 @@ impl<'a> SessionBuilder<'a> {

if finalized {
if new.terminal() && old_count != new_count {
Err(anyhow! {
format!(
bail! {
"While constructing the game '{}', a terminal node was \
added containing {} utility entries, but then a new \
one was added with {} entries. Utility entries must be \
consistent across all terminal nodes.",
self.name, old_count, new_count,
),
})?
}
} else if new.medial() && new_count > old_count {
Err(anyhow! {
format!(
bail! {
"While constructing the game '{}', a terminal node was \
added containing {} utility entries, but then a new \
medial node was added with a 0-indexed turn of {}, \
which is incompatible.",
self.name,
old_count,
new_count - 1,
),
})?
}
}
} else if new.terminal() && new_count < old_count {
Err(anyhow! {
format!(
bail! {
"While constructing the game '{}', a medial node was \
added with a 0-indexed turn of {}, but then a new \
terminal node was added with {} entries. All turn \
Expand All @@ -209,8 +198,7 @@ impl<'a> SessionBuilder<'a> {
self.name,
old_count - 1,
new_count,
),
})?
}
}

if new.terminal() {
Expand All @@ -227,12 +215,10 @@ impl<'a> SessionBuilder<'a> {
if let Some(index) = self.start {
Ok(index)
} else {
Err(anyhow! {
format!(
bail! {
"No starting node was specified for the game '{}'.",
self.name,
),
})?
}
}
}

Expand Down Expand Up @@ -260,13 +246,11 @@ impl<'a> SessionBuilder<'a> {
}
}

Err(anyhow! {
format!(
bail! {
"No terminal node is reachable from the node marked as the \
start in the game '{}'.",
self.name
),
})?
}
}

/// Fails if there exists a node marked as medial in the game graph which
Expand All @@ -280,13 +264,11 @@ impl<'a> SessionBuilder<'a> {
.count()
.eq(&0)
}) {
Err(anyhow! {
format!(
bail! {
"There exists a medial state with no outgoing edges in the \
constructed game '{}', which is a contradiction.",
self.name
),
})?
}
} else {
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Display for mock::Session<'_> {
let mut attrs = String::new();
match node {
mock::Node::Medial(turn) => {
attrs += &format!("label=P{} ", turn);
attrs += &format!("label=P{turn} ");
attrs += "style=filled ";
if self.start() == self.state(node).unwrap() {
attrs += "shape=doublecircle ";
Expand Down
Loading

0 comments on commit 996a31f

Please sign in to comment.