Example #1
0
File: daedalus.go Project: mouk/gc6
func getUnvisitedNeighbors(co mazelib.Coordinate, maze mazelib.MazeI) []mazelib.Coordinate {
	coordinates := []mazelib.Coordinate{
		mazelib.Coordinate{co.X, co.Y - 1},
		mazelib.Coordinate{co.X, co.Y + 1},
		mazelib.Coordinate{co.X + 1, co.Y},
		mazelib.Coordinate{co.X - 1, co.Y},
	}
	returnValues := []mazelib.Coordinate{}

	for _, currentCo := range coordinates {
		if cos, err := maze.GetRoom(currentCo.X, currentCo.Y); err == nil {
			if cos.Visited == false {
				returnValues = append(returnValues, currentCo)
			}
		}
	}
	return returnValues
}
Example #2
0
File: daedalus.go Project: mouk/gc6
func carvePathes(co mazelib.Coordinate, maze mazelib.MazeI, pathLength int) targetCandidate {
	room, _ := maze.GetRoom(co.X, co.Y)
	room.Visited = true
	deadEnd := true

	var currenttargetCandidate targetCandidate
	neighbors := getUnvisitedNeighbors(co, maze)
	for len(neighbors) > 0 {
		deadEnd = false
		randomNeighbor := neighbors[rand.Intn(len(neighbors))]
		neighborRoom, _ := maze.GetRoom(randomNeighbor.X, randomNeighbor.Y)
		switch {
		case randomNeighbor.Y == co.Y-1:
			room.RmWall(mazelib.N)
			neighborRoom.RmWall(mazelib.S)
		case randomNeighbor.Y == co.Y+1:
			room.RmWall(mazelib.S)
			neighborRoom.RmWall(mazelib.N)
		case randomNeighbor.X == co.X-1:
			room.RmWall(mazelib.W)
			neighborRoom.RmWall(mazelib.E)
		case randomNeighbor.X == co.X+1:
			room.RmWall(mazelib.E)
			neighborRoom.RmWall(mazelib.W)
		}

		result := carvePathes(randomNeighbor, maze, pathLength+1)
		if currenttargetCandidate.StepsTaken < result.StepsTaken {
			currenttargetCandidate = result
		}
		neighbors = getUnvisitedNeighbors(co, maze)
	}
	if deadEnd {
		currenttargetCandidate = targetCandidate{co, pathLength}
	}
	return currenttargetCandidate
}