Example #1
0
func (ht *HandTracker) populate(playerid int, hand sdz.Hand) {
	for _, suit := range sdz.Suits() {
		for _, face := range sdz.Faces() {
			card := sdz.CreateCard(suit, face)
			ht.cards[playerid][card] = 0
		}
	}
	for _, card := range hand {
		ht.cards[playerid][card]++
	}
	ht.calculate()
}
Example #2
0
// Returns a new HandTracker with the initial population and calculation done
func NewHandTracker(playerid int, hand sdz.Hand) *HandTracker {
	ht := new(HandTracker)
	for x := 0; x < 4; x++ {
		ht.cards[x] = make(map[sdz.Card]int)
	}
	ht.playedCards = make(map[sdz.Card]int)
	for _, suit := range sdz.Suits() {
		for _, face := range sdz.Faces() {
			card := sdz.CreateCard(suit, face)
			ht.playedCards[card] = 0
		}
	}
	ht.populate(playerid, hand)
	return ht
}
Example #3
0
func (ht *HandTracker) calculate() {
	for _, suit := range sdz.Suits() {
		for _, face := range sdz.Faces() {
			card := sdz.CreateCard(suit, face)
			sum := ht.playedCards[card]
			for x := 0; x < 4; x++ {
				if val, ok := ht.cards[x][card]; ok {
					sum += val
				}
			}
			if sum == 2 {
				for x := 0; x < 4; x++ {
					if _, ok := ht.cards[x][card]; !ok {
						ht.cards[x][card] = 0
					}
				}
			} else {
				unknown := -1
				for x := 0; x < 4; x++ {
					if _, ok := ht.cards[x][card]; !ok {
						if unknown == -1 {
							unknown = x
						} else {
							// at least two unknowns
							unknown = -1
							break
						}
					}
				}
				if unknown != -1 {
					ht.cards[unknown][card] = 2 - sum
				}
			}
		}
	}
}
Example #4
0
func (ht *HandTracker) noSuit(playerid int, suit sdz.Suit) {
	for _, face := range sdz.Faces() {
		ht.cards[playerid][sdz.CreateCard(suit, face)] = 0
	}
}