Help us shape the future of Go! Take the 2026 Go Developer Survey

generate

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

DEPRECATED: This package is deprecated. Use parable-bloom/tools/level-builder instead. See: parable-bloom/tools/level-builder/cmd/generate/generate.go

Index

Constants

This section is empty.

Variables

View Source
var LevelGenerateCmd = &cobra.Command{
	Use:   "level-generate",
	Short: "Generate a new game level",
	Long: `Generate a new game level for the Parable Bloom project.
This command creates solvable levels with the required structure and metadata.`,
	Run: func(cmd *cobra.Command, _args []string) {
		isVerbose := utils.IsVerbose(cmd)
		log.Start("Generating game levels")

		name, _ := cmd.Flags().GetString("name")
		moduleID, _ := cmd.Flags().GetInt("module")
		width, _ := cmd.Flags().GetInt("grid-width")
		height, _ := cmd.Flags().GetInt("grid-height")
		output, _ := cmd.Flags().GetString("output")
		stdout, _ := cmd.Flags().GetBool("stdout")
		overwrite, _ := cmd.Flags().GetBool("overwrite")
		count, _ := cmd.Flags().GetInt("count")
		seed, _ := cmd.Flags().GetInt64("seed")
		randomize, _ := cmd.Flags().GetBool("randomize")
		render, _ := cmd.Flags().GetBool("render")
		renderStyle, _ := cmd.Flags().GetString("render-style")
		renderCoords, _ := cmd.Flags().GetBool("render-coords")
		difficultyFlag, _ := cmd.Flags().GetString("difficulty")

		if difficultyFlag != "" {
			validDifficulties := []string{"Tutorial", "Seedling", "Sprout", "Nurturing", "Flourishing", "Transcendent"}
			found := false
			for _, d := range validDifficulties {
				if d == difficultyFlag {
					found = true
					break
				}
			}
			if !found {
				log.Error(
					"Invalid difficulty '%s'. Valid options: %s",
					difficultyFlag,
					strings.Join(validDifficulties, ", "),
				)
				os.Exit(1)
			}
		}

		if output == "" {
			output = "assets/levels"
		}

		modules, err := common.LoadModules("")
		if err != nil {
			log.Error("Failed to load modules: %v", err)
			os.Exit(1)
		}

		if moduleID > 0 && count == 1 {
			if moduleID <= len(modules) {
				moduleRange := modules[moduleID-1]
				count = moduleRange.End - moduleRange.Start + 1
				log.Verbose(
					isVerbose,
					"Module %d specified, setting count to %d levels (%d-%d)",
					moduleID,
					count,
					moduleRange.Start,
					moduleRange.End,
				)
			} else {
				log.Error("Invalid module ID: %d (must be 1-%d)", moduleID, len(modules))
				os.Exit(1)
			}
		}

		if count > 1 {

			generateBatch(
				modules,
				moduleID,
				count,
				output,
				overwrite,
				isVerbose,
				seed,
				randomize,
				render,
				renderStyle,
				renderCoords,
			)
		} else {

			generateSingle(
				name,
				width,
				height,
				output,
				stdout,
				overwrite,
				modules,
				isVerbose,
				seed,
				randomize,
				render,
				renderStyle,
				renderCoords,
				difficultyFlag,
			)
		}
	},
}

LevelGenerateCmd represents the 'parable-bloom level-generate' command for generating new game levels. It provides tools to scaffold and generate new level files for the Parable Bloom game.

Functions

func CreateGameLevel added in v0.30.1

func CreateGameLevel(
	id int,
	name, difficulty string,
	width, height int,
	verbose bool,
	seed int64,
	randomize bool,
) *common.Level

func FastScoreBlocking

func FastScoreBlocking(vines []common.Vine, gridSize [2]int) (float64, int)

FastScoreBlocking computes a simple blocking score and maximum blocking depth for a set of vines on a grid. It mutates vine.Blocks via calculateBlocking.

func GrowFromSeed

func GrowFromSeed(
	seed common.Point,
	occupied map[string]bool,
	gridSize [2]int,
	targetLen int,
	profile common.VarietyProfile,
	_ common.GeneratorConfig,
	rng *rand.Rand,
) (common.Vine, map[string]bool, error)

GrowFromSeed attempts to grow a vine starting from seed, avoiding occupied cells. It returns the vine and the updated occupancy map on success.

func SweepParams

func SweepParams(difficulty string, iters int) (float64, common.GeneratorConfig, common.VarietyProfile, int64)

SweepParams runs the parameter sweep and returns the best results.

func TileGridIntoVines

func TileGridIntoVines(
	gridSize [2]int,
	constraints common.DifficultySpec,
	profile common.VarietyProfile,
	cfg common.GeneratorConfig,
	rng *rand.Rand,
) ([]common.Vine, *common.Mask, error)

TileGridIntoVines partitions the grid into vines according to the provided difficulty constraints and a variety profile. It returns vines and a mask for empty cells.

Types

type GenerationResult

type GenerationResult struct {
	Vines            []common.Vine
	Score            float64
	MaxBlockingDepth int
	GreedySolvable   bool
	BFSSolvable      bool
	Attempts         int
	SeedUsed         int64 // seed used for the successful variant
	ElapsedMS        int64 // generation time in milliseconds
	Mask             *common.Mask
}

GenerationResult contains metadata about a generation attempt.

func CreateLevelWithProfile added in v0.30.1

func CreateLevelWithProfile(
	gridSize [2]int,
	constraints common.DifficultySpec,
	profile common.VarietyProfile,
	cfg common.GeneratorConfig,
	seed int64,
	strictMode bool,
	rng *rand.Rand,
) GenerationResult

CreateLevelWithProfile tries to create a tiled level using the given profile and config. It runs fast pre-validation and greedy solver gating; optionally runs BFS for final verification if strictMode is true. It returns a GenerationResult containing score and solvability flags.

Jump to

Keyboard shortcuts

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