Skip to content

Commit

Permalink
feat(maze): various getter for Maze
Browse files Browse the repository at this point in the history
  • Loading branch information
anhgelus committed May 31, 2023
1 parent b92ab29 commit 00e6e75
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
21 changes: 18 additions & 3 deletions Generators/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ func GenerateNewMaze(w uint, h uint, algo func(*Maze) error) (Maze, error) {

// generateWalls generate the default walls
func (m *Maze) generateWalls() []Wall {
xV := (m.Width - 1) * m.Height
xH := m.Width * m.Height
x := xH + xV
xH := m.GetHorizontalWallsNumber()
x := xH + m.GetVerticalWallsNumber()
walls := make([]Wall, x)
for i := uint(0); i < x; i++ {
walls[i] = Wall{IsVertical: i >= xH, ID: int(i)}
Expand All @@ -35,6 +34,22 @@ func (m *Maze) generateWalls() []Wall {
return walls
}

func (m *Maze) GetHorizontalWallsNumber() uint {
return m.Width * m.Height
}

func (m *Maze) GetVerticalWallsNumber() uint {
return (m.Width - 1) * m.Height
}

func (m *Maze) GetVerticalWalls() []Wall {
return m.Walls[m.GetHorizontalWallsNumber():]
}

func (m *Maze) GetHorizontalWalls() []Wall {
return m.Walls[:m.GetHorizontalWallsNumber()-1]
}

func (m *Maze) RenderWalls() {

}
22 changes: 19 additions & 3 deletions Generators/randomised_kruskal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@ import (
)

func TestWallsRandomisedKruskal(t *testing.T) {
maze, err := GenerateNewMaze(5, 5, NewRandomisedKruskal)
m, err := GenerateNewMaze(5, 5, NewRandomisedKruskal)
if err != nil {
t.Error(err.Error())
return
}
if len(maze.Walls) != 45 {
if len(m.Walls) != 45 {
t.Error(utils.FormatTestError("bad length of total walls", strconv.Itoa(45),
strconv.Itoa(len(maze.Walls))))
strconv.Itoa(len(m.Walls))))
}

vertical := m.GetVerticalWalls()
for _, wall := range vertical {
if !wall.IsVertical {
t.Error(utils.FormatTestError("non vertical walls in GetVerticalWalls", "true", "false"))
break
}
}

horizontal := m.GetHorizontalWalls()
for _, wall := range horizontal {
if wall.IsVertical {
t.Error(utils.FormatTestError("vertical walls in GetHorizontalWalls", "false", "true"))
break
}
}
}

0 comments on commit 00e6e75

Please sign in to comment.