wfc

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: GPL-3.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tile

type Tile struct {
	Collapsed bool
	Name      string
	Options   []string
}

The tile to be drawn on screen

type Wfc added in v0.9.0

type Wfc struct {
	Tiles       []Tile
	TileEntries map[string]assets.TileEntry
	IsRunning   bool
	// contains filtered or unexported fields
}

func NewWfc added in v0.9.0

func NewWfc(numOfTilesX, numOfTilesY int, tileEntries map[string]assets.TileEntry) *Wfc

NewWfc returns a new WFC with the given number of tiles in the X and Y directions, and the given tile entries.

Parameters: - numOfTilesX: the number of tiles in the X direction. - numOfTilesY: the number of tiles in the Y direction. - tileEntries: a map of tile names to TileEntries.

Returns: - *Wfc: a pointer to a new WFC.

func (*Wfc) CollapseCell added in v0.9.0

func (wfc *Wfc) CollapseCell(index int)

CollapseCell collapses a cell.

Parameters: - cellIndex: the index of the cell to collapse.

Returns:

  • nothing. It modifies the cell at the given index to have a collapsed state with a randomly chosen option.

func (*Wfc) ElaborateCell added in v0.9.0

func (wfc *Wfc) ElaborateCell(x, y int)

ElaborateCell takes an x and y coordinate and elaborates a cell by filtering its available options based on the options of its adjacent cells.

Parameters: - x: the x coordinate of the cell to elaborate. - y: the y coordinate of the cell to elaborate.

Returns:

  • nothing. It modifies the options of the cell at the given x and y coordinates.

func (*Wfc) FilterOptions added in v0.9.0

func (wfc *Wfc) FilterOptions(orig, options []string) []string

FilterOptions filters the original options based on the provided options slice.

It takes in two parameters: - orig []string: the original options slice - options []string: the options to filter by Returns []string: the filtered options slice

func (*Wfc) GetAvailableOptions added in v0.9.0

func (wfc *Wfc) GetAvailableOptions(cellIndex int, direction string) []string

GetAvailableOptions takes a cell index and a direction, and returns a slice of strings that represent all the available options for the given direction.

Parameters: - cellIndex: the index of the cell to retrieve the available options for. - direction: a string representing the direction to retrieve the available options for. Can be "up", "right", "down", or "left".

Returns: - []string: a slice of strings representing the available options

func (*Wfc) IntInSlice added in v0.9.0

func (wfc *Wfc) IntInSlice(a int, slice []int) bool

IntInSlice checks if a given integer is present in a slice of integers.

Parameters: - a: the integer to search for. - slice: the slice of integers to search in.

Returns: - bool: true if the integer is found in the slice, false otherwise.

func (*Wfc) Iterate added in v0.9.0

func (wfc *Wfc) Iterate(numOfTilesX, numOfTilesY int) bool

Iterate collapses one cell with least entropy, then elaborates all cells. The collapsing and elaboration is done concurrently, but the elaboration of each row is done sequentially to avoid race conditions. If all cells are collapsed, it sets IsRunning to false and returns false. Otherwise, it returns true.

func (*Wfc) LeastEntropyCellIndexes added in v0.9.0

func (wfc *Wfc) LeastEntropyCellIndexes() []int

func (*Wfc) RandomOptionWithWeight added in v0.9.0

func (wfc *Wfc) RandomOptionWithWeight(index int) string

func (*Wfc) Reset added in v0.9.0

func (wfc *Wfc) Reset()

func (*Wfc) StartRender added in v0.9.0

func (wfc *Wfc) StartRender()

Jump to

Keyboard shortcuts

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