Documentation ¶
Index ¶
- type RandomSimple
- type Randomer
- type RandomerMock
- type SimulationEngine
- func (s *SimulationEngine) Finalize(ctx context.Context) error
- func (s *SimulationEngine) HasNextStep(ctx context.Context) (bool, error)
- func (s *SimulationEngine) Prepare(ctx context.Context) error
- func (s *SimulationEngine) Run(ctx context.Context) error
- func (s *SimulationEngine) SimulateNextStep(ctx context.Context) error
- type Simulator
- type SimulatorMock
- func (s *SimulatorMock) Finalize(ctx context.Context) error
- func (s *SimulatorMock) HasNextStep(ctx context.Context) (bool, error)
- func (s *SimulatorMock) Prepare(ctx context.Context) error
- func (s *SimulatorMock) Run(ctx context.Context) error
- func (s *SimulatorMock) SimulateNextStep(ctx context.Context) error
- type World
- func (w *World) AddAlien(ctx context.Context, alienID int) (*entity.Alien, error)
- func (w *World) AddCity(ctx context.Context, cityName string) (*entity.City, error)
- func (w *World) AddLink(ctx context.Context, cityFrom, cityTo *entity.City, direction entity.Direction) error
- func (w *World) DestroyCity(ctx context.Context, city *entity.City) error
- func (w *World) GetAlien(ctx context.Context, alienID int) (*entity.Alien, error)
- func (w *World) GetAlienAtCity(ctx context.Context, city *entity.City) (*entity.Alien, error)
- func (w *World) GetAliveCities(ctx context.Context) ([]*entity.City, error)
- func (w *World) GetCity(ctx context.Context, cityName string) (*entity.City, error)
- func (w *World) GetUntrappedAliens(ctx context.Context) ([]*entity.Alien, error)
- func (w *World) IsTrappedAlien(ctx context.Context, alien *entity.Alien) (bool, error)
- func (w *World) MoveAlien(ctx context.Context, alien *entity.Alien, city *entity.City) error
- func (w *World) TrapAlien(ctx context.Context, alien *entity.Alien) error
- type WorldStorer
- type WorldStorerMock
- func (w *WorldStorerMock) AddAlien(ctx context.Context, alienID int) (*entity.Alien, error)
- func (w *WorldStorerMock) AddCity(ctx context.Context, cityName string) (*entity.City, error)
- func (w *WorldStorerMock) AddLink(ctx context.Context, cityFrom, cityTo *entity.City, direction entity.Direction) error
- func (w *WorldStorerMock) DestroyCity(ctx context.Context, city *entity.City) error
- func (w *WorldStorerMock) GetAlien(ctx context.Context, alienID int) (*entity.Alien, error)
- func (w *WorldStorerMock) GetAlienAtCity(ctx context.Context, city *entity.City) (*entity.Alien, error)
- func (w *WorldStorerMock) GetAliveCities(ctx context.Context) ([]*entity.City, error)
- func (w *WorldStorerMock) GetCity(ctx context.Context, cityName string) (*entity.City, error)
- func (w *WorldStorerMock) GetUntrappedAliens(ctx context.Context) ([]*entity.Alien, error)
- func (w *WorldStorerMock) IsTrappedAlien(ctx context.Context, alien *entity.Alien) (bool, error)
- func (w *WorldStorerMock) MoveAlien(ctx context.Context, alien *entity.Alien, city *entity.City) error
- func (w *WorldStorerMock) TrapAlien(ctx context.Context, alien *entity.Alien) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RandomSimple ¶
type RandomSimple struct { }
RandomSimple is a simple random integer generator Important: it does not rely on crypto safe random generator
func NewRandomSimple ¶
func NewRandomSimple() *RandomSimple
NewRandomSimple is a simple random generator
func (*RandomSimple) GetRandomInt ¶
func (rs *RandomSimple) GetRandomInt(n int) (int, error)
GetRandomInt retrieves a random integer between 0 and n-1 given n Returns an error if n <= 0
type Randomer ¶
type Randomer interface { // GetRandomInt retrieves a random integer between 0 and n-1 given n GetRandomInt(n int) (int, error) }
Randomer is a random generator
type RandomerMock ¶
RandomerMock mocks a Randomer
func (*RandomerMock) GetRandomInt ¶
func (r *RandomerMock) GetRandomInt(n int) (int, error)
GetRandomInt retrieves a random integer between 0 and n-1 given n
type SimulationEngine ¶
type SimulationEngine struct {
// contains filtered or unexported fields
}
SimulationEngine is a simple implementation of an alien invasion simulator
func NewSimulationEngine ¶
func NewSimulationEngine(startAliens, maxSteps uint, world WorldStorer, random Randomer, in io.Reader, out io.Writer) *SimulationEngine
NewSimulationEngine is a simulation engine constructor
func (*SimulationEngine) Finalize ¶
func (s *SimulationEngine) Finalize(ctx context.Context) error
Finalize finalizes the simulation
func (*SimulationEngine) HasNextStep ¶
func (s *SimulationEngine) HasNextStep(ctx context.Context) (bool, error)
HasNextStep computes if a next step of the simulation exists
func (*SimulationEngine) Prepare ¶
func (s *SimulationEngine) Prepare(ctx context.Context) error
Prepare prepares the simulation
func (*SimulationEngine) Run ¶
func (s *SimulationEngine) Run(ctx context.Context) error
Run simulates an alien invasion
func (*SimulationEngine) SimulateNextStep ¶
func (s *SimulationEngine) SimulateNextStep(ctx context.Context) error
SimulateNextStep simulates the next step of the simulation
type Simulator ¶
type Simulator interface { // Prepare prepares the simulation Prepare(ctx context.Context) error // HasNextStep computes if a next step of the simulation exists HasNextStep(ctx context.Context) (bool, error) // SimulateNextStep simulates the next step of the simulation SimulateNextStep(ctx context.Context) error // Run simulates an alien invasion Run(ctx context.Context) error // Finalize finalizes the simulation Finalize(ctx context.Context) error }
Simulator is an alien invasion simulator interface
type SimulatorMock ¶
SimulatorMock mocks a Simulator
func (*SimulatorMock) Finalize ¶
func (s *SimulatorMock) Finalize(ctx context.Context) error
Finalize finalizes the simulation
func (*SimulatorMock) HasNextStep ¶
func (s *SimulatorMock) HasNextStep(ctx context.Context) (bool, error)
HasNextStep computes if a next step of the simulation exists
func (*SimulatorMock) Prepare ¶
func (s *SimulatorMock) Prepare(ctx context.Context) error
Prepare prepares the simulation
func (*SimulatorMock) Run ¶
func (s *SimulatorMock) Run(ctx context.Context) error
Run simulates an alien invasion
func (*SimulatorMock) SimulateNextStep ¶
func (s *SimulatorMock) SimulateNextStep(ctx context.Context) error
SimulateNextStep simulates the next step of the simulation
type World ¶
type World struct {
// contains filtered or unexported fields
}
World represents the world with cities, aliens, and links
func (*World) AddLink ¶
func (w *World) AddLink(ctx context.Context, cityFrom, cityTo *entity.City, direction entity.Direction) error
AddLink adds a link from a city to another city given a direction
func (*World) DestroyCity ¶
DestroyCity destroys a city
func (*World) GetAlienAtCity ¶
GetAlienAtCity retrieves the alien at a city
func (*World) GetAliveCities ¶
GetAliveCities retrieves the list of non destroyed cities
func (*World) GetUntrappedAliens ¶
GetUntrappedAliens retrieves the list of untrapped aliens
func (*World) IsTrappedAlien ¶
IsTrappedAlien checks if an alien is trapped
type WorldStorer ¶
type WorldStorer interface { // GetCity retrieves a city GetCity(ctx context.Context, cityName string) (*entity.City, error) // GetAliveCities retrieves the list of non destroyed cities GetAliveCities(ctx context.Context) ([]*entity.City, error) // AddCity adds a city AddCity(ctx context.Context, cityName string) (*entity.City, error) // DestroyCity destroys a city DestroyCity(ctx context.Context, city *entity.City) error // AddLink adds a link from a city to another city given a direction AddLink(ctx context.Context, cityFrom, cityTo *entity.City, direction entity.Direction) error // GetAlien retrieves an alien GetAlien(ctx context.Context, alienID int) (*entity.Alien, error) // AddAlien adds an alien AddAlien(ctx context.Context, alienID int) (*entity.Alien, error) // MoveAlien moves an alien to a city MoveAlien(ctx context.Context, alien *entity.Alien, city *entity.City) error // IsTrappedAlien checks if an alien is trapped IsTrappedAlien(ctx context.Context, alien *entity.Alien) (bool, error) // TrapAlien traps an alien TrapAlien(ctx context.Context, alien *entity.Alien) error // GetAlienAtCity retrieves the alien at a given city GetAlienAtCity(ctx context.Context, city *entity.City) (*entity.Alien, error) // GetUntrappedAliens retrieves the list of untrapped aliens GetUntrappedAliens(ctx context.Context) ([]*entity.Alien, error) }
WorldStorer is a world store interface
type WorldStorerMock ¶
WorldStorerMock mocks a WorldStorer
func (*WorldStorerMock) AddLink ¶
func (w *WorldStorerMock) AddLink(ctx context.Context, cityFrom, cityTo *entity.City, direction entity.Direction) error
AddLink adds a link from a city to another city given a direction
func (*WorldStorerMock) DestroyCity ¶
DestroyCity destroys a city
func (*WorldStorerMock) GetAlienAtCity ¶
func (w *WorldStorerMock) GetAlienAtCity(ctx context.Context, city *entity.City) (*entity.Alien, error)
GetAlienAtCity retrieves the alien at a given city
func (*WorldStorerMock) GetAliveCities ¶
GetAliveCities retrieves the list of non destroyed cities
func (*WorldStorerMock) GetUntrappedAliens ¶
GetUntrappedAliens retrieves the list of untrapped aliens
func (*WorldStorerMock) IsTrappedAlien ¶
IsTrappedAlien checks if an alien is trapped