Skip to content

Commit

Permalink
About to redefine CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfierrog committed Oct 30, 2023
1 parent e77e71e commit f76007f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
10 changes: 1 addition & 9 deletions nova/src/games/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//!
//! - Max Fierro, 4/6/2023 (maxfierro@berkeley.edu)

use nalgebra::{Matrix, Matrix1, SMatrix, SVector, Vector1};
use nalgebra::{Matrix1, SMatrix, SVector, Vector1};

use crate::models::{Solver, State, Variant};

Expand Down Expand Up @@ -323,14 +323,6 @@ where
}
}

/* BIPARTITE GAME BLANKET */

pub trait Bipartite
where
Self: Solvable<2>,
{
}

/* SOLVING MARKERS */

/// Indicates that a game's state graph can be partitioned into independent
Expand Down
50 changes: 32 additions & 18 deletions nova/src/games/zero_by/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ use super::{
AcyclicallySolvable, CyclicallySolvable, Game, GameData, Solvable,
TierSolvable, Automaton,
};
use nalgebra::{Matrix2, SMatrix, SVector, Vector2};
use crate::implement;
use crate::{
models::{Solver, State, Value, Variant},
models::{Solver, State, Value, Variant, Turn},
solvers::{acyclic::AcyclicSolver, cyclic::CyclicSolver, tier::TierSolver},
};
use regex::Regex;
Expand Down Expand Up @@ -54,6 +55,7 @@ the only consequence will be a slight decrease in performance.";
pub struct Session
{
variant: Option<String>,
players: Turn,
from: State,
by: Vec<u64>,
}
Expand Down Expand Up @@ -121,34 +123,34 @@ impl Automaton<State> for Session
}
}

impl Solvable for Session
impl Solvable<2> for Session
{
fn value(&self, state: State) -> Option<Value>
fn weights(&self) -> SMatrix<i32, 2, 2>
{
if state > 0 { None } else { Some(Value::Lose(0)) }
Matrix2::new(1, 1, 1, 1);
}

fn utility(&self, state: State) -> Option<SVector<i32, 1>>
{
if !self.accepts(state) {
None
} else {
Some(Vector2::new(state % 2, (state + 1) % 2))
}
}

fn solvers(&self) -> Vec<(String, Solver<Self>)>
{
vec![
(
<Session as AcyclicSolver>::name(),
<Session as AcyclicSolver>::solve,
),
(
<Session as CyclicSolver>::name(),
<Session as CyclicSolver>::solve,
),
(
<Session as TierSolver>::name(),
<Session as TierSolver>::solve,
),
]

}
}

/* HELPER FUNCTIONS */

impl Session {

}

fn decode_variant(v: Variant) -> Session
{
let re = Regex::new(VARIANT_PATTERN).unwrap();
Expand All @@ -175,6 +177,18 @@ fn decode_variant(v: Variant) -> Session
}
}

fn encode_turn(state: State, player_count: Turn, turn: Turn) -> State
{
let turn_bits =
(0 as Turn).leading_zeros() - player_count.leading_zeros();
let shifted_state = state << turn_bits;
shifted_state + turn
}

fn decode_turn(state: State, ) -> Turn {

}

/* TESTS */

#[cfg(test)]
Expand Down
8 changes: 8 additions & 0 deletions nova/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ pub type Variant = String;
/// that can be achieved in a game.
pub type State = u64;

/// Expresses whose turn it is in a game, where every player is assigned to a
/// different integer. The fact that this only reaches `u16::MAX == 255` does
/// mean that we should only be prepared to consider games of up to 255 players.
/// This is a reasonable limitation, because considering games of any larger
/// player count is computationally unfeasible in transferrable utility
/// settings.
pub type Turn = u8;

/// The signature of a function which can solve a game, taking in the game,
/// and parameters read and write.
pub type Solver<G> = fn(&G, bool, bool) -> Value;
Expand Down

0 comments on commit f76007f

Please sign in to comment.