-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//! Loopy games | ||
pub mod games; | ||
pub mod vertex; |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//! Loopy game graph vertex | ||
use crate::{display, numeric::nimber::Nimber}; | ||
use std::fmt::Display; | ||
|
||
/// Vertex set used during graph orbiting | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum UnresolvedVertex { | ||
/// Vertex that is equal to some finite nimber or a loop. | ||
Resolved(Vertex), | ||
|
||
/// Vertex that is yet to be resolved to a finite nimber or a loop. | ||
Unresolved, | ||
} | ||
|
||
/// Value of graph vertex - finite or infinite | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum Vertex { | ||
/// Vertex that is equal to some finite nimber. | ||
Value(Nimber), | ||
|
||
/// Vertex that can move in a finite loop, or escape to one of the nimbers. | ||
Loop(Vec<Nimber>), | ||
} | ||
|
||
impl Display for Vertex { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Value(n) => write!(f, "{}", n), | ||
Self::Loop(infs) => { | ||
write!(f, "∞")?; | ||
if !infs.is_empty() { | ||
display::parens(f, |f| display::commas(f, infs))?; | ||
} | ||
Ok(()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl UnresolvedVertex { | ||
/// Check if vertex is a finite zero | ||
pub const fn is_zero(&self) -> bool { | ||
matches!(self, Self::Resolved(Vertex::Value(val)) if val.value() == 0) | ||
} | ||
} |