behavior3行为树
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

31 linhas
1.0 KiB

  1. -module(mem_sequence).
  2. -include("eBhv3.hrl").
  3. -export([open/2, tick/2, close/2]).
  4. -spec open(bt_node(), bt_state()) -> bt_state().
  5. open(#{id := ID, children := Children} = _BTNode, BTState) ->
  6. blackboard:set(running_children, Children, ID, BTState).
  7. -spec tick(bt_node(), bt_state()) -> {bt_status(), bt_state()}.
  8. tick(#{id := ID} = _BTNode, BTState) ->
  9. RunningChildren = blackboard:get(running_children, ID, BTState),
  10. tick_1(RunningChildren, ID, BTState).
  11. -spec close(bt_node(), bt_state()) -> bt_state().
  12. close(#{id := ID} = _BTNode, BTState) ->
  13. blackboard:remove(running_children, ID, BTState).
  14. tick_1([ChildID | T] = Children, ID, BTState) ->
  15. case base_node:execute(ChildID, BTState) of
  16. {?BT_SUCCESS, BTState1} ->
  17. tick_1(T, ID, BTState1);
  18. {?BT_RUNNING, BTState1} ->
  19. BTState2 = blackboard:set(running_children, Children, ID, BTState1),
  20. {?BT_RUNNING, BTState2};
  21. {BTStatus, BTState1} ->
  22. {BTStatus, BTState1}
  23. end;
  24. tick_1([], _ID, BTState) ->
  25. {?BT_SUCCESS, BTState}.