maze-solver-go/io/reader/raw_maze.go
2023-08-05 16:36:49 +02:00

42 lines
865 B
Go

package reader
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
}