Пример #1
0
// Find all of the cycles in this mask. It will only yield
// unique masks, with respect to the effect that this mask
// would have to the board. It uses colorMask to help determine
// this. This means that if there are multiple squares, it will
// only return one of them, because all squares have the same
// effect on the board.
func (mask Mask) Cycles(cycles chan Mask, colorMask Mask) {
	q := newQueue()
	defer q.free()
	C.Cycles(C.Mask(mask), C.Mask(colorMask), (*C.Queue)(q))
	for _, cycle := range q.slice() {
		cycles <- cycle
	}
	close(cycles)
}
Пример #2
0
func (mask Mask) DFS(paths chan Mask) {
	q := newQueue()
	defer q.free()
	C.DFS(C.Mask(mask), (*C.Queue)(q))
	for _, path := range q.slice() {
		paths <- path
	}
	close(paths)
}
Пример #3
0
func (mask Mask) Partition(partitions chan Mask) {
	q := newQueue()
	defer q.free()
	C.Partition(C.Mask(mask), (*C.Queue)(q))
	for _, partition := range q.slice() {
		partitions <- partition
	}
	close(partitions)
}
Пример #4
0
func (mask Mask) CountNeighbors(row, col int) int {
	return int(C.CountNeighbors(C.Mask(mask), C.int(row), C.int(col)))
}
Пример #5
0
func (mask Mask) Count() int {
	return int(C.Count(C.Mask(mask)))
}
Пример #6
0
// Returns a Mask of any dots encircled by this cyclic Mask.
// Using this on masks that are cyclic or contain squares will have
// undefined/meaningless return values.
func (mask Mask) Encircled() Mask {
	return Mask(C.Encircled(C.Mask(mask)))
}
Пример #7
0
// Return the minimum and maximum rows and columns. In other words,
// return the convex hull, where (r0, c0), (r1, c1) are the
// top left and bottom right coordinates. Convex hull is a
// fancy math term to indicate the smallest convex set that
// contains all of a set of points.
// https://en.wikipedia.org/wiki/Convex_hull
func (mask Mask) ConvexHull() (int, int, int, int) {
	var r0, c0, r1, c1 C.int
	C.ConvexHull(C.Mask(mask), &r0, &c0, &r1, &c1)
	return int(r0), int(c0), int(r1), int(c1)
}
Пример #8
0
// Returns the first square in this mask. Returns 0 if there is none.
func (mask Mask) findSquare(r0, c0, r1, c1 int) Mask {
	return Mask(C.findSquare(C.Mask(mask),
		C.int(r0), C.int(c0), C.int(r1), C.int(c1)))
}