Add maze pkg

This commit is contained in:
dwrz
2026-10-25 02:51:07 +00:00
parent 1aabbdfee7
commit 17d9903f17
6 changed files with 388 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
// Package cell represents a single cell in a maze grid.
package cell
import (
"code.chimeric.al/dwrz/minotaur/pkg/maze/direction"
)
// Cell is a bitmask of open passages from a cell to its neighbors.
// Bit d (1 << d) is 1 when the passage in direction d is open, and 0 when a
// wall blocks that direction.
type Cell uint8
// HasDirection reports whether the passage in direction d is open.
func (c Cell) HasDirection(d direction.Direction) bool {
return c&(1<<d) != 0
}
// SetDirection opens the passage in direction d.
func (c *Cell) SetDirection(d direction.Direction) {
*c |= 1 << d
}
+43
View File
@@ -0,0 +1,43 @@
package cell
import (
"testing"
"code.chimeric.al/dwrz/minotaur/pkg/maze/direction"
)
func TestSetDirection(t *testing.T) {
var c Cell
t.Logf("start: %08b", c)
c.SetDirection(direction.Right)
t.Logf("set right: %08b", c)
c.SetDirection(direction.Down)
t.Logf("set down: %08b", c)
var (
hasRight = c.HasDirection(direction.Right)
hasDown = c.HasDirection(direction.Down)
hasLeft = c.HasDirection(direction.Left)
hasUp = c.HasDirection(direction.Up)
)
t.Logf("has right: %v", hasRight)
t.Logf("has down: %v", hasDown)
t.Logf("has left: %v", hasLeft)
t.Logf("has up: %v", hasUp)
if !hasRight {
t.Errorf("expected cell to have right")
}
if !hasDown {
t.Errorf("expected cell to have down")
}
if hasLeft {
t.Errorf("expected cell to not have left")
}
if hasUp {
t.Errorf("expected cell to not have up")
}
}