fa4c13812d
Added a string reader too so that one can create a maze just with a slice of stings and RawMaze now has chunks of bytes to limit memory usage with big mazes (hopefully)
42 lines
863 B
Go
42 lines
863 B
Go
package maze
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
const CHUNK_SIZE = 8 // size of a byte
|
|
|
|
type RawMaze struct {
|
|
Width, Height int
|
|
Data [][]byte
|
|
}
|
|
|
|
func (m *RawMaze) String() string {
|
|
var ret strings.Builder
|
|
ret.WriteString("{\n")
|
|
ret.WriteString("\tData: \n")
|
|
for _, line := range m.Data {
|
|
ret.WriteRune('\t')
|
|
ret.WriteRune('\t')
|
|
ret.Write(line) // TODO: prolly should fix this to make it readable
|
|
ret.WriteRune('\n')
|
|
}
|
|
ret.WriteString("}")
|
|
|
|
return ret.String()
|
|
}
|
|
|
|
func (m *RawMaze) IsPath(x int, y int) bool {
|
|
chunk_index := x / CHUNK_SIZE
|
|
chunk_rest := x % CHUNK_SIZE
|
|
chunk := m.Data[y][chunk_index]
|
|
return chunk&(1<<(CHUNK_SIZE-1-chunk_rest)) != 0
|
|
}
|
|
|
|
func (m *RawMaze) IsWall(x int, y int) bool {
|
|
chunk_index := x / CHUNK_SIZE
|
|
chunk_rest := x % CHUNK_SIZE
|
|
chunk := m.Data[y][chunk_index]
|
|
return chunk&(1<<(CHUNK_SIZE-1-chunk_rest)) == 0
|
|
}
|