demo

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

README

OutrigAcres - Idle Farming Game Demo

A demonstration game showcasing Outrig's real-time debugging capabilities for Go applications.

Overview

OutrigAcres is a simple idle farming game with:

  • 30x30 grid game board
  • Different cell types (Empty, Mountain, Wheat, Corn in various growth stages)
  • 8-12 autonomous agents that move around and harvest crops
  • Real-time WebSocket updates to the frontend
  • Integration with Outrig for logging and debugging

Running the Demo

  1. Build the application:

    go build -o outrigacres .
    
  2. Run the server:

    ./outrigacres
    
  3. Open your browser and navigate to:

    http://localhost:8080
    

Game Mechanics

Board
  • 30x30 grid (900 cells total)
  • Cell Types:
    • Empty (light green)
    • Mountain (gray, static obstacles)
    • Wheat: Seed → Growing → Mature → Withered → Empty
    • Corn: Seed → Growing → Mature → Withered → Empty
Cell Lifecycle
  • Empty cells have a 10% chance per tick to spawn new seeds
  • Seeds take 3 ticks to grow
  • Growing crops take 3 ticks to mature
  • Mature crops wither after 8 ticks if not harvested
  • Withered crops return to empty after 3 ticks
Agents
  • 8-12 agents spawn randomly on the board
  • Move 1 square per tick (1 second intervals)
  • Prioritize nearest mature crop within radius 5
  • Harvest crops instantly upon arrival
  • Move randomly if no crops are in range

Outrig Integration

The game demonstrates Outrig's capabilities:

  • Real-time logging: All game events are logged (agent movements, harvests, crop changes)
  • Goroutine monitoring: Game loop runs in a named goroutine using outrig.Go("game-loop")
  • WebSocket communication: Real-time updates between Go backend and JavaScript frontend

Frontend

  • HTML/CSS/JavaScript frontend embedded in the Go binary
  • WebSocket connection for real-time game state updates
  • Visual representation of the game board with colored tiles and numbered agents
  • Speed controls (UI placeholder for future server-side implementation)

File Structure

demo/
├── main-outrigacres.go  # Go backend with game logic
├── go.mod               # Go module definition
├── README.md            # This file
├── frontend/
│   ├── index.html       # Main HTML page
│   ├── game.css         # Styling for game board and agents
│   ├── game.js          # JavaScript game client
│   └── assets/          # Directory for future game assets
└── outrigacres          # Compiled binary (after build)

Development Notes

  • The frontend files are embedded using //go:embed frontend/*
  • Game state is synchronized via JSON over WebSocket
  • All game logic runs server-side for consistency
  • CSS provides simple colored tiles and numbered agent circles
  • Future enhancements could include PNG sprites in the assets directory

Documentation

Index

Constants

View Source
const (
	BoardSize = 30

	// Server constants
	PreferredPort = 22005 // Preferred port for the demo server

	// Crop timing constants
	GrowTicks   = 5  // Ticks for seed to grow to growing stage
	MatureTicks = 12 // Ticks for growing to mature stage
	WitherTicks = 4  // Ticks for withered crops to disappear

	// Agent search constants
	MaxSearchRadius = 12 // Maximum Manhattan distance to search for targets

	// Cell types
	CellEmpty       = "empty"
	CellMountain    = "mountain"
	CellWheatSeed   = "wheat_seed"
	CellWheatGrow   = "wheat_growing"
	CellWheatMature = "wheat_mature"
	CellWheatWither = "wheat_withered"
)

Variables

This section is empty.

Functions

func RunOutrigAcres

func RunOutrigAcres(config Config)

Types

type Agent

type Agent struct {
	ID        int     `json:"id"`
	X         int     `json:"x"`
	Y         int     `json:"y"`
	TargetX   int     `json:"targetx"`
	TargetY   int     `json:"targety"`
	Score     int     `json:"score"`
	MoveSpeed float64 `json:"movespeed"`
	// contains filtered or unexported fields
}

type AgentUpdate

type AgentUpdate struct {
	Type      string `json:"type"`
	AgentID   int    `json:"agentid"`
	X         int    `json:"x"`
	Y         int    `json:"y"`
	Harvested bool   `json:"harvested"`
}

type BoardUpdate

type BoardUpdate struct {
	Type   string   `json:"type"`
	Board  [][]Cell `json:"board"`
	Tick   int      `json:"tick"`
	Paused bool     `json:"paused"`
}

type Cell

type Cell struct {
	Type     string `json:"type"`
	TicksAge int    `json:"ticksage"`
}

type Config

type Config struct {
	DevMode         bool `json:"devmode"`
	NoBrowserLaunch bool `json:"nobrowserlaunch"`
	Port            int  `json:"port"`
	CloseOnStdin    bool `json:"closeonstdin"`
}

Config holds configuration options for OutrigAcres

type Game

type Game struct {
	// contains filtered or unexported fields
}

func NewGame

func NewGame() *Game

func (*Game) IsPaused

func (g *Game) IsPaused() bool

func (*Game) SetPaused

func (g *Game) SetPaused(paused bool)

func (*Game) Start

func (g *Game) Start()

func (*Game) Stop

func (g *Game) Stop()

type GameState

type GameState struct {
	Board  [][]Cell `json:"board"`
	Agents []*Agent `json:"agents"`
	Tick   int      `json:"tick"`
	Paused bool     `json:"paused"`
}

Jump to

Keyboard shortcuts

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