MaikelOrtega [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=10613 PicoBT: Behavior Trees in Pico8 <p>Hi everybody! </p> <p>It's been some time since I posted around here, and worked with Pico8 in general. Was a tough summer. But I come back with a second wind, partly because of the arrival of my PocketC.H.I.P.</p> <p>Last Friday I started a project while I was on a train, to test out the device and how comfortable was to actually code with it. And I decided to post here some updates about the development of said project. So, without further ado: </p> <pre><code>--------------------------------------------------------------------------------------------------------------------------------</code></pre> <p><strong>Behavior Trees</strong></p> <p>Most of you probably know about them, and have worked with them. For those which do not, I'll provide a quick explanation. Please correct me if I'm wrong, as I'm by no means an expert in this matter.</p> <p>The Behavior Tree is a model widely used in the videogame industry to create goal-oriented plans using small, self-contained, behaviors. They came out in a conference about Halo 2 AI systems, and since then they've been used in lots of different projects, even outside of the domain of videogames (robotics, etc). </p> <p>A behavior tree(BT) works by going through its nodes, from the root towards the leaves, computing these nodes according to certain rules. </p> <p>The possible outcome of a node Tick() function is either Success, Failure or Running (usually). Each node computes its Tick() function analyzing the outcome of its own children. </p> <p>e.g: The Inverter node's Tick() will return Success if its unique child returns Failure, and Failure if it returns Success.</p> <p>So, in each Tick() (usually inside an Update() function), the tree will be computed and only some behaviors will activate, creating a composed, more complex, behavior. </p> <p>If you're interested in reading more about them, here are a few nice links to articles and posts:<br /> <a href="http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php">Gamasutra Article</a><br /> <a href="http://guineashots.com/2014/08/10/an-introduction-to-behavior-trees-part-2/"> Introduction To Behavior Trees </a><br /> <a href="http://obviam.net/index.php/game-ai-an-introduction-to-behavior-trees/somewhere.com">Another introduction</a></p> <pre><code>--------------------------------------------------------------------------------------------------------------------------------</code></pre> <p><strong>PicoBT</strong></p> <p><strong>&gt;Objectives</strong></p> <p>I had a few objectives in mind when I started my implementation, tried to focus my project on them. Namely: </p> <p>1) Each BT should be able to take a form of serialized data as model, and built itself with that given data. This is because code-driven trees (when you have to call a function yourself to create each node, add them, etc) it's extremely cumbersome, and more importantly, a token eater. There are interesting code-driven models out there (like this one: <a href="https://github.com/codecapers/Fluent-Behaviour-Tree">https://github.com/codecapers/Fluent-Behaviour-Tree</a>), but a data driven approach it's way more realistic. </p> <p>2) Debug. Debug. Debug. Being able to visualize the real tree was really important for me, as I said I'm no expert and prone to make silly mistakes. </p> <p><strong>&gt;Basic structure</strong></p> <p>I started with the second one. First thing was actually build the trees (with mock methods, totally code-driven), draw them, etc... When I was confident that everything important was visible, I started to implement the basic nodes that made up most trees: Selector and Sequence. I also created two nodes, Success and Failure, for testing purposes.</p> <p>They work like this:<br /> Parent: A<br /> Children: B, C, D </p> <p><em>[NODE] SEQUENCE </em><br /> If A is a Sequence Node, it will return Success only if all childs, in order, Succeed. If any Fails, the remaining child nodes won't compute. e.g:</p> <p>Sequence( &quot;AreEnemiesAround&quot;, &quot;EnterCombatMode&quot;, &quot;TargetClosestEnemy&quot;)</p> <p>This sequence will fail if there are no enemies, or if you can't enter combat mode, or if for whatever reason you can't target the closest enemy.</p> <p><em>[NODE] SELECTOR </em><br /> If A is a Selector Node, it will check if child, in order, and return the status of the first child that doesn't fail. That means either Success or Running will be selected. Once it selects one child, the rest aren't computed in that tick.<br /> e.g:</p> <p>Imagine a Selector node, entered if a npc is hungry on a survival game:<br /> Selector(&quot;Eat&quot;, &quot;Cook&quot;, &quot;Hunt&quot;, &quot;CraftBow&quot;)</p> <p>If our npc has cooked food, she will be able to Eat.<br /> Else she will have to cook something she owns.<br /> Else, if she doesn't carry anything, she will have to hunt.<br /> Else, if she can't hunt because she lacks weapons, she will have to craft a bow. Etc...</p> <p><strong>&gt;Visual Representation</strong></p> <p>I wrote a recursive draw function that goes through each node and draw it, in a different color according to its state:<br /> green for Success, red for Failure, and yellow for Running. If the node is not reached by the calculations of that given Tick, it's color won't be updated, and usually will show Yellow as default color. </p> <p>This was one of my first tries:</p> <img loading="lazy" style="margin-bottom:16px" border=0 src="https://pbs.twimg.com/media/CsjIRCKXYAAXsQS.jpg:small" alt="" /> <p>Here both the Root node and its two children were Sequence nodes, and its children, the leaves, were either success or failure nodes.<br /> You can see how the first sequence returns Success (as its two children did too), but the second sequence fails because the first child (the third leaf) its a Failure Node.<br /> The fourth leaf is not evaluated, and hence its left as it is, with yellow color. </p> <p>-- To be continued ---</p> https://www.lexaloffle.com/bbs/?tid=27689 https://www.lexaloffle.com/bbs/?tid=27689 Mon, 19 Sep 2016 08:01:21 UTC Reaper Jr <p> <table><tr><td> <a href="/bbs/?pid=13562#p"> <img src="/bbs/thumbs/pico22282.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=13562#p"> Reaper Jr 0.4</a><br><br> by <a href="/bbs/?uid=10613"> MaikelOrtega</a> <br><br><br> <a href="/bbs/?pid=13562#p"> [Click to Play]</a> </td></tr></table> </p> <p>I'm back! It turns out my game had heavy slowdowns after this several Pico8 updates, but on the other hand I got a bunch of tokens! I optimized the game quite a bit, added a new enemy and more. Still not finished, but I hope I'll be able to play this on a PocketCHIP soon :D</p> <p>I hope you like it!</p> <p><strong>DESCRIPTION<br /> -----------------</strong><br /> You're the son of Death, he is out for holidays, and left you in charge of the whole soul reaping business. But for some reason, the undead got out of their graves and are wreaking havoc.<br /> Your objective is to find all the scattered souls in the graveyard, and to find the source of this madness.</p> <p>Everytime you die, you will lose a Soul. If you lose all of them, you die for real. Souls are also your score, so the more souls you have when you reach the ending, the better player you are :D</p> <p>Right now there's no ending, no highscore screen, nothing. But you can still get a bunch of those souls placed on the map.</p> <p>There are also two Great Souls, hidden in difficult to reach areas. Those are upgrades, that will allow ReaperJr to Double Jump or Charge his scythe and release a special attack.</p> <p><strong>CONTROLS<br /> --------------</strong><br /> Arrows to move<br /> Z: Jump. Press again to double jump after getting the Blue Flame upgrade.<br /> X: Attack. Hold for charge attack after getting the Green Flame upgrade.</p> <p><strong>UPDATES<br /> -----------------</strong></p> <p>v0.4:<br /> -Tiles redesigned.<br /> -Optimization.<br /> -New enemy: Spinning Flames With A Face On Them (Name is not final. Probably)<br /> -UI elements that show the upgrades you possess.<br /> -You lose souls after dying. If you don't have any when you die, its game over.<br /> -Spikes don't make you lose Hearts anymore. You just die. Don't fall on them.<br /> -Spikes also got a new tile. Way deadlier :D</p> <p>v0.3:<br /> -Lots of stuff. I won't go into much detail.<br /> -Remade the main song. New song on title screen.<br /> -Ah yeah, there is a title screen :D<br /> -A new zone, the Big Root, which contains the first upgrade of the game: the Green Flame.<br /> -Three new enemies (although one is a palette swap): Franky, Audrey and SuperFranky.<br /> -New mechanic: bullet reflection. Attack an enemy bullet shot by an Audrey to reflect it in the direction you're facing.<br /> -There are ways to deflect them in different directions, but I won't spoil that :D<br /> -Checkpoints. Also you can (and probably will) die now.</p> <p>v0.2:<br /> -Added Charge attack. Hold down attack until effect and sound changes. You'll have to unlock it on the final game, same as the double jump.<br /> -Buttons have to be pressed down, released and pressed again to work (no more auto-double-jump)<br /> -Added a dramatic pause effect when you hit enemies.<br /> -Added animation for the jump</p> <p><strong>Old versions<br /> -----------------</strong></p> <p> <table><tr><td> <a href="/bbs/?pid=13562#p"> <img src="/bbs/thumbs/pico14042.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=13562#p"> Reaper Jr 0.3</a><br><br> by <a href="/bbs/?uid=10613"> MaikelOrtega</a> <br><br><br> <a href="/bbs/?pid=13562#p"> [Click to Play]</a> </td></tr></table> </p> <p> <table><tr><td> <a href="/bbs/?pid=13562#p"> <img src="/bbs/thumbs/pico13624.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=13562#p"> Reaper Jr 0.2</a><br><br> by <a href="/bbs/?uid=10613"> MaikelOrtega</a> <br><br><br> <a href="/bbs/?pid=13562#p"> [Click to Play]</a> </td></tr></table> </p> <p> <table><tr><td> <a href="/bbs/?pid=13562#p"> <img src="/bbs/thumbs/pico13561.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=13562#p"> Reaper Jr 0.1</a><br><br> by <a href="/bbs/?uid=10613"> MaikelOrtega</a> <br><br><br> <a href="/bbs/?pid=13562#p"> [Click to Play]</a> </td></tr></table> </p> https://www.lexaloffle.com/bbs/?tid=2403 https://www.lexaloffle.com/bbs/?tid=2403 Wed, 02 Sep 2015 13:01:24 UTC