From 6a5a3f1016df18e6ec5c2541de72f40c36e2f097 Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 16 Jul 2023 14:07:14 -0600 Subject: [PATCH] extend spec for generating with complexity --- src/game/maze/generate.go | 24 ++++++++++++++++++++++++ src/game/maze/generate_test.go | 1 + src/game/maze/spec.go | 10 ++++++---- src/game/maze/spec_test.go | 4 +++- 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 src/game/maze/generate.go create mode 100644 src/game/maze/generate_test.go diff --git a/src/game/maze/generate.go b/src/game/maze/generate.go new file mode 100644 index 0000000..7839877 --- /dev/null +++ b/src/game/maze/generate.go @@ -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{} +} diff --git a/src/game/maze/generate_test.go b/src/game/maze/generate_test.go new file mode 100644 index 0000000..e5c863a --- /dev/null +++ b/src/game/maze/generate_test.go @@ -0,0 +1 @@ +package maze_test diff --git a/src/game/maze/spec.go b/src/game/maze/spec.go index 6210cb4..fc80f28 100644 --- a/src/game/maze/spec.go +++ b/src/game/maze/spec.go @@ -5,17 +5,19 @@ type Spec struct { W uint16 H uint16 } - Seed uint32 + Complexity byte + Seed uint32 } -func NewSpec(w, h uint16) Spec { - return NewSpecWithSeed(w, h, NewSeed()) +func NewSpec(w, h uint16, complexity byte) Spec { + 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.Size.W = w result.Size.H = h + result.Complexity = complexity result.Seed = seed return result } diff --git a/src/game/maze/spec_test.go b/src/game/maze/spec_test.go index a339c13..3515170 100644 --- a/src/game/maze/spec_test.go +++ b/src/game/maze/spec_test.go @@ -7,11 +7,13 @@ import ( ) func TestNewSpec(t *testing.T) { - spec := maze.NewSpec(8, 6) + spec := maze.NewSpec(8, 6, 2) if got := spec.Size.W; got != 8 { t.Error(got) } else if got := spec.Size.H; got != 6 { t.Error(got) + } else if got := spec.Complexity; got != 2 { + t.Error(got) } else if got := spec.Seed; got == 0 { t.Error(got) }