Skip to content

Commit

Permalink
feat(scheme): handle disabled cells
Browse files Browse the repository at this point in the history
  • Loading branch information
anhgelus committed Jun 23, 2023
1 parent 5cbdcc7 commit 149ed75
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Generators/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,21 @@ func (m *Maze) generateCells() []*Cell {
}

func (m *Maze) innerHole() {
cI := m.Width/2
cJ := m.Height/2
mid := m.Inner/2
for _, c := range m.Cells {
i, j := m.GenIJFromIDForCell(uint(c.ID))
if !(i >= cI - mid && i < cI + mid && j >= cJ - mid && j < cJ + mid) {
if !m.isInHole(m.GenIJFromIDForCell(uint(c.ID))) {
continue
}
c.Disabled = true
}
}

func (m *Maze) isInHole(i uint, j uint) bool {
cI := m.Width/2
cJ := m.Height/2
mid := m.Inner/2
return i >= cI - mid && i < cI + mid && j >= cJ - mid && j < cJ + mid
}

// GetHorizontalWallsNumber return the number of horizontal walls
func (m *Maze) GetHorizontalWallsNumber() uint {
return m.Width * m.Height
Expand Down Expand Up @@ -168,8 +171,16 @@ func (m *Maze) ToScheme() Scheme {
continue
}
if wall.IsVertical {
if len(wall.CellsNear) == 2 && (wall.CellsNear[0].Disabled || wall.CellsNear[1].Disabled) {
str += "-"
continue
}
str += "|"
} else {
if len(wall.CellsNear) == 2 && wall.CellsNear[0].Disabled {
str += "X"
continue
}
str += "_"
}
}
Expand Down

0 comments on commit 149ed75

Please sign in to comment.