File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,12 +37,26 @@ func NewRandomisedKruskal(b *Maze) error {
3737 if m .Difficulty > 0 {
3838 size := len (m .Walls )
3939 for n := 0 ; n < int (math .Floor (float64 (size / 4 )* (float64 (m .Difficulty )* 0.05 ))); n ++ {
40- id := uint (utils .RandMax (uint (size - 1 )))
41- i , j := m .GenIJFromIDOfWall (id )
42- if i == 0 || i == m .Width - 1 || j == m .Height - 1 {
43- continue
40+ valid := false
41+ var wall Wall
42+ for ! valid {
43+ id := uint (utils .RandMax (uint (size - 1 )))
44+ i , j := m .GenIJFromIDOfWall (id )
45+ if i == 0 || i == m .Width - 1 || j == m .Height - 1 {
46+ continue
47+ }
48+ wall = m .Walls [id ]
49+ if wall .IsVertical {
50+ if ! (wall .CellsNear [0 ].Disabled || wall .CellsNear [1 ].Disabled ) {
51+ valid = true
52+ }
53+ } else {
54+ if ! wall .CellsNear [0 ].Disabled {
55+ valid = true
56+ }
57+ }
4458 }
45- m . Walls [ id ] .IsPresent = false
59+ wall .IsPresent = false
4660 }
4761 }
4862 println ("Merging done!" )
@@ -114,5 +128,5 @@ func (m *kruskal) mergeRandomly() error {
114128//
115129// Return true if the maze is finished, false otherwise
116130func (m * kruskal ) isFinished () bool {
117- return uint (len (* m .Cells [0 ].MergedRef .MergedCell )) == m .Width * m .Height - m .Inner * m .Inner
131+ return uint (len (* m .Cells [0 ].MergedRef .MergedCell )) == m .Width * m .Height - m .Inner * m .Inner
118132}
You can’t perform that action at this time.
0 commit comments