Refactor Strip (already).
Stripping cards from the Hand will also be useful, so I pulled the logic of Strip out into arrayutil (more efficiently, too) and rewrote deck.Strip to use it.
This commit is contained in:
@ -275,22 +275,7 @@ func (d *Deck[C]) ShuffleBottom(frac float64) error {
|
||||
// shouldRemove is provided with each card in the deck and its index.
|
||||
// It returns how many cards were stripped from the deck.
|
||||
func (d *Deck[C]) Strip(shouldRemove func(idx int, c Card[C]) bool) int {
|
||||
stripped := 0
|
||||
startStripRange := -1
|
||||
for i := 0; i < len(d.cards); i++ {
|
||||
if shouldRemove(i, d.cards[i]) {
|
||||
stripped++
|
||||
if startStripRange < 0 {
|
||||
startStripRange = i
|
||||
}
|
||||
} else if startStripRange >= 0 {
|
||||
d.cards = DeleteNFrom(d.cards, startStripRange, i-startStripRange)
|
||||
i = startStripRange
|
||||
startStripRange = -1
|
||||
}
|
||||
}
|
||||
if startStripRange >= 0 {
|
||||
d.cards = d.cards[:startStripRange]
|
||||
}
|
||||
return stripped
|
||||
origLen := d.Len()
|
||||
d.cards = Strip(d.cards, shouldRemove)
|
||||
return origLen - d.Len()
|
||||
}
|
||||
|
Reference in New Issue
Block a user