Skip to content

Instantly share code, notes, and snippets.

@simonwittber
Created May 1, 2019 12:56
Show Gist options
  • Save simonwittber/8e5400b0acb9661e968e35f6233efce8 to your computer and use it in GitHub Desktop.
Save simonwittber/8e5400b0acb9661e968e35f6233efce8 to your computer and use it in GitHub Desktop.
DSL for HTN declaration.
public class AI
{
Domain CreateDomain()
{
using (domain = Domain.New())
{
worldState = DefineWorldState(health, fuel, speed, angularSpeed);
DefinePrimitiveTask(SetRandomDestination);
DefinePrimitiveTask(MoveToDestination)
.Conditions(angularSpeed < 1)
.Conditions(speed < 50);
DefinePrimitiveTask(SetAutoPilotDestination);
DefinePrimitiveTask(autoPilot.Pause);
DefinePrimitiveTask(autoPilot.Resume);
DefinePrimitiveTask(shipMotor.EnableRotationalDamping)
.Effects(angularSpeed.Set(0));
DefinePrimitiveTask(shipMotor.DisableRotationalDamping);
DefinePrimitiveTask(shipMotor.EnableTranslationDamping)
.Effects(speed.Set(0));
DefinePrimitiveTask(shipMotor.DisableTranslationDamping);
DefineCompoundTask("Main")
.DefineMethod("MoveSomewhereRandom")
.Conditions(health > 1, angularSpeed < 1)
.Tasks(shipMotor.DisableRotationalDamping, shipMotor.DisableTranslationDamping, SetRandomDestination, SetAutoPilotDestination, autoPilot.Resume, MoveToDestination)
.DefineMethod("StopSpinning")
.Conditions(angularSpeed > 1, speed < 50)
.Tasks(autoPilot.Pause, shipMotor.EnableRotationalDamping)
.DefineMethod("StopMoving")
.Conditions(speed > 50)
.Tasks(autoPilot.Pause, shipMotor.EnableTranslationDamping);
SetRootTask("Main");
return domain;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment