extend spec for generating with complexity
parent
95fe38699b
commit
6a5a3f1016
|
|
@ -0,0 +1,24 @@
|
||||||
|
package maze
|
||||||
|
|
||||||
|
type Maze struct {
|
||||||
|
Rows []Row
|
||||||
|
}
|
||||||
|
|
||||||
|
type Row []Room
|
||||||
|
|
||||||
|
type Room struct {
|
||||||
|
Top bool
|
||||||
|
Left bool
|
||||||
|
Right bool
|
||||||
|
Bottom bool
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
1. generate start=>finish
|
||||||
|
1. complexity to determine how many paths [0..100 for % of rooms/2]
|
||||||
|
1. randomly choose a start point
|
||||||
|
1. simulated annealing to generate paths straight vs turn vs end
|
||||||
|
*/
|
||||||
|
func Generate(spec Spec) Maze {
|
||||||
|
return Maze{}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
package maze_test
|
||||||
|
|
@ -5,17 +5,19 @@ type Spec struct {
|
||||||
W uint16
|
W uint16
|
||||||
H uint16
|
H uint16
|
||||||
}
|
}
|
||||||
Seed uint32
|
Complexity byte
|
||||||
|
Seed uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSpec(w, h uint16) Spec {
|
func NewSpec(w, h uint16, complexity byte) Spec {
|
||||||
return NewSpecWithSeed(w, h, NewSeed())
|
return NewSpecWithSeed(w, h, complexity, NewSeed())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSpecWithSeed(w, h uint16, seed uint32) Spec {
|
func NewSpecWithSeed(w, h uint16, complexity byte, seed uint32) Spec {
|
||||||
result := Spec{}
|
result := Spec{}
|
||||||
result.Size.W = w
|
result.Size.W = w
|
||||||
result.Size.H = h
|
result.Size.H = h
|
||||||
|
result.Complexity = complexity
|
||||||
result.Seed = seed
|
result.Seed = seed
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewSpec(t *testing.T) {
|
func TestNewSpec(t *testing.T) {
|
||||||
spec := maze.NewSpec(8, 6)
|
spec := maze.NewSpec(8, 6, 2)
|
||||||
if got := spec.Size.W; got != 8 {
|
if got := spec.Size.W; got != 8 {
|
||||||
t.Error(got)
|
t.Error(got)
|
||||||
} else if got := spec.Size.H; got != 6 {
|
} else if got := spec.Size.H; got != 6 {
|
||||||
t.Error(got)
|
t.Error(got)
|
||||||
|
} else if got := spec.Complexity; got != 2 {
|
||||||
|
t.Error(got)
|
||||||
} else if got := spec.Seed; got == 0 {
|
} else if got := spec.Seed; got == 0 {
|
||||||
t.Error(got)
|
t.Error(got)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue