Пример #1
0
// On generates a maze on a given grid by using a binary tree algorithm.
func (bt binaryTree) On(grid maze.Grid) {
	for _, cell := range grid.EachCell() {
		var neighbors []*maze.Cell
		if cell.North != nil {
			neighbors = append(neighbors, cell.North)
		}
		if cell.East != nil {
			neighbors = append(neighbors, cell.East)
		}

		if len(neighbors) < 1 {
			continue
		}

		idx := bt.r.Intn(len(neighbors))
		neighbor := neighbors[idx]
		cell.Link(neighbor)
	}
}