Skip to content

Commit

Permalink
update url checker to work for unlimited decks
Browse files Browse the repository at this point in the history
  • Loading branch information
efinauri committed Jan 16, 2024
1 parent 467ac55 commit 52c239d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
49 changes: 26 additions & 23 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,36 +156,39 @@ impl Context {
}
}

#[allow(dead_code)]
pub fn from_debug() -> Self {
let game_mode = 1;
let craft = 1;
let map = CardsMap::from_input(game_mode, craft).unwrap();
let mut tags = HashSet::new();
for (_, info) in &map.0 {
for tag in &info.tags_ {
tags.insert(tag);
}
}
let tags: Vec<_> = tags.into_iter().map(|s| String::from(s)).collect();
let vec = CardsVec::from_dict(&map);
Context {
cards_map: map,
cards_vec: vec,
game_mode,
craft,
tags,
}
}

pub fn idx_to_card(&self, idx: usize) -> &CardInfo {
self.cards_map.0.get(&self.cards_vec.0[idx]).unwrap()
}
}

#[cfg(test)]
mod tests {
use crate::context::Context;
use std::collections::HashSet;

use crate::context::{CardsMap, CardsVec, Context};

impl Context {
pub fn from_debug() -> Self {
let game_mode = 1;
let craft = 1;
let map = CardsMap::from_input(game_mode, craft).unwrap();
let mut tags = HashSet::new();
for (_, info) in &map.0 {
for tag in &info.tags_ {
tags.insert(tag);
}
}
let tags: Vec<_> = tags.into_iter().map(|s| String::from(s)).collect();
let vec = CardsVec::from_dict(&map);
Context {
cards_map: map,
cards_vec: vec,
game_mode,
craft,
tags,
}
}
}

#[test]
fn ctx() {
Expand Down
5 changes: 2 additions & 3 deletions src/deck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ impl Deck for DeckBTree {
// 3 is rotation, 1 is unlimited
format!("https://shadowverse-portal.com/deck/{}.{}.{}",
match ctx.game_mode {
0 => 3,
0 => 2,
1 => 1,
_ => panic!("invalid game mode (not 0 or 1)")
},
ctx.craft,
ctx.craft + 1,
deck_hash)
}

Expand Down Expand Up @@ -246,7 +246,6 @@ impl Deck for DeckBTree {
}

// The crossover is single-point.
// TODO: double-point crossover should be better.
fn mix(&self, other: &DeckBTree) -> DeckBTree {
let cross = rand::thread_rng().gen_range(1, DECK_SIZE - MAX_QTY);
let mut ret = DeckBTree::new();
Expand Down

0 comments on commit 52c239d

Please sign in to comment.