Improve lua dealer
This commit is contained in:
@ -31,7 +31,7 @@ impl Deal {
|
||||
while let Some((w, n)) = pops.pop() {
|
||||
for _ in 0..n {
|
||||
let card = wells[w].pop().expect("card must be present");
|
||||
Self::find_home(setup, rng, card, None, None, &mut slots, &max_height, true);
|
||||
Self::find_home(setup, rng, card, &mut slots, &max_height, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ impl Deal {
|
||||
for i in 0..slots.len() {
|
||||
while slots[i].len() > max_height[i] {
|
||||
let card = slots[i].pop().expect("must be a card");
|
||||
Self::find_home(setup, rng, card, None, None, &mut slots, &max_height, false);
|
||||
Self::find_home(setup, rng, card, &mut slots, &max_height, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,28 +127,21 @@ impl Deal {
|
||||
rle
|
||||
}
|
||||
|
||||
fn find_home(setup: &Setup, rng: &mut impl Rng, card: Card, source: Option<usize>, exclude: Option<usize>, slots: &mut [Vec<Card>], max_height: &[usize], allow_too_tall: bool) {
|
||||
fn find_home(setup: &Setup, rng: &mut impl Rng, card: Card, slots: &mut [Vec<Card>], max_height: &[usize], allow_too_tall: bool) {
|
||||
// if a card is sitting on an acceptor, it could have been moved there
|
||||
// from somewhere else
|
||||
let mut acceptors = vec![];
|
||||
|
||||
for s in 0..slots.len() {
|
||||
if Some(s) == exclude {
|
||||
// don't place it here, ever
|
||||
} else if false { // slots[s].len() == max_height[s] - 1 && setup.deck.instantly_accepted.contains(&card) {
|
||||
// can't place an instantly accepted card at the bottom of a slot
|
||||
} else {
|
||||
if allow_too_tall && accepts(setup, slots[s].last().cloned(), card) {
|
||||
acceptors.push(s);
|
||||
} else if slots[s].len() < max_height[s] {
|
||||
acceptors.push(s);
|
||||
}
|
||||
if (allow_too_tall && accepts(setup, slots[s].last().cloned(), card)) ||
|
||||
slots[s].len() < max_height[s] {
|
||||
acceptors.push(s);
|
||||
}
|
||||
}
|
||||
|
||||
let acceptor = acceptors.choose(rng).cloned();
|
||||
|
||||
if let Some(a) = acceptor.or(source) {
|
||||
if let Some(a) = acceptor {
|
||||
slots[a].push(card);
|
||||
} else {
|
||||
panic!("should never happen")
|
||||
|
Reference in New Issue
Block a user