Example #1
0
func ReachableSpec(c gospec.Context) {
	b := [][]int{
		[]int{1, 2, 9, 4, 3, 2, 1}, // 0 - 6
		[]int{9, 2, 9, 4, 3, 1, 1}, // 7 - 13
		[]int{2, 1, 5, 5, 5, 2, 1}, // 14 - 20
		[]int{1, 1, 1, 1, 1, 1, 1}, // 21 - 27
	}
	c.Specify("Check reachability", func() {
		reach := algorithm.ReachableWithinLimit(board(b), []int{3}, 5)
		c.Expect(reach, ContainsInOrder, []int{3, 4, 5, 10})
		reach = algorithm.ReachableWithinLimit(board(b), []int{3}, 10)
		c.Expect(reach, ContainsInOrder, []int{2, 3, 4, 5, 6, 10, 11, 12, 13, 17, 19, 20, 24, 25, 26, 27})
	})
	c.Specify("Check reachability with multiple sources", func() {
		reach := algorithm.ReachableWithinLimit(board(b), []int{0, 6}, 3)
		c.Expect(reach, ContainsInOrder, []int{0, 1, 5, 6, 12, 13, 20, 27})
		reach = algorithm.ReachableWithinLimit(board(b), []int{21, 27}, 2)
		c.Expect(reach, ContainsInOrder, []int{13, 14, 15, 20, 21, 22, 23, 25, 26, 27})
	})
	c.Specify("Check bounds with multiple sources", func() {
		reach := algorithm.ReachableWithinBounds(board(b), []int{0, 6}, 2, 4)
		c.Expect(reach, ContainsInOrder, []int{1, 5, 8, 12, 19, 20, 26, 27})
	})
}
Example #2
0
// Given the anim graph for a sprite, determines the frames that must always
// be loaded such that the remaining facings can be loaded only when the
// sprite facing changes, so long as the facings sprite sheet can be loaded
// in under limit milliseconds.  A higher value for limit will require more
// texture memory, but will reduce the chance that there will be any
// stuttering in the animation because a spritesheet couldn't be loaded in
// time.
func figureConnectors(anim *yed.Graph, limit int) []*yed.Node {
	var facing_edges []int
	for i := 0; i < anim.NumEdges(); i++ {
		edge := anim.Edge(i)
		if edge.Tag("facing") != "" {
			facing_edges = append(facing_edges, edge.Dst().Id())
		}
	}

	reachable := algorithm.ReachableWithinLimit(&animAlgoGraph{anim}, facing_edges, float64(limit))
	var ret []*yed.Node
	for _, reach := range reachable {
		ret = append(ret, anim.Node(reach))
	}
	return ret
}