Compare commits
2 Commits
b806264154
...
75de281cee
Author | SHA1 | Date | |
---|---|---|---|
75de281cee | |||
222d4375ee |
@ -264,9 +264,18 @@ func (d *Deck[C]) ShuffleTop(frac float64) error {
|
|||||||
return d.ShuffleRange(0.0, frac)
|
return d.ShuffleRange(0.0, frac)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shufflebottom uses ShuffleRange to shuffle the bottom frac (between 0.0 and
|
// ShuffleBottom uses ShuffleRange to shuffle the bottom frac (between 0.0 and
|
||||||
// 1.0) of the deck. See ShuffleRange and ShufflePart for information on
|
// 1.0) of the deck. See ShuffleRange and ShufflePart for information on
|
||||||
// rounding and warnings.
|
// rounding and warnings.
|
||||||
func (d *Deck[C]) ShuffleBottom(frac float64) error {
|
func (d *Deck[C]) ShuffleBottom(frac float64) error {
|
||||||
return d.ShuffleRange(frac, 1.0)
|
return d.ShuffleRange(frac, 1.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strip removes all cards from the deck where shouldRemove returns true.
|
||||||
|
// 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 {
|
||||||
|
origLen := d.Len()
|
||||||
|
d.cards = Strip(d.cards, shouldRemove)
|
||||||
|
return origLen - d.Len()
|
||||||
|
}
|
||||||
|
@ -126,3 +126,22 @@ func ShufflePart[T any](slice []T, r *rand.Rand, loc, n int) {
|
|||||||
}
|
}
|
||||||
ShuffleAll(slice[loc:loc+n], r)
|
ShuffleAll(slice[loc:loc+n], r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strip iterates T, removing any element for which removeWhen returns true
|
||||||
|
// (when provided the index of the element and the element itself as arguments).
|
||||||
|
// It returns the stripped slice.
|
||||||
|
func Strip[T any](slice []T, removeWhen func(idx int, t T) bool) []T {
|
||||||
|
if len(slice) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
to := 0
|
||||||
|
for from, e := range slice {
|
||||||
|
if !removeWhen(from, e) {
|
||||||
|
if to != from {
|
||||||
|
slice[to] = slice[from]
|
||||||
|
}
|
||||||
|
to++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return slice[:to]
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user