Skip to content

Commit

Permalink
fix(randomised_kruskal): stop removing non removable wall
Browse files Browse the repository at this point in the history
  • Loading branch information
anhgelus committed Jun 3, 2023
1 parent 0a65d71 commit 1e9450a
Showing 1 changed file with 4 additions and 33 deletions.
37 changes: 4 additions & 33 deletions Generators/randomised_kruskal.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,10 @@ func NewRandomisedKruskal(b *Maze) error {
}
i++
}
println("Merging done!")
if len(m.Cells) != int(m.Width*m.Height) {
return fmt.Errorf("bad length of cells: %d", len(m.Cells))
}
var f string
for i, cell := range m.Cells {
if i != 0 && uint(i)%m.Height == 0 {
println(f)
f = ""
}
f += fmt.Sprintf("%d ", cell.ID)
}
println(f)
println("Merging done!")
return nil
}

Expand Down Expand Up @@ -71,7 +62,6 @@ func (m *kruskal) mergeRandomly() error {
if !wall.IsPresent {
return nil
}
wall.IsPresent = false
var mergeWith *Cell
if len(wall.CellsNear) != 2 {
return fmt.Errorf("the wall with the id %d have only %d cells near", wall.ID, len(wall.CellsNear))
Expand All @@ -83,36 +73,17 @@ func (m *kruskal) mergeRandomly() error {
} else {
return nil
}
wall.IsPresent = false
if mergeWith.ID == cell.ID {
return fmt.Errorf("the cell with the id %d is the same as the cell with the id %d", mergeWith.ID, cell.ID)
}
if len(*cell.MergedRef.MergedCell) >= len(*mergeWith.MergedRef.MergedCell) {
mergeCells(cell, mergeWith)

var f string
for i, c := range m.Cells {
if i != 0 && uint(i)%m.Height == 0 {
println(f)
f = ""
}
f += fmt.Sprintf("%d ", c.ID)
}
println(f)

m.RenderWalls()
return nil
}
mergeCells(mergeWith, cell)

var f string
for i, c := range m.Cells {
if i != 0 && uint(i)%m.Height == 0 {
println(f)
f = ""
}
f += fmt.Sprintf("%d ", c.ID)
}
println(f)

m.RenderWalls()
return nil
}

Expand Down

0 comments on commit 1e9450a

Please sign in to comment.