Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingmidas74 committed Dec 24, 2023
1 parent e029959 commit 8cd754b
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 115 deletions.
19 changes: 18 additions & 1 deletion cmd/wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
package main

import (
"github.com/kingmidas74/gonesis-engine/internal/domain/contract"
"github.com/kingmidas74/gonesis-engine/internal/domain/entity/maze_generator_collection"
"github.com/kingmidas74/gonesis-engine/internal/service/agent"
"github.com/kingmidas74/gonesis-engine/internal/service/world"
"github.com/kingmidas74/gonesis-engine/pkg/maze/generator/aldous_broder"
"github.com/kingmidas74/gonesis-engine/pkg/maze/generator/binary"
"github.com/kingmidas74/gonesis-engine/pkg/maze/generator/border"
"github.com/kingmidas74/gonesis-engine/pkg/maze/generator/empty"
"github.com/kingmidas74/gonesis-engine/pkg/maze/generator/grid"
"github.com/kingmidas74/gonesis-engine/pkg/maze/generator/sidewinder"
"syscall/js"

"github.com/kingmidas74/gonesis-engine/internal/handler/wasm"
Expand All @@ -19,13 +27,22 @@ func main() {
randomIntGenerator := randomize_int.New()
randomFloatGenerator := randomize_float.New()

mazeGeneratorCollection := maze_generator_collection.New()
mazeGeneratorCollection.Register(contract.MazeTypeAldousBroder, aldous_broder.New(aldous_broder.Params{RandomIntGenerator: randomIntGenerator}))
mazeGeneratorCollection.Register(contract.MazeTypeBinary, binary.New(binary.Params{RandomIntGenerator: randomIntGenerator}))
mazeGeneratorCollection.Register(contract.MazeTypeGrid, grid.New())
mazeGeneratorCollection.Register(contract.MazeTypeBorder, border.New())
mazeGeneratorCollection.Register(contract.MazeTypeSideWinder, sidewinder.New(sidewinder.Params{RandomIntGenerator: randomIntGenerator}))
mazeGeneratorCollection.Register(contract.MazeTypeEmpty, empty.New())

agentService := agent.New(agent.Params{
RandomIntGenerator: randomIntGenerator,
RandomFloatGenerator: randomFloatGenerator,
})

worldService := world.New(world.Params{
AgentService: agentService,
AgentService: agentService,
MazeGeneratorCollection: mazeGeneratorCollection,
})

WasmHandler, _ = wasm.New(wasm.Params{
Expand Down
12 changes: 1 addition & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,19 @@ require (
github.com/google/uuid v1.3.0
github.com/stretchr/testify v1.8.2
go.uber.org/fx v1.20.0
go.uber.org/mock v0.3.0
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc
golang.org/x/net v0.10.0
)

require (
github.com/cucumber/gherkin/go/v26 v26.2.0 // indirect
github.com/cucumber/godog v0.13.0 // indirect
github.com/cucumber/messages/go/v21 v21.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gofrs/uuid v4.3.1+incompatible // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-memdb v1.3.4 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/dig v1.17.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
28 changes: 4 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,49 +1,31 @@
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cristalhq/aconfig v0.17.0/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E=
github.com/cristalhq/aconfig v0.18.4 h1:Z0I0NN8LTohitqrkv/C54sQD4SIeXdTCJwFIXhdVA2A=
github.com/cristalhq/aconfig v0.18.4/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E=
github.com/cristalhq/aconfig/aconfigyaml v0.17.1 h1:xCCbRKVmKrft9gQj3gHOq6U5PduasvlXEIsxtyzmFZ0=
github.com/cristalhq/aconfig/aconfigyaml v0.17.1/go.mod h1:5DTsjHkvQ6hfbyxfG32roB1lF0U82rROtFaLxibL8V8=
github.com/cucumber/gherkin/go/v26 v26.2.0/go.mod h1:t2GAPnB8maCT4lkHL99BDCVNzCh1d7dBhCLt150Nr/0=
github.com/cucumber/godog v0.13.0/go.mod h1:FX3rzIDybWABU4kuIXLZ/qtqEe1Ac5RdXmqvACJOces=
github.com/cucumber/messages/go/v21 v21.0.1/go.mod h1:zheH/2HS9JLVFukdrsPWoPdmUtmYQAQPLk7w5vWsk5s=
github.com/cucumber/messages/go/v22 v22.0.0/go.mod h1:aZipXTKc0JnjCsXrJnuZpWhtay93k7Rn3Dee7iyPJjs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0=
github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.3.1+incompatible h1:0/KbAdpx3UXAx1kEOWHJeOkpbgRFGHVgv+CFIY7dBJI=
github.com/gofrs/uuid v4.3.1+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-memdb v1.3.4/go.mod h1:uBTr1oQbtuMgd1SSGoR8YV27eT3sBHbYiNm53bMpgSg=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
Expand All @@ -52,8 +34,6 @@ go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU=
go.uber.org/fx v1.20.0 h1:ZMC/pnRvhsthOZh9MZjMq5U8Or3mA9zBSPaLnzs3ihQ=
go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo=
go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
Expand All @@ -66,8 +46,8 @@ golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
7 changes: 7 additions & 0 deletions internal/domain/contract/maze_generator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package contract

import "github.com/kingmidas74/gonesis-engine/pkg/maze/cell"

type MazeGenerator interface {
Generate(width, height int) ([]cell.Cell, error)
}
15 changes: 15 additions & 0 deletions internal/domain/entity/maze_generator_collection/collection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package maze_generator_collection

import "github.com/kingmidas74/gonesis-engine/internal/domain/contract"

func (c *MazeGeneratorCollection) Register(mazeType contract.MazeType, mazeGenerator contract.MazeGenerator) {
c.mazeGenerators[mazeType] = mazeGenerator
}

func (c *MazeGeneratorCollection) Get(mazeType contract.MazeType) (contract.MazeGenerator, error) {
mazeGenerator, ok := c.mazeGenerators[mazeType]
if !ok {
return nil, ErrMazeGenerationTypeIsNotSupported
}
return mazeGenerator, nil
}
18 changes: 18 additions & 0 deletions internal/domain/entity/maze_generator_collection/constructor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package maze_generator_collection

import (
"errors"
"github.com/kingmidas74/gonesis-engine/internal/domain/contract"
)

type MazeGeneratorCollection struct {
mazeGenerators map[contract.MazeType]contract.MazeGenerator
}

func New() *MazeGeneratorCollection {
return &MazeGeneratorCollection{
mazeGenerators: map[contract.MazeType]contract.MazeGenerator{},
}
}

var ErrMazeGenerationTypeIsNotSupported = errors.New("maze generation type is not supported")
12 changes: 10 additions & 2 deletions internal/service/world/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ import (

type Params struct {
AgentService agent.Service

MazeGeneratorCollection MazeGeneratorCollection
}

type srv struct {
world contract.World

agentService agent.Service
agentService agent.Service
mazeGeneratorCollection MazeGeneratorCollection
}

func New(params Params) Service {
return &srv{
agentService: params.AgentService,
agentService: params.AgentService,
mazeGeneratorCollection: params.MazeGeneratorCollection,
}
}

type MazeGeneratorCollection interface {
Get(mazeType contract.MazeType) (contract.MazeGenerator, error)
}
77 changes: 35 additions & 42 deletions internal/service/world/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,54 @@ package world

import (
"github.com/kingmidas74/gonesis-engine/internal/domain/configuration"
contract "github.com/kingmidas74/gonesis-engine/internal/domain/contract"
"github.com/kingmidas74/gonesis-engine/internal/domain/contract"
"github.com/kingmidas74/gonesis-engine/internal/domain/entity/cell"
"github.com/kingmidas74/gonesis-engine/pkg/graph_maze/empty"
"github.com/kingmidas74/gonesis-engine/pkg/graph_topology/neumann"
"github.com/kingmidas74/gonesis-engine/internal/domain/entity/terrain"
"github.com/kingmidas74/gonesis-engine/internal/domain/entity/topology/moore"
"github.com/kingmidas74/gonesis-engine/internal/domain/entity/world"
)

func (s *srv) Init(config *configuration.Configuration) (contract.World, error) {
ng := neumann.New[cell.Cell]()
g, err := ng.Generate(config.WorldConfiguration.Ratio.Width, config.WorldConfiguration.Ratio.Height)
mazeGenerator, err := s.mazeGeneratorCollection.Get(config.WorldConfiguration.MazeType)
if err != nil {
return nil, err
}
cells, err := mazeGenerator.Generate(config.WorldConfiguration.Ratio.Width, config.WorldConfiguration.Ratio.Height)
if err != nil {
return nil, err
}

mg := empty.New[cell.Cell, neumann.VertexID]()
mg.Generate(g, g.FindVertex(neumann.VertexID{X: 0, Y: 0}))

/*
cells, err := empty.New().Generate(config.WorldConfiguration.Ratio.Width, config.WorldConfiguration.Ratio.Height)
if err != nil {
return nil, err
}
terrainCells := make([]contract.Cell, len(cells))
for i, c := range cells {
terrainCells[i] = cell.New(c.X(), c.Y(), cell.WallInfo{
North: c.NorthWall(),
East: c.EastWall(),
South: c.SouthWall(),
West: c.WestWall(),
})
}
topology := moore.New()
terra := terrain.New(terrain.MazeInfo{
Width: config.WorldConfiguration.Ratio.Width,
Height: config.WorldConfiguration.Ratio.Height,
Cells: terrainCells,
}, terrain.WithTopology(topology))
terrainCells := make([]contract.Cell, len(cells))
for i, c := range cells {
terrainCells[i] = cell.New(c.X(), c.Y(), cell.WallInfo{
North: c.NorthWall(),
East: c.EastWall(),
South: c.SouthWall(),
West: c.WestWall(),
})
}

agents, err := s.agentService.Generate(config)
if err != nil {
return nil, err
}
topology := moore.New()
terra := terrain.New(terrain.MazeInfo{
Width: config.WorldConfiguration.Ratio.Width,
Height: config.WorldConfiguration.Ratio.Height,
Cells: terrainCells,
}, terrain.WithTopology(topology))

w := world.New(world.WithTerrain(terra))
agents, err := s.agentService.Generate(config)
if err != nil {
return nil, err
}

err = w.PlaceAgents(agents)
if err != nil {
return nil, err
}
w := world.New(world.WithTerrain(terra))

s.world = w
return w, nil
err = w.PlaceAgents(agents)
if err != nil {
return nil, err
}

*/
s.world = w
return w, nil
}

func (s *srv) Update(config *configuration.Configuration) (contract.World, error) {
Expand Down
35 changes: 0 additions & 35 deletions internal/service/world/service_test.go

This file was deleted.

1 change: 1 addition & 0 deletions web/scripts/services/data-access/wasm/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Engine extends IDataClient {
initWorld(configurationProvider) {
const response = this.#windowProvider.initWorld(this.#JSONProvider.stringify(configurationProvider.getInstance()))
let r = this.#parseResponse(response);
console.log("world", r)
return r
}

Expand Down

0 comments on commit 8cd754b

Please sign in to comment.