crowns/util.go

68 lines
1.3 KiB
Go

package main
import (
"sort"
)
func search(hand []Card, wildFace int, search Card) []int {
ret := []int{}
for idx, c := range hand {
if c == search || c.Joker() || c.Face() == wildFace {
ret = append(ret, idx)
}
}
return ret
}
func searchExcept(hand []Card, wildFace int, search Card, blockindexes map[int]struct{}) []int {
ret := []int{}
for idx, c := range hand {
if _, blocked := blockindexes[idx]; blocked {
continue
}
if c.Masked() {
continue // Doesn't match anything
}
if c.Joker() || c == search || c.Face() == wildFace {
ret = append(ret, idx)
}
}
return ret
}
// take takes a single card out of a hand by its index, returning the remaining cards.
func take(hand []Card, index int) (Card, []Card) {
cc := hand[index]
rem := make([]Card, 0, len(hand)-1)
rem = append(rem, hand[0:index]...)
rem = append(rem, hand[index+1:]...)
return cc, rem
}
func forkPossibilities(in map[int]struct{}) map[int]struct{} {
ret := map[int]struct{}{}
for prev, _ := range in {
ret[prev] = struct{}{}
}
return ret
}
func forkHand(hand []Card) []Card {
ret := make([]Card, len(hand))
copy(ret, hand)
return ret
}
func flattenPossibility(in map[int]struct{}) []int {
flat := make([]int, 0, len(in))
for cidx, _ := range in {
flat = append(flat, cidx)
}
sort.Ints(flat)
return flat
}