-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Style changes, inlined inetrpolated strs, used bail macro
- Loading branch information
1 parent
19215e8
commit 9d9d1f1
Showing
18 changed files
with
200 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
//! #### Authorship | ||
//! - Max Fierro, 3/31/2024 ([email protected]) | ||
use anyhow::anyhow; | ||
use anyhow::bail; | ||
use anyhow::Result; | ||
use petgraph::Direction; | ||
use petgraph::{graph::NodeIndex, Graph}; | ||
|
@@ -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)?; | ||
|
@@ -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, | ||
), | ||
})? | ||
} | ||
} | ||
} | ||
|
||
|
@@ -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 | ||
}, | ||
|
@@ -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 \ | ||
|
@@ -209,8 +198,7 @@ impl<'a> SessionBuilder<'a> { | |
self.name, | ||
old_count - 1, | ||
new_count, | ||
), | ||
})? | ||
} | ||
} | ||
|
||
if new.terminal() { | ||
|
@@ -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, | ||
), | ||
})? | ||
} | ||
} | ||
} | ||
|
||
|
@@ -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 | ||
|
@@ -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(()) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.