示例#1
0
// removeWallBetween removes the wall between two neighboring coordinates
func (m *Maze) removeWallBetween(c1, c2 common.Coordinate) {
	d1 := c1.GetDir(c2)
	r1, _ := m.GetRoom(c1.X, c1.Y)
	r1.RmWall(d1)

	d2 := c2.GetDir(c1)
	r2, _ := m.GetRoom(c2.X, c2.Y)
	r2.RmWall(d2)
}
示例#2
0
// addWall on both sides
func (m *Maze) addWall(c common.Coordinate, dir int) {
	nb := c.Neighbor(dir)
	if m.contains(nb) {
		r, _ := m.GetRoom(c.X, c.Y)
		r.AddWall(dir)
		r, _ = m.GetRoom(nb.X, nb.Y)
		r.AddWall(common.ReverseDirection[dir])
	}
}
示例#3
0
文件: icarus.go 项目: showbufire/gc6
// pickNeighbor selects a neighboring unexplored coordinate
func pickNeighbor(coordinate common.Coordinate, explored map[common.Coordinate]Survey) (common.Coordinate, int, bool) {
	survey := explored[coordinate]
	idxs := rand.Perm(len(allDirections))
	for _, idx := range idxs {
		dir := allDirections[idx]
		if !survey.HasWall(dir) {
			neighbor := coordinate.Neighbor(dir)
			if _, ok := explored[neighbor]; !ok {
				return neighbor, dir, true
			}
		}
	}
	return coordinate, 0, false
}
示例#4
0
// floodfill starts from some coordinate, and randomly moves(floodfills) neighboring coordinates if unexplored.
// This is used to create deadends.
func (m *Maze) floodfill(c, from common.Coordinate, explored map[common.Coordinate]bool) {
	m.sealRoom(c)
	m.removeWallBetween(c, from)
	explored[c] = true

	nbs := c.Neighbors()
	idxs := rand.Perm(len(nbs))
	for _, idx := range idxs {
		nb := nbs[idx]
		if m.contains(nb) && !explored[nb] {
			m.floodfill(nb, c, explored)
		}
	}
}