Skip to content

Commit

Permalink
Refactor cyclic and puzzle solvers
Browse files Browse the repository at this point in the history
  • Loading branch information
ishirgarg committed Apr 23, 2024
1 parent 64c29ac commit b9911ac
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 205 deletions.
2 changes: 1 addition & 1 deletion src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub type Turn = usize;
pub type Utility = i64;

/// TODO
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum SimpleUtility {
WIN = 0,
LOSE = 1,
Expand Down
20 changes: 5 additions & 15 deletions src/solver/algorithm/strong/cyclic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! - Ishir Garg, 3/12/2024 (ishirgarg@berkeley.edu)

use anyhow::{Context, Result};

use std::collections::{HashMap, VecDeque};

use crate::database::volatile;
Expand All @@ -20,18 +21,7 @@ use crate::model::{PlayerCount, Remoteness, State, Turn};
use crate::solver::record::sur::RecordBuffer;
use crate::solver::RecordType;

/* CONSTANTS */

/// The exact number of bits that are used to encode remoteness.
const REMOTENESS_SIZE: usize = 16;

/// The maximum number of bits that can be used to encode a record.
const BUFFER_SIZE: usize = 128;

/// The exact number of bits that are used to encode utility for one player.
const UTILITY_SIZE: usize = 2;

pub fn two_player_zero_sum_dynamic_solver<G>(
pub fn dynamic_solver<G>(
game: &G,
mode: IOMode,
) -> Result<()>
Expand All @@ -40,11 +30,11 @@ where
{
let mut db =
volatile_database(game).context("Failed to initialize database.")?;
basic_loopy_solver(game, &mut db)?;
cyclic_solver(game, &mut db)?;
Ok(())
}

fn basic_loopy_solver<G, D>(game: &G, db: &mut D) -> Result<()>
fn cyclic_solver<G, D>(game: &G, db: &mut D) -> Result<()>
where
G: DTransition<State> + Bounded<State> + SimpleSum<2> + Extensive<2> + Game,
D: KVStore,
Expand Down Expand Up @@ -91,7 +81,7 @@ where

let parents = game.retrograde(child);
// If child is a losing position
if matches!(child_utility, SimpleUtility::LOSE) {
if let SimpleUtility::LOSE = child_utility {
for parent in parents {
if *child_counts.get(&parent).expect("Failed to enqueue parent state in initial enqueueing stage") > 0 {
// Add database entry
Expand Down
Loading

0 comments on commit b9911ac

Please sign in to comment.