{"id":1201,"date":"2018-05-03T20:34:14","date_gmt":"2018-05-03T12:34:14","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=1201"},"modified":"2018-05-03T20:34:14","modified_gmt":"2018-05-03T12:34:14","slug":"%e8%a1%8c%e4%b8%ba%e6%a0%91%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5%e5%8f%8a%e8%bf%9b%e9%98%b6","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/1201","title":{"rendered":"\u884c\u4e3a\u6811\u7684\u57fa\u672c\u6982\u5ff5\u53ca\u8fdb\u9636"},"content":{"rendered":"<div class=\"iheader\">\n<div class=\"titlebar\">\n<h1 class=\"entry-title\">\u884c\u4e3a\u6811\u7684\u57fa\u672c\u6982\u5ff5\u53ca\u8fdb\u9636<\/h1>\n<div class=\"nx-breadcrumb\"><a class=\"home\" title=\"Go to behaviac.\" href=\"http:\/\/www.behaviac.com\/\">behaviac<\/a>\u00a0&gt;\u00a0<a class=\"taxonomy category\" title=\"Go to the \u6587\u6863 category archives.\" href=\"http:\/\/www.behaviac.com\/language\/zh\/category\/%e6%96%87%e6%a1%a3\/\">\u6587\u6863<\/a>\u00a0&gt;\u00a0<a class=\"taxonomy category\" title=\"Go to the \u6587\u7ae0 category archives.\" href=\"http:\/\/www.behaviac.com\/language\/zh\/category\/%e6%96%87%e6%a1%a3\/%e6%96%87%e7%ab%a0\/\">\u6587\u7ae0<\/a>\u00a0&gt;\u00a0\u884c\u4e3a\u6811\u7684\u57fa\u672c\u6982\u5ff5\u53ca\u8fdb\u9636<\/div>\n<\/div>\n<\/div>\n<div id=\"main\" class=\"site-main\">\n<div id=\"primary\" class=\"content-area\">\n<div id=\"content\" class=\"site-content\" role=\"main\">\n<article id=\"post-158\" class=\"post-158 post type-post status-publish format-standard hentry category-21 tag-31\">\n<div class=\"meta-img\"><\/div>\n<div class=\"post-mainpart\">\n<header class=\"entry-header\">\n<div class=\"entry-meta\"><span class=\"date\"><a title=\"Permalink to \u884c\u4e3a\u6811\u7684\u57fa\u672c\u6982\u5ff5\u53ca\u8fdb\u9636\" href=\"http:\/\/www.behaviac.com\/concepts\/\" rel=\"bookmark\"><time class=\"entry-date\" datetime=\"2016-04-11T17:56:50+00:00\">2016\u5e744\u670811\u65e5<\/time>\u00a0<time>\u6700\u8fd1\u66f4\u65b0\u4e8e\uff1a2017\u5e748\u67088\u65e5<\/time><\/a><\/span><span class=\"categories-links\"><a href=\"http:\/\/www.behaviac.com\/language\/zh\/category\/%e6%96%87%e6%a1%a3\/%e6%96%87%e7%ab%a0\/\" rel=\"category tag\">\u6587\u7ae0<\/a><\/span><span class=\"tags-links\"><a href=\"http:\/\/www.behaviac.com\/language\/zh\/tag\/%e6%a6%82%e5%bf%b5\/\" rel=\"tag\">\u6982\u5ff5<\/a><\/span><span class=\"author vcard\"><a class=\"url fn n\" title=\"View all posts by jonygli\" href=\"http:\/\/www.behaviac.com\/language\/zh\/author\/jonygli\/\" rel=\"author\">jonygli<\/a><\/span><\/div>\n<\/header>\n<div class=\"entry-content\">\n<div id=\"ez-toc-container\" class=\"ez-toc-wrap-left counter-hierarchy ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u5f55<\/p>\n<p><i class=\"glyphicon ez-toc-icon-toggle\"><\/i><\/div>\n<\/div>\n<h2><span id=\"i\" class=\"ez-toc-section\">\u524d\u8a00<\/span><\/h2>\n<p>\u5f00\u53d1\u6e38\u620fAI\u7684\u76ee\u6807\u4e4b\u4e00\u5c31\u662f\u8981\u627e\u5230\u4e00\u4e2a\u7b80\u5355\uff0c\u53ef\u6269\u5c55\u7684\u7f16\u8f91\u903b\u8f91\u7684\u65b9\u6848\uff0c\u4ece\u800c\u52a0\u901f\u6e38\u620f\u5f00\u53d1\u7684\u8fed\u4ee3\u901f\u5ea6\u3002\u5728\u201c\u884c\u4e3a\u7cfb\u7edf\u56fe\u201d\u4e2d\uff0c\u884c\u4e3a\u7cfb\u7edf\uff08Behavior System\uff09\u54cd\u5e94\u6e38\u620f\u4e2d\u7684\u5404\u79cd\u4fe1\u606f\uff0c\u8fdb\u884c\u51b3\u7b56\u4ee5\u6311\u9009\u63a5\u4e0b\u6765\u5c06\u8981\u6267\u884c\u7684\u884c\u52a8\u5e76\u4e14\u76d1\u63a7\u8be5\u884c\u52a8\u7684\u6267\u884c\u3002<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/architecture.png\" alt=\"\u884c\u4e3a\u7cfb\u7edf\u56fe\" \/><\/p>\n<p>\u77e5\u8bc6\u6a21\u578b\uff08Knowledge Model\uff09\u662f\u5bf9\u6e38\u620f\u4e16\u754c\u4e2d\u5404\u79cd\u4fe1\u606f\u7684\u62bd\u8c61\u3002<\/p>\n<p>\u5728\u884c\u4e3a\u7cfb\u7edf\u4e2d\uff0c\u6709\u9650\u72b6\u6001\u673a\uff08FSM\uff0cFinite State Machine\uff09\u6700\u4e3a\u7ecf\u5178\uff0cFSM\u6a21\u578b\u7684\u4f18\u52bf\u4e4b\u4e00\u662f\u7b80\u5355\u3002\u4f46\u662fFSMs\u9700\u8981\u7528\u8f6c\u6362\uff08Transition\uff09\u8fde\u63a5\u72b6\u6001\uff08State\uff09\uff0c\u56e0\u6b64\uff0c\u72b6\u6001\uff08State\uff09\u5931\u53bb\u4e86\u6a21\u5757\u6027\uff08Modularity\uff09\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/fsm.png\" alt=\"FSM\" \/><\/p>\n<h2 id=\"section\"><span id=\"i-2\" class=\"ez-toc-section\">\u4ec0\u4e48\u662f\u884c\u4e3a\u6811<\/span><\/h2>\n<p>\u884c\u4e3a\u6811\uff0c\u82f1\u6587\u662fBehavior Tree\uff0c\u7b80\u79f0BT\uff0c\u662f\u7531\u884c\u4e3a\u8282\u70b9\u7ec4\u6210\u7684\u6811\u72b6\u7ed3\u6784\uff1a<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/whatisbt.png\" alt=\"\u4ec0\u4e48\u662f\u884c\u4e3a\u6811\" \/><\/p>\n<p>\u5bf9\u4e8eFSM\uff0c\u6bcf\u4e2a\u8282\u70b9\u8868\u793a\u4e00\u4e2a\u72b6\u6001\uff0c\u800c\u5bf9\u4e8eBT\uff0c\u6bcf\u4e2a\u8282\u70b9\u8868\u793a\u4e00\u4e2a\u884c\u4e3a\u3002\u540c\u6837\u662f\u7531\u8282\u70b9\u8fde\u63a5\u800c\u6210\uff0cBT\u6709\u4ec0\u4e48\u4f18\u52bf\u5462\uff1f<\/p>\n<p>\u5728BT\u4e2d\uff0c\u8282\u70b9\u662f\u6709\u5c42\u6b21\uff08Hierarchical\uff09\u7684\uff0c\u5b50\u8282\u70b9\u7531\u5176\u7236\u8282\u70b9\u6765\u63a7\u5236\u3002\u6bcf\u4e2a\u8282\u70b9\u7684\u6267\u884c\u90fd\u6709\u4e00\u4e2a\u7ed3\u679c\uff08\u6210\u529fSuccess\uff0c\u5931\u8d25Failure\u6216\u8fd0\u884cRunning\uff09\uff0c\u8be5\u8282\u70b9\u7684\u6267\u884c\u7ed3\u679c\u90fd\u7531\u5176\u7236\u8282\u70b9\u6765\u7ba1\u7406\uff0c\u4ece\u800c\u51b3\u5b9a\u63a5\u4e0b\u6765\u505a\u4ec0\u4e48\uff0c\u7236\u8282\u70b9\u7684\u7c7b\u578b\u51b3\u5b9a\u4e86\u4e0d\u540c\u7684\u63a7\u5236\u7c7b\u578b\u3002\u8282\u70b9\u4e0d\u9700\u8981\u7ef4\u62a4\u5411\u5176\u4ed6\u8282\u70b9\u7684\u8f6c\u6362\uff0c\u8282\u70b9\u7684\u6a21\u5757\u6027\uff08Modularity\uff09\u88ab\u5927\u5927\u589e\u5f3a\u4e86\u3002\u5b9e\u9645\u4e0a\uff0c\u5728BT\u91cc\uff0c\u7531\u4e8e\u8282\u70b9\u4e0d\u518d\u6709\u8f6c\u6362\uff0c\u5b83\u4eec\u4e0d\u518d\u662f\u72b6\u6001\uff08State\uff09\uff0c\u800c\u662f\u884c\u4e3a\uff08Behavior\uff09\u3002<\/p>\n<p>\u7531\u6b64\u53ef\u89c1\uff0cBT\u7684\u4e3b\u8981\u4f18\u52bf\u4e4b\u4e00\u5c31\u662f\u5176\u66f4\u597d\u7684\u5c01\u88c5\u6027\u548c\u6a21\u5757\u6027\uff0c\u8ba9\u6e38\u620f\u903b\u8f91\u66f4\u76f4\u89c2\uff0c\u5f00\u53d1\u8005\u4e0d\u4f1a\u88ab\u90a3\u4e9b\u590d\u6742\u7684\u8fde\u7ebf\u7ed5\u6655\u3002<\/p>\n<h2 id=\"section-1\"><span id=\"i-3\" class=\"ez-toc-section\">\u4e00\u4e2a\u4f8b\u5b50<\/span><\/h2>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/example1.png\" alt=\"\u4f8b\u5b501\" \/><br \/>\n\u4e0a\u56fe\u4e2d\uff0c3\u53f7Sequence\u8282\u70b9\u67093\u4e2a\u5b50\u8282\u70b9\uff0c\u5206\u522b\u662f\uff1a<br \/>\n\u2013 4\u53f7Condition\u8282\u70b9<br \/>\n\u2013 5\u53f7Action\u8282\u70b9<br \/>\n\u2013 6\u53f7Wait\u8282\u70b9<\/p>\n<p>\u800c3\u53f7\u8282\u70b9\u7684\u7236\u8282\u70b9\u662f2\u53f7\u7684Loop\u8282\u70b9\u3002<\/p>\n<p>\u5148\u8865\u5145\u4e0b\u5404\u8282\u70b9\u7c7b\u578b\u7684\u6267\u884c\u903b\u8f91\uff08\u8be6\u89c1<a href=\"http:\/\/www.behaviac.com\/intro\/\">\u8282\u70b9\u8bf4\u660e<\/a>\uff09\uff1a<\/p>\n<ul>\n<li>\u5e8f\u5217\uff08Sequence\uff09\u8282\u70b9\uff1a\u987a\u5e8f\u6267\u884c\u6240\u6709\u5b50\u8282\u70b9\u8fd4\u56de\u6210\u529f\uff0c\u5982\u679c\u67d0\u4e2a\u5b50\u8282\u70b9\u5931\u8d25\u8fd4\u56de\u5931\u8d25\u3002<\/li>\n<li>\u5faa\u73af\uff08Loop\uff09\u8282\u70b9\uff1a\u5faa\u73af\u6267\u884c\u5b50\u8282\u70b9\u5230\u6307\u5b9a\u6b21\u6570\u540e\u8fd4\u56de\u6210\u529f\uff0c\u5982\u679c\u5faa\u73af\u6b21\u6570\u4e3a-1\uff0c\u5219\u65e0\u9650\u5faa\u73af\u3002<\/li>\n<li>\u6761\u4ef6\uff08Condition\uff09\u8282\u70b9\uff1a\u6839\u636e\u6761\u4ef6\u7684\u6bd4\u8f83\u7ed3\u679c\uff0c\u8fd4\u56de\u6210\u529f\u6216\u5931\u8d25\u3002<\/li>\n<li>\u52a8\u4f5c\uff08Action\uff09\u8282\u70b9\uff1a\u6839\u636e\u52a8\u4f5c\u7ed3\u679c\u8fd4\u56de\u6210\u529f\uff0c\u5931\u8d25\uff0c\u6216\u8fd0\u884c\u3002<\/li>\n<li>\u7b49\u5f85\uff08Wait\uff09\u8282\u70b9\uff1a\u5f53\u6307\u5b9a\u7684\u65f6\u95f4\u8fc7\u53bb\u540e\u8fd4\u56de\u6210\u529f\u3002<\/li>\n<\/ul>\n<h3 id=\"section-2\"><span id=\"i-4\" class=\"ez-toc-section\">\u6267\u884c\u8bf4\u660e<\/span><\/h3>\n<ul>\n<li>\u5982\u679c4\u53f7\u6761\u4ef6\u8282\u70b9\u7684\u6267\u884c\u7ed3\u679c\u662f\u6210\u529f\uff0c\u5176\u7236\u8282\u70b93\u53f7\u8282\u70b9\u5219\u7ee7\u7eed\u6267\u884c5\u53f7\u8282\u70b9\uff0c\u5982\u679c5\u53f7\u52a8\u4f5c\u8282\u70b9\u8fd4\u56de\u6210\u529f\uff0c\u5219\u6267\u884c6\u53f7\u7b49\u5f85\u8282\u70b9\uff0c\u5982\u679c6\u53f7\u8282\u70b9\u8fd4\u56de\u6210\u529f\uff0c\u52193\u53f7\u8282\u70b9\u5168\u90e8\u6267\u884c\u5b8c\u6bd5\u4e14\u4f1a\u8fd4\u56de\u6210\u529f\uff0c\u90a3\u4e482\u53f7\u8282\u70b9\u7ee7\u7eed\u4e0b\u4e2a\u8fed\u4ee3\u3002<\/li>\n<li>\u5982\u679c4\u53f7\u6761\u4ef6\u8282\u70b9\u7684\u6267\u884c\u7ed3\u679c\u662f\u5931\u8d25\uff0c\u5176\u7236\u8282\u70b93\u53f7\u8282\u70b9\u5219\u8fd4\u56de\u5931\u8d25\u4e0d\u518d\u7ee7\u7eed\u6267\u884c\u5b50\u8282\u70b9\uff0c\u5e76\u4e142\u53f7\u8282\u70b9\u7ee7\u7eed\u4e0b\u4e2a\u8fed\u4ee3\u3002<\/li>\n<\/ul>\n<h2 id=\"section-3\"><span id=\"i-5\" class=\"ez-toc-section\">\u8fdb\u9636<\/span><\/h2>\n<p>\u806a\u660e\u7684\u8bfb\u8005\u53ef\u80fd\u4f1a\u95ee\uff0c\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\u53ea\u8bb2\u4e86\u6210\u529f\u6216\u5931\u8d25\u7684\u60c5\u51b5\uff0c\u4f46\u5982\u679c\u52a8\u4f5c\u8981\u6301\u7eed\u4e00\u6bb5\u65f6\u95f4\u5462\uff1f\u5982\u679c5\u53f7\u8282\u70b9\uff0cFire\u9700\u8981\u6301\u7eed\u4e00\u6bb5\u65f6\u95f4\u5462\uff1f<\/p>\n<ul>\n<li>\u8282\u70b9\u7684\u6267\u884c\u7ed3\u679c\u53ef\u4ee5\u662f\u201c\u6210\u529f\u201d\uff0c\u201c\u5931\u8d25\u201d\uff0c\u6216\u201c\u8fd0\u884c\u201d\u3002<\/li>\n<li>\u5bf9\u4e8e\u6301\u7eed\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u7684Fire\u52a8\u4f5c\uff0c\u5176\u6267\u884c\u7ed3\u679c\u6301\u7eed\u8fd4\u56de\u201c\u8fd0\u884c\u201d\uff0c\u7ed3\u675f\u7684\u65f6\u5019\u8fd4\u56de\u201c\u6210\u529f\u201d\u3002<\/li>\n<li>\u5bf9\u4e8e\u6301\u7eed\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u7684Wait\u52a8\u4f5c\uff0c\u5176\u6267\u884c\u7ed3\u679c\u6301\u7eed\u8fd4\u56de\u201c\u8fd0\u884c\u201d\uff0c\u5f53\u7b49\u5f85\u65f6\u95f4\u5230\u8fbe\u7684\u65f6\u5019\u8fd4\u56de\u201c\u6210\u529f\u201d\u3002<\/li>\n<\/ul>\n<p>\u5f53\u8282\u70b9\u6301\u7eed\u8fd4\u56de\u201c\u8fd0\u884c\u201d\u7684\u65f6\u5019\uff0cBT\u6811\u7684\u5185\u90e8\u201c\u77e5\u9053\u201d\u8be5\u8282\u70b9\u662f\u5728\u6301\u7eed\u201c\u8fd0\u884c\u201d\u7684\uff0c\u4ece\u800c\u5728\u540e\u7eed\u7684\u6267\u884c\u8fc7\u7a0b\u4e2d\u201c\u76f4\u63a5\u201d\u7ee7\u7eed\u6267\u884c\u8be5\u8282\u70b9\uff0c\u800c\u4e0d\u9700\u8981\u4ece\u5934\u5f00\u59cb\u6267\u884c\uff0c\u76f4\u5230\u8be5\u8fd0\u884c\u72b6\u6001\u7684\u8282\u70b9\u8fd4\u56de\u201c\u6210\u529f\u201d\u6216\u201c\u5931\u8d25\u201d\uff0c\u4ece\u800c\u7ee7\u7eed\u540e\u7eed\u7684\u8282\u70b9\u3002\u4ece\u5916\u9762\u770b\uff0c\u5c31\u50cf\u201c\u963b\u585e\u201d\u5728\u4e86\u90a3\u4e2a\u201c\u8fd0\u884c\u201d\u7684\u8282\u70b9\u4e0a\uff0c\u5176\u7236\u8282\u70b9\u5c31\u50cf\u4e0d\u518d\u7ba1\u7406\uff0c\u8981\u4e00\u76f4\u7b49\u8fd0\u884c\u7684\u5b50\u8282\u70b9\u7ed3\u675f\u7684\u65f6\u5019\uff0c\u5176\u7236\u8282\u70b9\u624d\u518d\u6b21\u63a5\u7ba1<\/p>\n<p>\uff08\u8bf7\u6ce8\u610f\uff0c\u8fd9\u4e00\u6bb5\u8bf4\u660e\u53ea\u662f\u4ece\u6982\u5ff5\u4e0a\u8fd9\u6837\u8bb2\uff0c\u6982\u5ff5\u4e0a\u53ef\u4ee5\u8fd9\u6837\u7406\u89e3\uff0c\u5b9e\u9645\u4e0a\u5373\u4f7f\u8fd0\u884c\u72b6\u6001\u7684\u8282\u70b9\u6bcf\u6b21\u6267\u884c\u4e5f\u662f\u8981\u8fd4\u56de\u7684\uff0c\u53ea\u662f\u5176\u8fd4\u56de\u503c\u662f\u8fd0\u884c\uff0c\u5176\u7236\u8282\u70b9\u5bf9\u4e8e\u8fd4\u56de\u503c\u662f\u8fd0\u884c\u72b6\u6001\u7684\u8282\u70b9\uff0c\u5c06\u4f7f\u5176\u7ee7\u7eed\uff0c\u6240\u4ee5\u770b\u4e0a\u53bb\u597d\u50cf\u7236\u8282\u70b9\u4e0d\u518d\u7ba1\u7406\u3002\uff09\u3002<\/p>\n<h2 id=\"a-nameanotherexample-a\"><span id=\"i-6\" class=\"ez-toc-section\">\u53e6\u4e00\u4e2a\u4f8b\u5b50<\/span><\/h2>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/example2.png\" alt=\"\u4f8b\u5b502\" \/><br \/>\n\u5982\u4e0a\u56fe\uff0c\u4e3a\u4e86\u6e05\u6670\u8bf4\u660e\u8fd0\u884c\u72b6\u6001\uff0c\u6765\u770b\u53e6\u4e00\u4e2a\u4f8b\u5b50\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cCondition\uff0cAction1\uff0cAction3\u662f3\u4e2a\u51fd\u6570\u3002<\/p>\n<ul>\n<li>0\u53f7\u8282\u70b9\u662f\u4e2aLoop\u8282\u70b9\uff0c\u5faa\u73af3\u6b21\u3002<\/li>\n<li>1\u53f7\u8282\u70b9\u662f\u4e2aSequence\u8282\u70b9<\/li>\n<li>2\u53f7\u8282\u70b9\u6a21\u62df\u4e00\u4e2a\u6761\u4ef6\uff0c\u76f4\u63a5\u8fd4\u56de\u6210\u529f\u3002<\/li>\n<li>3\u53f7\u8282\u70b9Action1\u662f\u4e00\u4e2a\u52a8\u4f5c\uff0c\u76f4\u63a5\u8fd4\u56de\u6210\u529f\u3002<\/li>\n<li>4\u53f7\u8282\u70b9Action3\u540c\u6837\u662f\u4e00\u4e2a\u52a8\u4f5c\uff0c\u8fd4\u56de3\u6b21\u8fd0\u884c\uff0c\u7136\u540e\u8fd4\u56de\u6210\u529f\u3002<\/li>\n<\/ul>\n<p>\u5176\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code><span class=\"n\">bool<\/span> <span class=\"n\">CBTPlayer<\/span><span class=\"o\">::<\/span><span class=\"n\">Condition<\/span><span class=\"p\">()<\/span>\r\n<span class=\"p\">{<\/span>\r\n    <span class=\"n\">m_Frames<\/span> <span class=\"o\">=<\/span> <span class=\"mi\">0<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"n\">cout<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">\"<\/span><span class=\"se\">\\t<\/span><span class=\"s\">Condition<\/span><span class=\"se\">\\n<\/span><span class=\"s\">\"<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"k\">return<\/span> <span class=\"nb\">true<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<span class=\"n\">behaviac<\/span><span class=\"o\">::<\/span><span class=\"n\">EBTStatus<\/span> <span class=\"n\">CBTPlayer<\/span><span class=\"o\">::<\/span><span class=\"n\">Action1<\/span><span class=\"p\">()<\/span>\r\n<span class=\"p\">{<\/span>\r\n    <span class=\"n\">cout<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">\"<\/span><span class=\"se\">\\t<\/span><span class=\"s\">Action1<\/span><span class=\"se\">\\n<\/span><span class=\"s\">\"<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"k\">return<\/span> <span class=\"n\">behaviac<\/span><span class=\"o\">::<\/span><span class=\"n\">BT_SUCCESS<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<span class=\"n\">behaviac<\/span><span class=\"o\">::<\/span><span class=\"n\">EBTStatus<\/span> <span class=\"n\">CBTPlayer<\/span><span class=\"o\">::<\/span><span class=\"n\">Action3<\/span><span class=\"p\">()<\/span>\r\n<span class=\"p\">{<\/span>\r\n    <span class=\"n\">cout<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"s\">\"<\/span><span class=\"se\">\\t<\/span><span class=\"s\">Action3<\/span><span class=\"se\">\\n<\/span><span class=\"s\">\"<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"n\">m_Frames<\/span><span class=\"o\">++<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"n\">m_Frames<\/span> <span class=\"o\">==<\/span> <span class=\"mi\">3<\/span><span class=\"p\">)<\/span>\r\n    <span class=\"p\">{<\/span>\r\n        <span class=\"k\">return<\/span> <span class=\"n\">behaviac<\/span><span class=\"o\">::<\/span><span class=\"n\">BT_SUCCESS<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"p\">}<\/span>\r\n    <span class=\"k\">return<\/span> <span class=\"n\">behaviac<\/span><span class=\"o\">::<\/span><span class=\"n\">BT_RUNNING<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>\u800c\u6267\u884c\u8be5BT\u6811\u7684C++\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>    <span class=\"kt\">int<\/span> <span class=\"n\">frames<\/span> <span class=\"o\">=<\/span> <span class=\"mi\">0<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"n\">behaviac<\/span><span class=\"o\">::<\/span><span class=\"n\">EBTStatus<\/span> <span class=\"n\">status<\/span> <span class=\"o\">=<\/span> <span class=\"n\">behaviac<\/span><span class=\"o\">::<\/span><span class=\"n\">BT_RUNNING<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"k\">while<\/span> <span class=\"p\">(<\/span><span class=\"n\">status<\/span> <span class=\"o\">==<\/span> <span class=\"n\">behaviac<\/span><span class=\"o\">::<\/span><span class=\"n\">BT_RUNNING<\/span><span class=\"p\">)<\/span>\r\n    <span class=\"p\">{<\/span>\r\n        <span class=\"n\">cout<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"err\">\\<\/span><span class=\"s\">\" frame \"<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"o\">++<\/span><span class=\"n\">frames<\/span> <span class=\"o\">&lt;&lt;<\/span> <span class=\"n\">std<\/span><span class=\"o\">::<\/span><span class=\"n\">endl<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"n\">status<\/span> <span class=\"o\">=<\/span> <span class=\"n\">g_player<\/span><span class=\"o\">-&gt;<\/span><span class=\"n\">btexec<\/span><span class=\"p\">();<\/span>\r\n\r\n        <span class=\"c1\">\/\/other codes\r\n<\/span>    <span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>\u4e0a\u9762\u7684\u6267\u884c\u884c\u4e3a\u6811\u7684\u4ee3\u7801\u5c31\u5982\u540c\u6e38\u620f\u66f4\u65b0\u90e8\u5206\u3002<code class=\"highlighter-rouge\">status = g_player-&gt;btexec()<\/code>\u662f\u5728\u6e38\u620f\u7684\u66f4\u65b0\u51fd\u6570\uff08update\u6216tick\uff09\u91cc\uff0c\u9700\u8981\u6bcf\u5e27\u8c03\u7528\u3002<br \/>\n\u7279\u522b\u7684\uff0c\u5bf9\u4e8e\u8fd0\u884c\u72b6\u6001\uff0c\u5373\u4f7f\u8fd0\u884c\u72b6\u6001\u6982\u5ff5\u4e0a\u8bb2\u662f\u201c\u963b\u585e\u201d\u5728\u8282\u70b9\uff0c\u4f46\u662f\u4f9d\u7136\u662f\u6bcf\u5e27\u9700\u8981\u8c03\u7528<code class=\"highlighter-rouge\">btexec<\/code>\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5176\u8282\u70b9\u4f9d\u7136\u662f\u6bcf\u5e27\u90fd\u5728\u8fd0\u884c\uff0c\u53ea\u662f\u4e0b\u4e00\u5e27\u662f\u7ee7\u7eed\u4e0a\u4e00\u5e27\uff0c\u4ece\u800c\u8868\u73b0\u7684\u662f\u8fd0\u884c\u72b6\u6001\uff0c\u5728\u5176\u7ed3\u675f\u4e4b\u524d\uff0c\u5176\u7236\u8282\u70b9\u4e0d\u4f1a\u628a\u63a7\u5236\u8f6c\u79fb\u7ed9\u5176\u4ed6\u540e\u7eed\u8282\u70b9\u3002\u8fd9\u91cc\u7684\u201c\u963b\u585e\u201d\u5e76\u975e\u771f\u7684\u88ab\u963b\u585e\uff0c\u5e76\u975e\u540e\u7eed\u7684\u4ee3\u7801(\u4e0a\u9762\u7684<code class=\"highlighter-rouge\">other codes<\/code>\u90e8\u5206)\u4e0d\u4f1a\u88ab\u6267\u884c\u3002<code class=\"highlighter-rouge\">status = g_player-&gt;btexec()<\/code>\u540e\u9762\u5982\u679c\u6709\u4ee3\u7801\uff0c\u4f9d\u7136\u88ab\u6267\u884c\u3002<\/p>\n<p>\u6267\u884c\u7ed3\u679c\u4f1a\u662f\u4e2a\u4ec0\u4e48\u6837\u7684\u8f93\u51fa\u5462\uff1f<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/result.png\" alt=\"\u7ed3\u679c\" \/><\/p>\n<p>\u7b2c1\u5e27\uff1a<br \/>\n2\u53f7\u8282\u70b9Condition\u8fd4\u56de\u201c\u6210\u529f\u201d\uff0c\u7ee7\u7eed\u6267\u884c3\u53f7Action1\u8282\u70b9\uff0c\u540c\u6837\u8fd4\u56de\u201c\u6210\u529f\u201d\uff0c\u63a5\u7eed\u6267\u884c4\u53f7Action3\uff0c\u8fd4\u56de\u201c\u8fd0\u884c\u201d\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/frame1.png\" alt=\"frame1\" \/><\/p>\n<p>\u7b2c2\u5e27\uff1a<br \/>\n\u7531\u4e8e\u4e0a\u4e00\u5e274\u53f7Action3\u8fd4\u56de\u201c\u8fd0\u884c\u201d\uff0c\u76f4\u63a5\u7ee7\u7eed\u6267\u884c4\u53f7Action3\u8282\u70b9\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/frame2.png\" alt=\"frame2\" \/><\/p>\n<p>\u7b2c3\u5e27\uff1a<br \/>\n\u7531\u4e8e\u4e0a\u4e00\u5e274\u53f7Action3\u8fd4\u56de\u201c\u8fd0\u884c\u201d\uff0c\u76f4\u63a5\u7ee7\u7eed\u6267\u884c4\u53f7Action3\u8282\u70b9\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/frame3.png\" alt=\"frame3\" \/><\/p>\n<p>\u540c\u6837\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c2\u53f7Condition\u8282\u70b9\u4e0d\u518d\u88ab\u6267\u884c\u3002<\/p>\n<p>\u800c\u4e14\uff0c\u672c\u6b21Action3\u8fd4\u56de\u201c\u6210\u529f\u201d\uff0c1\u53f7Sequence\u8282\u70b9\u8fd4\u56de\u6210\u529f\u30020\u53f7Loop\u8282\u70b9\u7ed3\u675f\u7b2c1\u6b21\u8fed\u4ee3\u3002<br \/>\n\u7b2c4\u5e27\uff1a<br \/>\nLoop\u7684\u7b2c2\u6b21\u8fed\u4ee3\u5f00\u59cb\uff0c\u5c31\u50cf\u7b2c1\u5e27\u7684\u6267\u884c\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/frame4.png\" alt=\"frame4\" \/><\/p>\n<h2 id=\"section-4\"><span id=\"i-7\" class=\"ez-toc-section\">\u518d\u8fdb\u9636<\/span><\/h2>\n<p>\u53c8\u6709\u806a\u660e\u7684\u8bfb\u8005\u8981\u95ee\u4e86\uff0c\u6301\u7eed\u8fd4\u56de\u201c\u8fd0\u884c\u201d\u72b6\u6001\u7684\u8282\u70b9\u56fa\u7136\u4f18\u5316\u4e86\u6267\u884c\uff0c\u4f46\u5176\u7ed3\u679c\u5c31\u50cf\u201c\u963b\u585e\u201d\u4e86BT\u7684\u6267\u884c\u4e00\u6837\uff0c\u5982\u679c\u53d1\u751f\u4e86\u5176\u4ed6\u201c\u91cd\u8981\u201d\u7684\u4e8b\u60c5\u9700\u8981\u5904\u7406\u600e\u4e48\u529e\uff1f<\/p>\n<p>\u5728behaviac\u91cc\u81f3\u5c11\u6709\u591a\u79cd\u529e\u6cd5\u3002<\/p>\n<h3 id=\"httpwwwbehaviaccomdocszhreferencesattachment\"><span id=\"i-8\" class=\"ez-toc-section\">\u4f7f\u7528<a href=\"http:\/\/www.behaviac.com\/docs\/zh\/references\/attachment\/\">\u524d\u7f6e<\/a><\/span><\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/references\/preaction.png\" alt=\"\" \/><\/p>\n<p>\u6bcf\u4e2a\u8282\u70b9\u90fd\u53ef\u4ee5\u6dfb\u52a0<a href=\"http:\/\/www.behaviac.com\/docs\/zh\/references\/attachment\/\">\u524d\u7f6e<\/a>\u9644\u4ef6\u6216<a href=\"http:\/\/www.behaviac.com\/docs\/zh\/references\/attachment\/\">\u540e\u7f6e<\/a>\u9644\u4ef6\u3002<br \/>\n\u4e0a\u56fe\u7684action\u8282\u70b9\u6dfb\u52a0\u4e86\u4e00\u4e2a\u524d\u7f6e\uff0c\u4e24\u4e2a\u540e\u7f6e\u3002<\/p>\n<p>\u53ef\u4ee5\u6dfb\u52a0<a href=\"http:\/\/www.behaviac.com\/docs\/zh\/references\/attachment\/\">\u524d\u7f6e<\/a>\u9644\u4ef6\uff0c\u5e76\u4e14\u201c\u6267\u884c\u65f6\u673a\u201d\u8bbe\u4e3aUpdate\u6216Both\uff0c\u5219\u5728\u6bcf\u6b21\u6267\u884c\u4e4b\u524d\u90fd\u4f1a\u5148\u6267\u884c\u524d\u7f6e\u91cc\u914d\u7f6e\u7684\u6761\u4ef6\u3002<\/p>\n<h3 id=\"parallelhttpwwwbehaviaccomdocszhreferencesparallel\"><span id=\"Parallel\" class=\"ez-toc-section\">\u4f7f\u7528<a href=\"http:\/\/www.behaviac.com\/docs\/zh\/references\/parallel\/\">Parallel<\/a>\u8282\u70b9<\/span><\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/parallel.png\" alt=\"parallel\" \/><\/p>\n<p>\u5982\u4e0a\u56fe\uff0c\u53ef\u4ee5\u4f7f\u7528Parallel\u8282\u70b9\u6765\u201c\u4e00\u8fb9\u68c0\u67e5\u6761\u4ef6\uff0c\u4e00\u8fb9\u6267\u884c\u52a8\u4f5c\u201d\uff0c\u8be5\u6761\u4ef6\u4f5c\u4e3a\u8be5\u52a8\u4f5c\u7684\u201cGuard\u201d\u6761\u4ef6\u3002\u5f53\u8be5\u6761\u4ef6\u5931\u8d25\u7684\u65f6\u5019\u6765\u7ed3\u675f\u8be5\u5904\u4e8e\u6301\u7eed\u8fd0\u884c\u72b6\u6001\u7684\u52a8\u4f5c\u8282\u70b9\u3002<\/p>\n<h3 id=\"selectormonitorhttpwwwbehaviaccomdocszhreferencesselectormonitor\"><span id=\"SelectorMonitor\" class=\"ez-toc-section\">\u4f7f\u7528<a href=\"http:\/\/www.behaviac.com\/docs\/zh\/references\/selectormonitor\/\">SelectorMonitor<\/a>\u8282\u70b9<\/span><\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/selectormonitor.png\" alt=\"selectormonitor\" \/><\/p>\n<ul>\n<li>SelectorMonitor\u662f\u4e00\u4e2a\u52a8\u6001\u7684\u9009\u62e9\u8282\u70b9\uff0c\u548cSelector\u76f8\u540c\u7684\u662f\uff0c\u5b83\u9009\u62e9\u7b2c\u4e00\u4e2asuccess\u7684\u8282\u70b9\uff0c\u4f46\u4e0d\u540c\u7684\u662f\uff0c\u5b83\u4e0d\u662f\u53ea\u9009\u62e9\u4e00\u6b21\uff0c\u800c\u662f\u6bcf\u6b21\u6267\u884c\u7684\u65f6\u5019\u90fd\u5bf9\u5176\u5b50\u8282\u70b9\u8fdb\u884c\u9009\u62e9\u3002\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u5047\u82e5\u5b83\u9009\u62e9\u4e86\u4e0b\u9762\u6709True\u6761\u4ef6\u7684\u90a3\u4e2a\u8282\u70b9\uff08\u8282\u70b97\uff09\u5e76\u4e14\u4e0b\u9762\u76841\u53f7Sequence\u8282\u70b9\u5728\u8fd0\u884c\u72b6\u6001\uff0c\u4e0b\u4e00\u6b21\u5b83\u6267\u884c\u7684\u65f6\u5019\uff0c\u5b83\u4f9d\u7136\u4f1a\u53bb\u68c0\u67e5\u4e0a\u9762\u7684\u90a3\u4e2a8\u53f7\u6761\u4ef6\u7684\u5b50\u6811\uff0c\u5982\u679c\u8be5\u6761\u4ef6\u4e3a\u771f\uff0c\u5219\u7ec8\u6b62\u4e0b\u9762\u7684\u8fd0\u884c\u8282\u70b9\u800c\u6267\u884c9\u53f7\u8282\u70b9\u3002<\/li>\n<li>WithPrecondition\u6709precondition\u5b50\u6811\u548caction\u5b50\u6811\u3002\u53ea\u6709precondition\u5b50\u6811\u8fd4\u56desuccess\u7684\u65f6\u5019\uff0caction\u5b50\u6811\u624d\u80fd\u591f\u88ab\u6267\u884c\u3002<\/li>\n<\/ul>\n<h3 id=\"event\"><span id=\"Event\" class=\"ez-toc-section\">\u4f7f\u7528Event\u5b50\u6811<\/span><\/h3>\n<p>\u4efb\u4f55\u4e00\u4e2aBT\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u4e8b\u4ef6\u5b50\u6811\uff0c\u4f5c\u4e3aevent\u9644\u52a0\u5230\u4efb\u4f55\u7684\u4e00\u4e2a\u8282\u70b9\u4e0a(\u7528\u9f20\u6807\u62d6\u52a8BT\u5230\u8282\u70b9)\u3002\u5f53\u8fd0\u884c\u8be5BT\u7684\u65f6\u5019\uff0c\u5982\u679c\u53d1\u751f\u4e86\u67d0\u4e2a\u4e8b\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7Agent::FireEvent\u6765\u89e6\u53d1\u8be5\u4e8b\u4ef6\uff0c\u5219\u5904\u4e8erunning\u72b6\u6001\u7684\u8282\u70b9\uff0c<strong>\u4ece\u4e0b\u5230\u4e0a<\/strong>\u90fd\u6709\u673a\u4f1a\u68c0\u67e5\u662f\u5426\u9700\u8981\u54cd\u5e94\u8be5\u4e8b\u4ef6\uff0c\u5982\u679c\u6709\u8be5\u4e8b\u4ef6\u914d\u7f6e\uff0c\u5219\u76f8\u5e94\u7684\u4e8b\u4ef6\u5b50\u6811\u5c31\u4f1a\u88ab\u89e6\u53d1\u3002\u8bf7\u53c2\u8003behaviac\u7684\u76f8\u5173\u6587\u6863\u83b7\u53d6\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<h2 id=\"section-5\"><span id=\"i-9\" class=\"ez-toc-section\">\u603b\u7ed3<\/span><\/h2>\n<p>\u884c\u4e3a\u6811\u7684\u57fa\u672c\u6982\u5ff5\uff1a<\/p>\n<ul>\n<li>\u6267\u884c\u6bcf\u4e2a\u8282\u70b9\u90fd\u4f1a\u6709\u4e00\u4e2a\u7ed3\u679c\uff08\u6210\u529f\uff0c\u5931\u8d25\u6216\u8fd0\u884c\uff09<\/li>\n<li>\u5b50\u8282\u70b9\u7684\u6267\u884c\u7ed3\u679c\u7531\u5176\u7236\u8282\u70b9\u63a7\u5236\u548c\u7ba1\u7406<\/li>\n<li>\u8fd4\u56de\u8fd0\u884c\u7ed3\u679c\u7684\u8282\u70b9\u88ab\u89c6\u4f5c\u5904\u4e8e\u8fd0\u884c\u72b6\u6001\uff0c\u5904\u4e8e\u8fd0\u884c\u72b6\u6001\u7684\u8282\u70b9\u5c06\u88ab\u6301\u7eed\u6267\u884c\u4e00\u76f4\u5230\u5176\u8fd4\u56de\u7ed3\u675f\uff08\u6210\u529f\u6216\u5931\u8d25\uff09\u3002\u5728\u5176\u7ed3\u675f\u524d\uff0c\u5176\u7236\u8282\u70b9\u4e0d\u4f1a\u628a\u63a7\u5236\u8f6c\u79fb\u5230\u540e\u7eed\u8282\u70b9\u3002<\/li>\n<\/ul>\n<p>\u5176\u4e2d\u7406\u89e3\u8fd0\u884c\u72b6\u6001\u662f\u7406\u89e3\u884c\u4e3a\u6811\u7684\u5173\u952e\uff0c\u4e5f\u662f\u4f7f\u7528\u597d\u884c\u4e3a\u6811\u7684\u5173\u952e\u3002<\/p>\n<h2 id=\"section-6\"><span id=\"i-10\" class=\"ez-toc-section\">\u5176\u4ed6<\/span><\/h2>\n<p>\u4e0a\u6587<a href=\"http:\/\/www.behaviac.com\/docs\/zh\/articles\/concepts\/#anotherexample\">\u53e6\u4e00\u4e2a\u4f8b\u5b50<\/a>\u4e2d\u201cdemo_running\u201d\u7684\u4f8b\u5b50\u5728\u5b89\u88c5\u5305\u53ca\u6e90\u7801\u91cc\u90fd\u6709\u63d0\u4f9b\u3002\u6700\u597d\u67e5\u770b\u6e90\u7801\uff0c\u7f16\u8bd1\u8fd0\u884c\uff0c\u81ea\u884c\u5c1d\u8bd5\u4f53\u4f1a\u3002<br \/>\n\u53ef\u4ee5\u67e5\u770b<a href=\"http:\/\/www.behaviac.com\/docs\/zh\/articles\/directory\/\">\u76ee\u5f55\u8bf4\u660e<\/a><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/demo_running_project.png\" alt=\"demo_running_project\" \/><\/p>\n<p>\u8bf7\u6307\u5b9ademo_running\u4f5c\u4e3a\u53c2\u6570\u6216\u4e0d\u6307\u5b9a\u4efb\u4f55\u53c2\u6570\u8fd0\u884cdemo_running\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.behaviac.com\/img\/concepts\/demo_running_exec.jpg\" alt=\"demo_running_exec\" \/><\/p>\n<p><a href=\"https:\/\/github.com\/Tencent\/behaviac\">\u6e90\u7801\u53ca\u793a\u4f8b\u4e0b\u8f7d\u5730\u5740<\/a><\/p>\n<\/div>\n<\/div>\n<\/article>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u884c\u4e3a\u6811\u7684\u57fa\u672c\u6982\u5ff5\u53ca\u8fdb\u9636 behaviac<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[118],"class_list":["post-1201","post","type-post","status-publish","format-standard","hentry","tag-02-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=1201"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1201\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=1201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=1201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=1201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}