Giter Site home page Giter Site logo

jamiecollinson / go-goap Goto Github PK

View Code? Open in Web Editor NEW
15.0 5.0 0.0 6 KB

Goal Oriented Action Planning for Golang

License: MIT License

Go 100.00%
golang go goap goal-oriented-action-planning ai artificial-intelligence planning-algorithms planning

go-goap's Introduction

Goal Oriented Action Planning for Golang

Introduction

Goal Oriented Action Planning (GOAP) is a powerful technique for introducing intelligent planning to agent simulations. It's often used in game AI, but has applications and roots in more general planning / optimisation work. It's most commonly associated with Jeff Orkin and the game F.E.A.R. which used the approach to give enemies convincing behaviour.

This package implements GOAP in Go.

Example

Given a simple scenario where an agent may fight an enemy unarmed (high cost but no pre-conditions), pick up a gun (low cost and no pre-conditions) or shoot an enemy (low cost but requires gun picked up first) our agent will attempt to pick the sequence of actions which achieves it's goals with the lowest cost.

// from cmd/main.go
emptyState := goap.State{}

fightEnemyHandToHandAction := goap.CreateAction("fight enemy hand to hand", 10, emptyState, goap.State{"killedEnemy": true})
pickupGunAction := goap.CreateAction("pick up gun", 1, emptyState, goap.State{"armed": true})
shootEnemyAction := goap.CreateAction("shoot enemy", 1, goap.State{"armed": true}, goap.State{"killedEnemy": true})

agent := goap.Agent{
	Actions: []goap.Action{
		fightEnemyHandToHandAction,
		pickupGunAction,
		shootEnemyAction,
	},
	WorldState: emptyState,
	Goals: goap.State{
		"killedEnemy": true,
	},	
}

fmt.Println(agent.GetBestPlan())

Results in the following plan (sequence of actions) and cost:

> go run cmd/main.go
[pick up gun, shoot enemy] 2

Status

Currently alpha quality. It works but may have rough edges, and in particular the search for action plans is currently exhaustive and so suffers from combinatorial explosion making it unsuitable for large action spaces. Mature implementations use (e.g.) A* for search.

Todo

  • Improve docs
  • Add A* search for action plans
  • Refactor API

Further reading

go-goap's People

Contributors

jamiecollinson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.