63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
helpers "git.bullercodeworks.com/brian/adventofcode/helpers"
|
|
)
|
|
|
|
type Vault struct {
|
|
maxX, maxY int
|
|
start helpers.Coordinate
|
|
vault map[string]bool
|
|
keys map[string]int
|
|
doors map[string]int
|
|
keylist int
|
|
}
|
|
|
|
func NewVault(file string) *Vault {
|
|
inp := helpers.FileToBytes(file)
|
|
wrk := bytes.Split(inp, []byte{'\n'})
|
|
|
|
v := Vault{
|
|
vault: make(map[string]bool),
|
|
keys: make(map[string]int),
|
|
doors: make(map[string]int),
|
|
}
|
|
v.maxY = len(wrk)
|
|
v.maxX = len(wrk[0])
|
|
for y, yv := range wrk {
|
|
for x, xv := range yv {
|
|
if xv == '@' {
|
|
v.start = *helpers.NewCoordinate(x, y)
|
|
xv = '.'
|
|
}
|
|
v.vault[helpers.NewCoordinate(x, y).String()] = (xv != '#')
|
|
if isKey(xv) {
|
|
k := keyInt(xv)
|
|
v.keys[helpers.NewCoordinate(x, y).String()] = k
|
|
v.keylist |= k
|
|
} else if isDoor(xv) {
|
|
d := doorInt(xv)
|
|
v.doors[helpers.NewCoordinate(x, y).String()] = d
|
|
v.keylist |= d
|
|
}
|
|
}
|
|
}
|
|
return &v
|
|
}
|
|
|
|
func (v *Vault) Print() {
|
|
for y := 0; y < v.maxY; y++ {
|
|
for x := 0; x < v.maxX; x++ {
|
|
if v.vault[helpers.NewCoordinate(x, y).String()] {
|
|
fmt.Print(".")
|
|
} else {
|
|
fmt.Print("#")
|
|
}
|
|
}
|
|
fmt.Println()
|
|
}
|
|
}
|