alexshafranov / derplanner

Hierarchical-Task-Network planner in C++
zlib License
42 stars 11 forks source link

derplanner

Build Status

derplanner is a:

Here's a sneak peek at domain syntax:

domain turret {
  fact location(vec3, vec3)
  fact target(id32, vec3)

  prim fire!(id32)

  const Fov = cos(pi() / 4.0)

  task attack_visible() {
    each :sorted(1.0 - Dot)
      location(Pos, Dir) & target(Id, Tgt) &
      (Dot = dot(norm(Tgt - Pos), Dir)) & (Dot >= Fov) -> [ fire!(Id) ]
  }
}

Building

derplanner has no external dependencies, so it can be included into your own build system.

Alternatively, you can use premake5 executable shipped with the project to generate project files / makefiles.

Quick Intro

Types

Fact Database

Fact database is a collection of typed tuples, representing domain knowledge about the world.

Domain database requirements are specified in the following way:
fact { location(vec3) target(id32, vec3) }

Primitive Task

Plan is a sequence of primitive task instances, where task instance is a task type and an argument tuple:
goto!(A) melee!(T) goto!(B)

Primitive task is defined in the following way:
prim { goto!(vec3) melee!(id32) }

Compound Task

Compound tasks make the planning process hierarchical and recursive.

Compound task defines one or more cases, where each case is a pre-condition and a task list:

task attack(Bot, Enemy) {
  case pos(Bot, Src) & pos(Enemy, Dst) & dist(Src, Dst) < Close_Range
    -> [ approach(Src, Dst), melee!(Bot, Enemy), retreat(Bot) ]

  case line_of_sight(Bot, Enemy)
    -> [ select_weapon(Bot), fire!(Enemy) ]
}

Task list can contain both primitive and compound task instances. It defines the way to execute a parent compound task.

Planning Process

The plan is formulated in a simple left-to-right and top-to-bottom way:

License

derplanner is licensed under zlib license