Ejemplo n.º 1
0
// addNodes recursively adds nodes to a game tree until all possible
// playouts have been added.
func addNodes(node interface{}, g *game.Game) {
	switch n := node.(type) {
	case *Bucket:
		g.Update(diff.Cards(""))
		for i := range n.Classes {
			n.Classes[i] = newNode(g)
			addNodes(n.Classes[i], g)
		}
	case *Player:
		la := g.LegalActions()
		s := 1 / float64(len(la))
		for _, a := range la {
			i := atoi[a]
			n.Strat[i] = s
			g1 := g.Copy()
			g1.Update(diff.Action(itoa[i]))
			n.Actions[i] = newNode(g1)
			addNodes(n.Actions[i], g1)
		}
	case *Opponent:
		for _, a := range g.LegalActions() {
			i := atoi[a]
			g1 := g.Copy()
			g1.Update(diff.Action(itoa[i]))
			n.Actions[i] = newNode(g1)
			addNodes(n.Actions[i], g1)
		}
	case Terminal:
	default:
		panic(fmt.Sprintln("Invalid type of node encountered.", n))
	}
}
Ejemplo n.º 2
0
func newNode(g *game.Game) interface{} {
	if g.Round == 4 || g.NumActive() < 2 {
		return Terminal(g.Pot())
	}
	if g.Actor == -1 {
		return new(Bucket)
	}
	if g.Actor == g.Viewer {
		return &Player{}
	}
	return new(Opponent)
}