Created
March 28, 2013 02:25
-
-
Save ElliotWood/5260029 to your computer and use it in GitHub Desktop.
AI Game Behavior Tree's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Behavior | |
{ | |
//Branch | |
public static Action Selector(Func<bool> cond, Action ifTrue, Action ifFalse) { | |
return () => { if (cond()) { ifTrue(); } else { ifFalse(); } }; | |
} | |
public static Action Sequencer(Action a, Action b) { | |
return () => { a(); b(); } | |
} | |
//Example trees | |
public static Func<bool> ifPlayerIsInSight = () => { return true; /*...true iff WorldState shows guard can see player...*/}; | |
public static Action shootAtPlayer = () => { /*...aim guard's weapon at player and fire...*/ }; | |
public static Func<bool> ifUnderFire = () => { return true; /*...true iff WorldState shows guard hears player gunfire...*/}; | |
public static Action takeCover = () => { /*...guard runs for nearest shelter... */}; | |
public static Action walkBackAndForthGuardingDoorway = () => { /*...default guard patrol behaviour...*/ }; | |
public static Action patrollingGuardBehaviour = | |
Selector(Behavior.ifPlayerIsInSight, Behavior.shootAtPlayer, | |
Selector(Behavior.ifUnderFire, Behavior.takeCover, | |
Behavior.walkBackAndForthGuardingDoorway)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment