GoWorld

package module
v0.0.0-...-db4c50c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2020 License: MIT Imports: 3 Imported by: 3

README

GoWorld logo

Simulate beings walking, eating, drinking and mating on randomly generated terrain.

GoWorld

This repository is meant to work as a simple simulation of life. Multiple beings can move around the surface and try to survive. It is not a perfect simulation and not many (if any) laws of nature are implemented. Still a fun little project to showcase the capabilities of go.

The terrain generation is done using Perlin noise, the movement is based on Brownian motion. Everything else is pretty much randomly generated or chosen.

Dependencies

  • ebiten ... a simple game library

Installation

Requirements:
  • Go 1.12 or later (ebiten requirement)
  • dep
Usage

Get the code:

go get -u github.com/rubinda/GoWorld

Get the dependencies:

cd $GOPATH/src/github.com/rubinda/GoWorld
dep ensure

Then, you can choose to either install to GOBIN:

go install cmd/goworld/goworld.go
goworld

... or build in the source folder:

go build -o GoWorld cmd/goworld/goworld.go
./GoWorld

Note: the last two commands (install or build) assume that you are positined at the root folder of this repository and that the appropriate tools and packages are installed. On macOS High Sierra nothing additional was needed, but in case of Ubuntu 20.04 xorg-dev and libgl1-mesa-dev were required)

License

See LICENSE.md

Documentation

Overview

GoWorld is a simulator of life. It places persons on a map and watches them how they move randomly around and interact with each other

@author David Rubin, 2020

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Being

type Being struct {
	ID             uuid.UUID // The identifier
	Hunger         float64   // The desire for food
	Thirst         float64   // The desire for liquid
	WantsChild     float64   // The desire to produce offspring
	LifeExpectancy float64   // How many epochs the being will survive
	VisionRange    float64   // How far the creature can spot objects
	Speed          float64   // How fast the creature can move (faster -> get hungry and thirsty quicker)
	Durability     float64   // More durable creatures need less food and liquids
	Stress         float64   // How stressed the creature is
	// Stress increases when:
	// 	- the being becomes hungrier / thirstier
	//  - does not find a partner to reproduce
	// 	- does not feel safe, e.g. is travelling outside its habitat
	Habitat uuid.UUID // The natural habitat where this creature can be found
	Gender  string    // The gender of the creature
	Size    float64   // Physical size of the creature (bigger need more food and liquid, but are
	// not affected by stress as much)
	Fertility float64 // The number of offspring produced after successful mating with another being
	// The offspring inherit their features from the parents with a random value using the parents values as borders
	MutationRate float64  // How much the attributes can deviate
	Position     Location // Where the creature is currently located in the world
	// The creature can not move on water (Jesus not implemented yet) or on mountain peaks.
	Type string // Being type refers to what it can eat and where it can move:

}

Being is a living creature that is 'living' on the terrain

type Food

type Food struct {
	ID               uuid.UUID // Identifier
	GrowthSpeed      float64   // How fast the food will grow (how many epochs to move to the next growth stage)
	NutritionalValue float64   // How much it decreases the hunger (also possible for minimal thirst decrease)
	Taste            float64   // Tastier food is preferred among creatures (when not too hungry)
	GrowthStage      float64   // The current growth phase of the food
	StageProgress    float64   // Percentage toward next growth stage. Resets when reaching next growth stage
	Area             float64   // How much area it needs to grow (taken as diameter of circle)
	Seeds            float64   // How many offspring can be produced
	SeedDisperse     float64   // How far can the plant throw seeds
	Wither           float64   // How many epochs it can survive
	MutationRate     float64   // How much seedlings can deviate from parent
	Habitat          uuid.UUID // The natural habitat of the plant
	Position         Location  // Static plant location
	Type             string    // Plant type: water or land

}

Food is for now just plants

type Location

type Location struct {
	X, Y int // The lower left corner is deemed as 0,0, X travels horizontally and Y vertically
}

Location represents coordinates of an object

type Pathfinder

type Pathfinder interface {
	GetPath(from, to Location, allowInhabitable bool) []Location // Return a list of neighbouring locations to move to the desired

}

Pathfinder is an interface for path finding implementations

type World

type World interface {
	New() error // create a new world (terrain + creatures + items)

	// Getters
	GetTerrainImage() *image.RGBA                       // Returns the colored terrain as an image
	GetBeings() map[string]*Being                       // Returns all beings currently living in the world map (ID: Being)
	GetFood() map[string]*Food                          // Get all edible food on the map (ID: Food)
	GetSurfaceColorAtSpot(spot Location) color.RGBA     // Returns the color of the surface at a location
	GetSurfaceNameAt(location Location) (string, error) // Returns the common name belonging to the surface at the location
	GetBeingAt(location Location) (uuid.UUID, error)    // Returns the being id at the location (or uuid.Nil if no being)
	GetSize() (int, int)                                // Return width, height of the world
	IsHabitable(location Location) (bool, error)        // Return if the world is inhabitable at the desired location
	IsOutOfBounds(location Location) bool               // Return true if location is outside the defined area
	GetFoodWithID(id uuid.UUID) *Food                   // Returns food with id or nil
	GetBeingWithID(id uuid.UUID) *Being                 // Returns being that belongs to id or nil
	Distance(from, to Location) float64                 // Return distance between locations

	CreateCarnivores(quantity int)              // Create random beings and place them (previous beings should remain)
	CreateFishies(quantity int)                 // Create random beings that live in water
	CreateFlyers(quantity int)                  // Create random beings that can fly
	CreateRandomCarnivore() *Being              // Make a random being (predefined attribute ranges)
	ThrowBeing(b *Being)                        // Place the (NEW) being onto a random map (adjusts its habitat to that spot)
	Wander(b *Being) error                      // Make the provided being move randomly across the terrain
	UpdateBeing(b *Being) (string, []uuid.UUID) // Make the being execute an action based on its needs
	UpdatePlant(p *Food) (string, []uuid.UUID)  // Update plant values, e.g. growth, wither, throw seeds ...

	ProvideFood(landPlants, waterPlants int) // Create edible food with random attributes

	// Stores being and food information into json files
	PlantsToJSON(fileName string)
	BeingsToJSON(fileName string)
}

World is an interface to construct and manage the world with beings (terrain and such)

Directories

Path Synopsis
cmd
goworld command
noise represents methods to generate noise, mainly for terrain generation
noise represents methods to generate noise, mainly for terrain generation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL