Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

plans.gno

0.89 Kb · 29 lines
 1package engine
 2
 3// LegalPlans lists every plan side can play from deck in state s: costs summing to 3,
 4// basics any number of times, each unspent special of deck at most once. Plans come in
 5// card order, depth first.
 6func (rs *Ruleset) LegalPlans(s State, side Side, deck uint64) []Plan {
 7	var buf [beatsPerRound]CardID
 8	return rs.extendPlans(nil, buf[:0], 0, deck&^s.Gnomes[side].Spent, 0)
 9}
10
11func (rs *Ruleset) extendPlans(out []Plan, plan Plan, beats int, available, used uint64) []Plan {
12	if beats == beatsPerRound {
13		done := make(Plan, len(plan))
14		copy(done, plan)
15		return append(out, done)
16	}
17	for i := range rs.Cards {
18		c := &rs.Cards[i]
19		if beats+c.Cost > beatsPerRound {
20			continue
21		}
22		bit := uint64(1) << uint(i)
23		if c.Special && (available&bit == 0 || used&bit != 0) {
24			continue
25		}
26		out = rs.extendPlans(out, append(plan, CardID(i)), beats+c.Cost, available, used|bit)
27	}
28	return out
29}