CN115934261B - Behavior tree operation method and device, electronic equipment and storage medium - Google Patents
Behavior tree operation method and device, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN115934261B CN115934261B CN202211551706.8A CN202211551706A CN115934261B CN 115934261 B CN115934261 B CN 115934261B CN 202211551706 A CN202211551706 A CN 202211551706A CN 115934261 B CN115934261 B CN 115934261B
- Authority
- CN
- China
- Prior art keywords
- node
- nodes
- child
- behavior tree
- serial
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 57
- 230000009471 action Effects 0.000 claims abstract description 35
- 230000008569 process Effects 0.000 claims abstract description 18
- 230000006399 behavior Effects 0.000 claims description 121
- 238000012545 processing Methods 0.000 claims description 21
- 230000004044 response Effects 0.000 claims description 17
- 238000004321 preservation Methods 0.000 claims description 7
- 238000004590 computer program Methods 0.000 claims description 5
- 239000003086 colorant Substances 0.000 claims description 3
- 230000009191 jumping Effects 0.000 claims description 2
- 230000003542 behavioural effect Effects 0.000 claims 1
- 238000010586 diagram Methods 0.000 description 12
- 238000004891 communication Methods 0.000 description 4
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 230000006870 function Effects 0.000 description 2
- 238000012360 testing method Methods 0.000 description 2
- 230000000694 effects Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
Classifications
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application provides a behavior tree operation method, a behavior tree operation device, electronic equipment and a storage medium, wherein the behavior tree operation method comprises the following steps: operating a target behavior tree; if the universal combined node is identified, aiming at each sub node, if the sub node is a parallel single node, a task thread corresponding to the sub node is called from a parallel thread pool corresponding to the universal combined node, and parallel logic is executed; for each child node, if the child node is a serial combination node, determining the serial combination to which the child node belongs, acquiring a serial thread pool corresponding to the serial combination, and executing parallel logic by the serial thread Chi Qiantao in the parallel thread pool; after the operation of all child nodes under the general combined node is completed, the parallel thread pool is jumped out, and the lower node connected with the general combined node is returned to the main thread pool to operate the general combined node so as to complete the operation of the behavior tree. The application simplifies the action tree drawing process by introducing the universal combined node which simultaneously supports serial logic and parallel logic.
Description
Technical Field
The present application relates to the field of software management technologies, and in particular, to a method and apparatus for running a behavior tree, an electronic device, and a storage medium.
Background
The existing behavior tree tool divides the combined nodes into three types of Parallel (Parallel), sequence and selection (Selector), and actions under the Parallel nodes are executed in Parallel; the actions under the sequence nodes are executed in series from left to right; the actions under the selection nodes are sequentially executed from left to right, and when a certain action is encountered for the first time and returns success, the execution of other actions is stopped.
In some application scenarios of non-AI or game, the service personnel will draw the behavior tree to express one large activity or event, but the drawing logic of the traditional behavior tree cannot support the parallel and serial relationships under the same combined node, which causes the complexity of the drawing process of the behavior tree, and the operation process needs to process a plurality of nodes to affect the operation speed.
Disclosure of Invention
In view of the above, an object of the present application is to provide at least a method, apparatus, electronic device and storage medium for running a behavior tree, which simplify a behavior tree drawing process by introducing a general combination node supporting both serial logic and parallel logic.
The application mainly comprises the following aspects:
In a first aspect, an embodiment of the present application provides a method for running a behavior tree, where the behavior tree includes a plurality of nodes, and the method includes:
acquiring a main thread pool corresponding to a target behavior tree, and running the target behavior tree according to the execution sequence corresponding to each node in the main thread pool, wherein a plurality of nodes comprise universal combined nodes; in the operation process, if the universal combined node is identified, determining the node type corresponding to each child node under the universal combined node; for each child node, if the child node is a parallel single node, a task thread corresponding to the child node is called from a parallel thread pool corresponding to the universal combined node, and parallel logic is executed; for each child node, if the child node is a serial combination node, determining a serial combination to which the child node belongs, and acquiring a serial thread pool corresponding to the serial combination, wherein the serial thread Chi Qiantao executes parallel logic in the parallel thread pool, and the serial combination comprises a plurality of child nodes and an execution sequence among the child nodes; after the operation of all child nodes under the general combined node is completed, the parallel thread pool is jumped out, and the lower node connected with the general combined node is returned to the main thread pool to operate the general combined node so as to complete the operation of the behavior tree.
In one possible implementation, the node type corresponding to each child node is determined by:
judging whether the child node has a transverse connection line or not; if the child node has a transverse connection, determining the type of the child node as a serial combined node; and if the child node does not have a transverse connection, determining the node type of the child node as a parallel single node.
In one possible implementation, the behavior tree is created by: responding to a behavior tree creation request, displaying a behavior tree creation interface, wherein the behavior tree creation interface comprises a node list and a storage identifier, and the node list comprises a plurality of nodes of different types; placing a plurality of target nodes in a drawing area in response to drag operations performed on the plurality of target nodes; determining an execution order between the target nodes in response to a wiring operation performed between the plurality of target nodes; for each target node, if the target node is a universal combined node, adding a plurality of child nodes under the universal combined node in response to editing operations performed for the universal combined node; receiving connection operation executed among all target sub-nodes, and determining all target sub-nodes as serial combination nodes; other child nodes than the plurality of target child nodes are determined to be parallel single nodes. And responding to the selection operation executed for the preservation identification, and preserving the drawn action tree to an action tree database to finish the creation of the action tree.
In one possible implementation, in response to a selection operation performed for the save identifier, saving the drawn behavior tree to the behavior tree database to complete the creation of the behavior tree includes: responding to the selection operation executed for the preservation identification, analyzing the drawn behavior tree, and placing task threads corresponding to all nodes to a main line Cheng Chizhong; when the universal combined node is identified, traversing all child nodes under the universal combined node in the order from left to right; judging whether a transverse connection exists in each sub node or not, if the transverse connection does not exist in the sub node, determining that the sub node is a parallel single node, and adding a task thread corresponding to the sub node to a parallel thread pool corresponding to a general combined node; for each child node, if the child node has a transverse connection, determining the child node as a serial combination node, determining a serial combination corresponding to the child node, starting a serial thread pool corresponding to the serial combination, and adding task threads corresponding to the child nodes in the serial combination to the serial thread pool; after the general combined node is traversed, the serial thread Chi Qiantao is fed into a parallel thread pool, and then the parallel thread Chi Qiantao is fed into a main thread pool; and continuing to traverse the next node until all nodes in the behavior tree are successfully traversed, and completing the creation of the behavior tree.
In one possible implementation, the lateral wires include a left wire and a right wire, wherein the serial combination is determined by: for each child node, if the child node has a right connection and has no left connection, taking the child node as an initial execution child node of the serial combination, continuing traversing the next child node in the left-to-right order until the child node without the right connection appears, and taking the child node without the right connection as an end execution child node of the serial combination; and forming serial combination by the initial execution sub-node, the end execution sub-node and all sub-nodes between the initial execution sub-node and the end execution sub-node.
In one possible embodiment, the method further comprises: capturing the processing state of each node in real time in the running process of the target behavior tree; and for each node, carrying out state prompt on the position of the node of the target behavior tree by utilizing different colors according to the corresponding processing state.
In a second aspect, an embodiment of the present application further provides an operation apparatus for a behavior tree, where the behavior tree includes a plurality of nodes, and the apparatus includes: the system comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for acquiring a main thread pool corresponding to a target behavior tree, operating the target behavior tree according to the corresponding execution sequence of each node in the main thread pool, and a plurality of nodes comprise universal combined nodes; the determining module is used for determining the node type corresponding to each child node under the universal combined node if the universal combined node is identified in the operation process; the first execution module is used for aiming at each sub node, if the sub node is a parallel single node, the task thread corresponding to the sub node is called from the parallel thread pool corresponding to the universal combined node, and parallel logic is executed; the second execution module is used for determining a serial combination to which each child node belongs for each child node if the child node is a serial combination node, acquiring a serial thread pool corresponding to the serial combination, and executing parallel logic by a serial thread Chi Qiantao in the parallel thread pool, wherein the serial combination comprises a plurality of child nodes and an execution sequence among the child nodes; and the operation module is used for jumping out of the parallel thread pool after completing the operation of all the child nodes under the universal combined node, and returning to the main thread pool to operate the lower node connected with the universal combined node so as to complete the operation of the behavior tree.
In one possible implementation, the identification module is further configured to: judging whether the child node has a transverse connection line or not; if the child node has a transverse connection, determining the type of the child node as a serial combined node; and if the child node does not have a transverse connection, determining the node type of the child node as a parallel single node.
In a third aspect, an embodiment of the present application further provides an electronic device, including: a processor, a memory and a bus, the memory storing machine readable instructions executable by the processor, the processor and the memory in communication via the bus when the electronic device is running, the machine readable instructions when executed by the processor performing the steps of the method of running a behavior tree as described in the first aspect or any of the possible implementation manners of the first aspect.
In a fourth aspect, the embodiment of the present application further provides a computer readable storage medium, where a computer program is stored, where the computer program is executed by a processor to perform the steps of the method for running a behavior tree according to the first aspect or any possible implementation manner of the first aspect.
The application provides a behavior tree operation method, a behavior tree operation device, electronic equipment and a storage medium, wherein the behavior tree operation method comprises the following steps: operating a target behavior tree; if the universal combined node is identified, aiming at each sub node, if the sub node is a parallel single node, a task thread corresponding to the sub node is called from a parallel thread pool corresponding to the universal combined node, and parallel logic is executed; for each child node, if the child node is a serial combination node, determining the serial combination to which the child node belongs, acquiring a serial thread pool corresponding to the serial combination, and executing parallel logic by the serial thread Chi Qiantao in the parallel thread pool; after the operation of all child nodes under the general combined node is completed, the parallel thread pool is jumped out, and the lower node connected with the general combined node is returned to the main thread pool to operate the general combined node so as to complete the operation of the behavior tree. The application simplifies the action tree drawing process by introducing the universal combined node which simultaneously supports serial logic and parallel logic; meanwhile, serial and parallel logic is displayed in a page in a crossing way, and the serial or parallel process is not only displayed, so that the running is realized quickly, and the running state is monitored.
In order to make the above objects, features and advantages of the present application more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 shows a schematic diagram of an existing tree diagram drawing provided by an embodiment of the present application;
FIG. 2 is a flow chart of a behavior tree operation method according to an embodiment of the present application;
FIG. 3 is a flowchart of a behavior tree creation method according to an embodiment of the present application;
FIG. 4 is a schematic diagram of a generic combined node according to an embodiment of the present application;
FIG. 5 shows a schematic structural diagram of an action tree operation device according to an embodiment of the present application;
fig. 6 shows a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described with reference to the accompanying drawings in the embodiments of the present application, and it should be understood that the drawings in the present application are for the purpose of illustration and description only and are not intended to limit the scope of the present application. In addition, it should be understood that the schematic drawings are not drawn to scale. A flowchart, as used in this disclosure, illustrates operations implemented according to some embodiments of the present application. It should be appreciated that the operations of the flow diagrams may be implemented out of order and that steps without logical context may be performed in reverse order or concurrently. Moreover, one or more other operations may be added to or removed from the flow diagrams by those skilled in the art under the direction of the present disclosure.
In addition, the described embodiments are only some, but not all, embodiments of the application. The components of the embodiments of the present application generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the application, as presented in the figures, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. All other embodiments, which can be made by a person skilled in the art based on embodiments of the application without making any inventive effort, fall within the scope of the application.
While the common combination nodes in the prior art include Parallel (Parallel) nodes, sequence (Sequence) nodes and selection (Selector) nodes, in the prior art, for peer nodes, when a node with a serial relationship is to be inserted into a node with a Parallel relationship, referring to fig. 1, fig. 1 shows a schematic diagram of an existing tree diagram drawing provided by an embodiment of the present application, as shown in fig. 1, a serial combination is formed between an action node 2 and an action node 3 by sequentially executing a relationship from left to right, and the serial combination is formed between the action node 2 and the action node 3, and a Parallel relationship is formed between the serial combination and an action node 1 and an action node 4, in the prior art, to achieve the serial relationship between the action node 2 and the action node 3, it is necessary to drag a serial node first, associate the action node 2 and the action node 3 under the serial node, and drag a Parallel node again, and associate the serial node 1 and the action node 4 under the Parallel node.
Therefore, under the condition that the number of the same-level action nodes is large, the drawing mode of the series-parallel connection relation in the prior art is very complicated, so that the drawn action tree is very complicated, the user is not easy to watch and understand, and meanwhile, when the action tree is operated, the logic relation operation is also possible to be wrong due to the complexity of the action tree.
Based on this, the embodiment of the application provides an operation method of a behavior tree, which supports both serial logic and parallel logic under a general combination node, and simplifies the drawing process of the behavior tree, and specifically comprises the following steps:
Referring to fig. 2, fig. 2 is a flowchart of a behavior tree operation method according to an embodiment of the present application. As shown in fig. 2, the method provided by the embodiment of the application is suitable for a behavior tree tool, and comprises the following steps:
S100, traversing a plurality of nodes in the target behavior tree, and operating the target behavior tree according to the execution logic corresponding to each node.
Specifically, the behavior tree is stored in a behavior tree database, each behavior tree includes a plurality of nodes, a behavior tree tool is provided with a behavior tree running test interface, the behavior tree running test interface includes a behavior tree list, the behavior tree list includes a plurality of behavior tree identifiers, each behavior tree identifier corresponds to a pre-created behavior tree, a main thread pool corresponding to a target behavior tree is called in response to a selection operation executed on the target behavior tree identifier, and running of the target behavior tree is started according to an execution sequence corresponding to each node in the main thread.
The plurality of nodes include general combined nodes, wherein before the behavior tree is run, the behavior tree needs to be created, specifically, referring to fig. 3, fig. 3 shows a flowchart of a behavior tree creation method according to an embodiment of the present application. As shown in fig. 3, the behavior tree is created by:
S201, responding to a behavior tree creation request, and displaying a behavior tree creation interface.
Specifically, the behavior tree creation interface comprises a node list, a storage identifier and a drawing area, wherein the node list comprises a plurality of nodes of different types, the plurality of nodes comprise parallel nodes, sequence nodes, selection nodes, universal combination nodes, random selection nodes, random weight nodes, if judgment parallel nodes, if judgment sequence nodes, modification nodes, condition nodes and the like.
S202, in response to drag operation performed on the plurality of target nodes, the plurality of target nodes are placed in a drawing area.
Specifically, for each target node, in response to a drag operation performed on the target node in the node list, a clone node of the target node is generated, and the corresponding clone node is placed in the drawing area.
S203, determining the execution sequence among the target nodes in response to the connection operation executed among the target nodes.
S204, for each target node, if the target node is a universal combined node, a plurality of child nodes are added under the universal combined node in response to editing operations executed for the universal combined node.
Specifically, the behavior tree creation interface further includes a task thread list, where the task thread list includes a plurality of task threads created in advance, and the editing operation may be to drag the target task thread under the universal combined node to form one of the child nodes of the universal combined node, where the plurality of child nodes are arranged laterally from left to right under the universal combined node.
S205, receiving connection operation executed among all target sub-nodes, and determining all the target sub-nodes as serial combination nodes.
Specifically, for a plurality of target sub-nodes with a sequential execution relationship, according to the execution sequence among the plurality of target sub-nodes, a transverse connection is sequentially drawn among the plurality of target sub-nodes needing to be sequentially executed, each target sub-node which is sequentially connected is determined to be a serial combination node, and each target sub-node which is sequentially connected forms a serial combination.
S206, determining other sub-nodes except the target sub-nodes as parallel single nodes.
Under the general combined node, the child nodes without any connection relationship belong to parallel single nodes.
S207, responding to the selection operation executed for the preservation identification, and preserving the drawn action tree to an action tree database so as to complete the creation of the action tree.
In another specific embodiment, the step of saving the drawn behavior tree to the behavior tree database in response to the selection operation performed for the save identification to complete the creation of the behavior tree comprises:
and responding to the selection operation executed for the preservation identifier, analyzing the drawn behavior tree, and placing the task thread corresponding to each node into the main thread pool.
The drawn behavior tree can be analyzed through a behavior tree analysis engine provided by a behavior tree tool, a main thread pool corresponding to the behavior tree is generated in response to a selection operation executed for a storage identifier, and the main thread pool is used for placing task threads corresponding to all nodes of the behavior tree.
When the universal combined node is identified, traversing all the sub-nodes under the universal combined node according to the left-to-right sequence, judging whether a transverse connection exists in each sub-node, if the transverse connection does not exist in the sub-node, determining that the sub-node is a parallel single node, and adding a task thread corresponding to the sub-node to a parallel thread pool corresponding to the universal combined node.
Specifically, each time the behavior tree parser recognizes a general combination node, a parallel thread pool corresponding to the general combination node is created, all task threads corresponding to all parallel single nodes under the general combination node are placed into the parallel thread pool, and all task threads in the parallel thread pool operate according to parallel logic during subsequent operation.
And for each child node, if the child node has a transverse connection, determining the child node as a serial combination node, determining a serial combination corresponding to the child node, starting a serial thread pool corresponding to the serial combination, and adding task threads corresponding to the child nodes in the serial combination to the serial thread pool.
In a preferred embodiment, the lateral links include a left link and a right link, wherein the serial combination is determined by:
And for each child node, if the child node has a right connection and has no left connection, taking the child node as an initial execution child node of the serial combination, continuing traversing the next child node in the order from left to right until the child node without the right connection appears, taking the child node without the right connection as an end execution child node of the serial combination, and forming the serial combination by the initial execution child node, the end execution child node and all child nodes between the initial execution child node and the end execution child node.
After the general combined node is traversed, the serial thread Chi Qiantao is fed into a parallel thread pool, and then the parallel thread Chi Qiantao is fed into a main thread pool; and continuing to traverse the next node until all nodes in the behavior tree are successfully traversed, and completing the creation of the behavior tree.
Referring to fig. 4, fig. 4 is a schematic diagram of a generic combined node according to an embodiment of the present application. As shown in fig. 4, the general combination node a includes a first sub-node a1, a second sub-node a2, a third sub-node a3 and a fourth sub-node a4, where the second sub-node a2 and the third sub-node a3 form a serial combination b together through a connection line L1, and the execution sequence of the second sub-node a2 and the third sub-node a3 in the serial combination is sequentially executed from left to right, and second, the first sub-node a1 and the fourth sub-node a4 are parallel single nodes, and the first sub-node a1, the serial combination b and the fourth sub-node a4 are parallel relations.
Returning to fig. 2, in the operation process, S101, if a general combined node is identified, determining a node type corresponding to each child node under the general combined node.
In a preferred embodiment, the node type corresponding to each child node is determined by:
Judging whether the child node has a transverse connection, if so, determining that the type of the child node is a serial combined node, and if not, determining that the node type of the child node is a parallel single node.
S102, for each child node, if the child node is a parallel single node, a task thread corresponding to the child node is called from a parallel thread pool corresponding to the general combination node, and parallel logic is executed.
S103, for each child node, if the child node is a serial combination node, determining the serial combination to which the child node belongs, obtaining a serial thread pool corresponding to the serial combination, and executing parallel logic by the serial thread Chi Qiantao in the parallel thread pool.
Wherein the serial combination includes a plurality of child nodes and an execution order among the child nodes.
S104, after the operation of all the child nodes under the general combined node is completed, the parallel thread pool is jumped out, and the lower node connected with the general combined node is returned to the main thread pool to operate so as to complete the operation of the behavior tree.
In another embodiment, the present application further comprises:
In the running process of the target behavior tree, the processing states of all nodes are captured in real time, and for each node, state prompt is carried out at the position of the node of the target behavior tree by utilizing different colors according to the corresponding processing states.
Specifically, after the back end starts running the target behavior tree, the websocket is used to communicate with the front end in real time, the behavior tree analysis engine of the back end sends the information and the processing state corresponding to the node currently being processed to the front end interface in the process of running the target behavior tree, the front end interface displays the target behavior tree currently being processed, and according to the processing state corresponding to the node currently being processed, different color prompts are given to the node corresponding to the front end, for example, the processing state comprises waiting, processing and processing completion, when the processing state is waiting, the node displays red indication prompt, when the processing state is processing, the node displays green flickering prompt, and when the processing state is processing, the node is green and normally bright, so that the client can be intuitively prompted by the node running state, and the subsequent maintenance is convenient.
In a possible implementation manner, based on the same application conception, the embodiment of the present application further provides a device for running a behavior tree corresponding to the running method of the behavior tree provided by the foregoing embodiment, and since the principle of solving the problem by the device in the embodiment of the present application is similar to that of the running method of the behavior tree in the foregoing embodiment of the present application, implementation of the device may refer to implementation of the method, and repeated descriptions are omitted.
Referring to fig. 5, fig. 5 shows a schematic structural diagram of a behavior tree operation device according to an embodiment of the present application, and as shown in fig. 4, the device includes:
An obtaining module 310, configured to obtain a main thread pool corresponding to the target behavior tree, run the target behavior tree according to an execution sequence corresponding to each node in the main thread pool, where the plurality of nodes include general combined nodes;
A determining module 320, configured to determine, in the operation process, a node type corresponding to each child node under the universal combined node if the universal combined node is identified;
The first execution module 330 is configured to, for each child node, if the child node is a parallel single node, invoke a task thread corresponding to the child node from a parallel thread pool corresponding to the general combination node, and execute parallel logic;
The second execution module 340 is configured to determine, for each child node, if the child node is a serial combination node, a serial combination to which the child node belongs, to obtain a serial thread pool corresponding to the serial combination, where the serial thread Chi Qiantao executes parallel logic in the parallel thread pool, and the serial combination includes a plurality of child nodes and an execution sequence between the child nodes;
and the operation module 350 is configured to, after completing operation on all the child nodes under the general combination node, jump out of the parallel thread pool, and return to the main thread pool to operate the lower node connected to the general combination node, so as to complete operation on the behavior tree.
In an alternative embodiment, the obtaining module 310 is further configured to:
judging whether the child node has a transverse connection line or not; if the child node has a transverse connection, determining the type of the child node as a serial combined node; and if the child node does not have a transverse connection, determining the node type of the child node as a parallel single node.
In an alternative embodiment, the apparatus further comprises a creation module (not shown in the figure) for:
Responding to a behavior tree creation request, displaying a behavior tree creation interface, wherein the behavior tree creation interface comprises a node list and a storage identifier, and the node list comprises a plurality of nodes of different types; placing a plurality of target nodes in a drawing area in response to drag operations performed on the plurality of target nodes; determining an execution order between the target nodes in response to a wiring operation performed between the plurality of target nodes; for each target node, if the target node is a universal combined node, adding a plurality of child nodes under the universal combined node in response to editing operations performed for the universal combined node; receiving connection operation executed among all target sub-nodes, and determining all target sub-nodes as serial combination nodes; other child nodes than the plurality of target child nodes are determined to be parallel single nodes. And responding to the selection operation executed for the preservation identification, and preserving the drawn action tree to an action tree database to finish the creation of the action tree.
Based on the same application concept, referring to fig. 6, fig. 6 shows a schematic structural diagram of an electronic device provided by an embodiment of the present application, and an electronic device 400 includes: a processor 410, a memory 420 and a bus 430, the memory 420 storing machine readable instructions executable by the processor 410, the processor 410 and the memory 420 communicating via the bus 430 when the electronic device 400 is running, the machine readable instructions being executed by the processor 410 to perform the steps of the method of running a behavior tree as described in any of the embodiments above.
Based on the same application concept, the embodiment of the present application further provides a computer readable storage medium, where a computer program is stored, where the computer program is executed by a processor to perform the steps of the behavior tree running method provided in the above embodiment.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described system and apparatus may refer to corresponding procedures in the foregoing method embodiments, which are not described herein again. In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. The above-described apparatus embodiments are merely illustrative, for example, the division of the units is merely a logical function division, and there may be other manners of division in actual implementation, and for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some communication interface, device or unit indirect coupling or communication connection, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer readable storage medium executable by a processor. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The foregoing is merely illustrative of the present application, and the present application is not limited thereto, and any person skilled in the art will readily appreciate variations or alternatives within the scope of the present application. Therefore, the protection scope of the application is subject to the protection scope of the claims.
Claims (10)
1. A method of operating a behavior tree, the behavior tree comprising a plurality of nodes, the method comprising:
Acquiring a main thread pool corresponding to a target behavior tree, and operating the target behavior tree according to the execution sequence corresponding to each node in the main thread pool, wherein the nodes comprise universal combined nodes;
In the operation process, if the universal combined node is identified, determining the node type corresponding to each child node under the universal combined node;
For each child node, if the child node is a parallel single node, a task thread corresponding to the child node is called from a parallel thread pool corresponding to the universal combined node, and parallel logic is executed;
For each child node, if the child node is a serial combination node, determining a serial combination to which the child node belongs, and acquiring a serial thread pool corresponding to the serial combination, wherein the serial thread Chi Qiantao executes parallel logic in the parallel thread pool, and the serial combination comprises a plurality of child nodes and an execution sequence among the child nodes;
after the operation of all child nodes under the general combined node is completed, the parallel thread pool is jumped out, and the lower node connected with the general combined node is returned to the main thread pool to operate the general combined node so as to complete the operation of the behavior tree.
2. The method of claim 1, wherein the node type for each child node is determined by:
judging whether the child node has a transverse connection line or not;
If the child node has a transverse connection, determining the type of the child node as a serial combined node;
and if the child node does not have a transverse connection, determining the node type of the child node as a parallel single node.
3. The method of claim 1, wherein the behavioral tree is created by:
Responding to a behavior tree creation request, displaying a behavior tree creation interface, wherein the behavior tree creation interface comprises a node list and a storage identifier, and the node list comprises a plurality of nodes of different types;
placing a plurality of target nodes in a drawing area in response to drag operations performed on the plurality of target nodes;
determining an execution order between the target nodes in response to a wiring operation performed between the plurality of target nodes;
For each target node, if the target node is a universal combined node, responding to editing operation executed for the universal combined node, and adding a plurality of child nodes under the universal combined node;
receiving connection operation executed among all target sub-nodes, and determining all target sub-nodes as serial combination nodes;
Determining other sub-nodes except the plurality of target sub-nodes as parallel single nodes;
And responding to the selection operation executed for the preservation identification, and preserving the drawn behavior tree to a behavior tree database to finish the creation of the behavior tree.
4. A method according to claim 3, wherein the step of saving the drawn action tree to an action tree database in response to a selection operation performed for the save identity to complete the creation of the action tree comprises:
Responding to the selection operation executed for the preservation identification, analyzing the drawn behavior tree, and placing task threads corresponding to all nodes to a main line Cheng Chizhong;
when the universal combined node is identified, traversing all child nodes under the universal combined node in the order from left to right;
judging whether a transverse connection exists in each sub node or not, if the transverse connection does not exist in the sub node, determining that the sub node is a parallel single node, and adding a task thread corresponding to the sub node to a parallel thread pool corresponding to the universal combined node;
For each child node, if the child node has a transverse connection, determining the child node as a serial combination node, determining a serial combination corresponding to the child node, starting a serial thread pool corresponding to the serial combination, and adding task threads corresponding to the child nodes in the serial combination into the serial thread pool;
After the general combined node is traversed, the serial thread Chi Qiantao is fed into a parallel thread pool, and then the parallel thread Chi Qiantao is fed into a main thread pool;
And continuing to traverse the next node until all nodes in the behavior tree are successfully traversed, and completing the creation of the behavior tree.
5. The method of claim 4, wherein the lateral wires comprise left and right wires,
Wherein the serial combination is determined by:
For each child node, if the child node has a right connection and has no left connection, taking the child node as an initial execution child node of the serial combination, continuing traversing the next child node in the left-to-right order until the child node without the right connection appears, and taking the child node without the right connection as an end execution child node of the serial combination;
And forming serial combination by the initial execution sub-node, the end execution sub-node and all sub-nodes between the initial execution sub-node and the end execution sub-node.
6. The method according to claim 1, wherein the method further comprises:
Capturing the processing state of each node in real time in the running process of the target behavior tree;
And for each node, carrying out state prompt on the position of the node of the target behavior tree by utilizing different colors according to the corresponding processing state.
7. An apparatus for running a behavior tree, wherein the behavior tree comprises a plurality of nodes, the apparatus comprising:
The system comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for acquiring a main thread pool corresponding to a target behavior tree, operating the target behavior tree according to the corresponding execution sequence of each node in the main thread pool, and the plurality of nodes comprise universal combined nodes;
The determining module is used for determining the node type corresponding to each child node under the universal combined node if the universal combined node is identified in the operation process;
the first execution module is used for aiming at each sub node, if the sub node is a parallel single node, the task thread corresponding to the sub node is called from the parallel thread pool corresponding to the general combined node, and parallel logic is executed;
the second execution module is configured to determine, for each child node, a serial combination to which the child node belongs if the child node is a serial combination node, and obtain a serial thread pool corresponding to the serial combination, where the serial thread Chi Qiantao executes parallel logic in the parallel thread pool, and the serial combination includes multiple child nodes and an execution sequence between the child nodes;
And the operation module is used for jumping out of the parallel thread pool after completing the operation of all the child nodes under the universal combined node, and returning to the main thread pool to operate the lower node connected with the universal combined node so as to complete the operation of the behavior tree.
8. The apparatus of claim 7, wherein the acquisition module is further configured to:
judging whether the child node has a transverse connection line or not;
If the child node has a transverse connection, determining the type of the child node as a serial combined node;
and if the child node does not have a transverse connection, determining the node type of the child node as a parallel single node.
9. An electronic device, comprising: a processor, a memory and a bus, said memory storing machine readable instructions executable by said processor, said processor and said memory communicating via said bus when the electronic device is running, said machine readable instructions when executed by said processor performing the steps of the method of running a behavior tree according to any of claims 1 to 7.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a computer program which, when executed by a processor, performs the steps of the method of operating a behavior tree according to any of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211551706.8A CN115934261B (en) | 2022-12-05 | 2022-12-05 | Behavior tree operation method and device, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211551706.8A CN115934261B (en) | 2022-12-05 | 2022-12-05 | Behavior tree operation method and device, electronic equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN115934261A CN115934261A (en) | 2023-04-07 |
CN115934261B true CN115934261B (en) | 2024-05-31 |
Family
ID=86650292
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211551706.8A Active CN115934261B (en) | 2022-12-05 | 2022-12-05 | Behavior tree operation method and device, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115934261B (en) |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111143223A (en) * | 2019-12-30 | 2020-05-12 | 珠海金山网络游戏科技有限公司 | Server pressure testing method and device |
CN111611679A (en) * | 2020-03-30 | 2020-09-01 | 西南电子技术研究所(中国电子科技集团公司第十研究所) | Modeling method of sensor scheduling behavior tree model |
CN115292816A (en) * | 2022-07-29 | 2022-11-04 | 中国科学院软件研究所 | Automatic driving test method, device, equipment and storage medium |
CN115291856A (en) * | 2022-07-19 | 2022-11-04 | 中电金信软件有限公司 | Flow establishing method and device and electronic equipment |
CN115408595A (en) * | 2022-11-03 | 2022-11-29 | 博和利统计大数据(天津)集团有限公司 | Data capture engine development method, data capture engine execution method, data capture engine equipment and storage medium |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1713192A (en) * | 2004-06-25 | 2005-12-28 | 国际商业机器公司 | Method and device for processing logic mode establishment and carrying out |
-
2022
- 2022-12-05 CN CN202211551706.8A patent/CN115934261B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111143223A (en) * | 2019-12-30 | 2020-05-12 | 珠海金山网络游戏科技有限公司 | Server pressure testing method and device |
CN111611679A (en) * | 2020-03-30 | 2020-09-01 | 西南电子技术研究所(中国电子科技集团公司第十研究所) | Modeling method of sensor scheduling behavior tree model |
CN115291856A (en) * | 2022-07-19 | 2022-11-04 | 中电金信软件有限公司 | Flow establishing method and device and electronic equipment |
CN115292816A (en) * | 2022-07-29 | 2022-11-04 | 中国科学院软件研究所 | Automatic driving test method, device, equipment and storage medium |
CN115408595A (en) * | 2022-11-03 | 2022-11-29 | 博和利统计大数据(天津)集团有限公司 | Data capture engine development method, data capture engine execution method, data capture engine equipment and storage medium |
Non-Patent Citations (2)
Title |
---|
Generating Compact Tree Ensembles via Annealing;Gitesh Dawer;《2020International Joint Conference on Neural Networks》;20200928;全文 * |
基于行为树的游戏智能研究;刘晓伟;《中国优秀硕士学位论文全文数据库 信息科技辑》;20190415;第2019年卷(第第4期期);全文 * |
Also Published As
Publication number | Publication date |
---|---|
CN115934261A (en) | 2023-04-07 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112463581B (en) | Method and system for carrying out fuzzy test on distributed system | |
CN110134659B (en) | Log monitoring system, method, medium, and apparatus for running program | |
CN104461693B (en) | Virtual machine update method and system under a kind of desktop cloud computing environment | |
CN109345200A (en) | Automatic auditing method and device, computer readable storage medium based on high-volume report | |
CN112131126A (en) | Test environment switching method and device | |
CN111641601A (en) | Firewall management method, device, equipment and storage medium | |
CN114338188A (en) | Malicious software intelligent cloud detection system based on process behavior sequence fragmentation | |
CN115934261B (en) | Behavior tree operation method and device, electronic equipment and storage medium | |
CN107193634A (en) | The access method and device of a kind of virtual machine | |
CN112434831A (en) | Troubleshooting method and device, storage medium and computer equipment | |
US20230213911A1 (en) | Method and device for testing product, computer device and readable storage medium | |
CN114880157B (en) | Fault injection method and device | |
CN113001538B (en) | Command analysis method and system | |
CN112134764B (en) | Method and device for determining connectivity of test environment | |
CN109947429B (en) | Data processing method and device | |
CN114020580A (en) | Method, system, device and storage medium for monitoring performance index of application system | |
CN111581019B (en) | Test method and device for storage fault recovery | |
CN110119301A (en) | A kind of virtual machine migration method and system | |
CN110795334B (en) | Testing device and method | |
CN113821450A (en) | Integrated method and system for executing computer software test | |
CN112363933A (en) | Automatic verification method and device for word paragraph table, computer equipment and storage medium | |
CN111767299A (en) | Database operation method, device and system, storage medium and electronic equipment | |
CN112434193B (en) | Method and device for rapidly troubleshooting guided system | |
CN112487017B (en) | SQL (structured query language) release method and system based on flow engine | |
CN118101999B (en) | Short video flow data analysis method |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |