<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[PathFinder.search giving strang results.]]></title><description><![CDATA[<p>Hey folks,</p>
<p>So I'm playing around with the new PathFinder module and it is giving me some bizarre results.</p>
<p>When trying to path between two adjecent rooms. which are directly connected, MY roomCallback is called 13 times, for different rooms.</p>
<p>I'm pathing from RoomPosition(43, 44, 'W5N1') to RoomPosition(17, 31, 'W6N1') and this is the result I get, when printing which roomName roomCallback is called with: </p>
<pre>W5N1 &lt;- Search from here<br>W4N1 &lt;- Not even directly accessible from W5N1.<br>W6N1 &lt;- To here<br>W6N2 &lt;-- To get here you pass through W6N1 (The target room)<br>W5N0<br>W6N0<br>W5N2<br>W5S0<br>W6S0<br>W6S1<br>W4N0<br>W7N1<br>W7N0</pre>
<p>Now, I do assume that the roomCallback are called in the order the rooms are visited by the A* and therefore it makes no sense to me that it should look at all those rooms. It should look at W5N1, W5N0 and W6N1, at max and stop as soon as it reaches the target room.</p>
<p>Because of this, I can't use PathFinder.search() to go from W5N1 to W5S1, as it hits 16 rooms long before it gets close to W5S1.</p>
<p>Now, I suppose my question is, am I doing something wrong, or is the PathFinder module bugged?</p>
<p>Some additional detail:</p>
<p>I'm calling the function like this:</p>
<pre>PathFinder.search(from, {pos: to, range: 1}, {<br>    plainCost: 2,<br>    swampCost: 10,<br>    roomCallback: module.exports.staticCostMatrix,<br>    maxRooms: 16,<br> });</pre>
<div class="console-message ng-scope"><span class="ng-binding">Number of ops: 1347</span></div>
<div class="console-message ng-scope console-in"><span class="ng-binding">And the path it creates: 88111111111188888811887777778877777767778887777777776663666665556565556666666777777777887888888111</span></div>
<div class="console-message ng-scope console-in"> </div>
<div class="console-message ng-scope console-in"><span class="ng-binding">Converted to directions from start to end, for compactness. The path is correct, though and is 98 steps.</span></div>
<div class="console-message ng-scope console-in"> </div>
<div class="console-message ng-scope console-in"><span class="ng-binding">Edit: Added the staticCostMatrix code:</span></div>
<pre class="console-message ng-scope console-in"><span class="ng-binding">module.exports.staticCostMatrix = function(roomName) {<br>    var room = Game.rooms[roomName];<br>     console.log(roomName);<br>     if(!room) {<br>         return;<br>     }<br> <br>     Memory.pathfinder = Memory.pathfinder || {};<br>     Memory.pathfinder[roomName] = Memory.pathfinder[roomName] || {};<br> <br>     if(Memory.pathfinder[roomName].costMatrix &amp;&amp; (Game.time - Memory.pathfinder[roomName].updated) &lt; 100) {<br>         return PathFinder.CostMatrix.deserialize(Memory.pathfinder[roomName].costMatrix);<br>     }<br> <br>     var costMatrix = new PathFinder.CostMatrix;<br> <br>     var structures = room.find(FIND_STRUCTURES);<br>     for(var i = 0; i &lt; structures.length; i++) {<br>         var structure = structures[i];<br> <br>         if(structure.structureType == STRUCTURE_ROAD) {<br>             costMatrix.set(structure.pos.x, structure.pos.y, 1);<br>         } else if(structure.structureType !== STRUCTURE_RAMPART || !structure.my) {<br>             costMatrix.set(structure.pos.x, structure.pos.y, 0xFF);<br>         }<br>     }<br> <br>     Memory.pathfinder[roomName].costMatrix = costMatrix.serialize();<br>     Memory.pathfinder[roomName].updated = Game.time;<br>     console.log("Recalculated costMatrix for " + roomName);<br>     return costMatrix;<br>};</span></pre>]]></description><link>http://screeps.com/forum/topic/1169/pathfinder-search-giving-strang-results</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 17:22:59 GMT</lastBuildDate><atom:link href="http://screeps.com/forum/topic/1169.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 25 Feb 2016 07:22:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PathFinder.search giving strang results. on Invalid Date]]></title><description><![CDATA[<p>Hey folks,</p>
<p>So I'm playing around with the new PathFinder module and it is giving me some bizarre results.</p>
<p>When trying to path between two adjecent rooms. which are directly connected, MY roomCallback is called 13 times, for different rooms.</p>
<p>I'm pathing from RoomPosition(43, 44, 'W5N1') to RoomPosition(17, 31, 'W6N1') and this is the result I get, when printing which roomName roomCallback is called with: </p>
<pre>W5N1 &lt;- Search from here<br>W4N1 &lt;- Not even directly accessible from W5N1.<br>W6N1 &lt;- To here<br>W6N2 &lt;-- To get here you pass through W6N1 (The target room)<br>W5N0<br>W6N0<br>W5N2<br>W5S0<br>W6S0<br>W6S1<br>W4N0<br>W7N1<br>W7N0</pre>
<p>Now, I do assume that the roomCallback are called in the order the rooms are visited by the A* and therefore it makes no sense to me that it should look at all those rooms. It should look at W5N1, W5N0 and W6N1, at max and stop as soon as it reaches the target room.</p>
<p>Because of this, I can't use PathFinder.search() to go from W5N1 to W5S1, as it hits 16 rooms long before it gets close to W5S1.</p>
<p>Now, I suppose my question is, am I doing something wrong, or is the PathFinder module bugged?</p>
<p>Some additional detail:</p>
<p>I'm calling the function like this:</p>
<pre>PathFinder.search(from, {pos: to, range: 1}, {<br>    plainCost: 2,<br>    swampCost: 10,<br>    roomCallback: module.exports.staticCostMatrix,<br>    maxRooms: 16,<br> });</pre>
<div class="console-message ng-scope"><span class="ng-binding">Number of ops: 1347</span></div>
<div class="console-message ng-scope console-in"><span class="ng-binding">And the path it creates: 88111111111188888811887777778877777767778887777777776663666665556565556666666777777777887888888111</span></div>
<div class="console-message ng-scope console-in"> </div>
<div class="console-message ng-scope console-in"><span class="ng-binding">Converted to directions from start to end, for compactness. The path is correct, though and is 98 steps.</span></div>
<div class="console-message ng-scope console-in"> </div>
<div class="console-message ng-scope console-in"><span class="ng-binding">Edit: Added the staticCostMatrix code:</span></div>
<pre class="console-message ng-scope console-in"><span class="ng-binding">module.exports.staticCostMatrix = function(roomName) {<br>    var room = Game.rooms[roomName];<br>     console.log(roomName);<br>     if(!room) {<br>         return;<br>     }<br> <br>     Memory.pathfinder = Memory.pathfinder || {};<br>     Memory.pathfinder[roomName] = Memory.pathfinder[roomName] || {};<br> <br>     if(Memory.pathfinder[roomName].costMatrix &amp;&amp; (Game.time - Memory.pathfinder[roomName].updated) &lt; 100) {<br>         return PathFinder.CostMatrix.deserialize(Memory.pathfinder[roomName].costMatrix);<br>     }<br> <br>     var costMatrix = new PathFinder.CostMatrix;<br> <br>     var structures = room.find(FIND_STRUCTURES);<br>     for(var i = 0; i &lt; structures.length; i++) {<br>         var structure = structures[i];<br> <br>         if(structure.structureType == STRUCTURE_ROAD) {<br>             costMatrix.set(structure.pos.x, structure.pos.y, 1);<br>         } else if(structure.structureType !== STRUCTURE_RAMPART || !structure.my) {<br>             costMatrix.set(structure.pos.x, structure.pos.y, 0xFF);<br>         }<br>     }<br> <br>     Memory.pathfinder[roomName].costMatrix = costMatrix.serialize();<br>     Memory.pathfinder[roomName].updated = Game.time;<br>     console.log("Recalculated costMatrix for " + roomName);<br>     return costMatrix;<br>};</span></pre>]]></description><link>http://screeps.com/forum/post/5412</link><guid isPermaLink="true">http://screeps.com/forum/post/5412</guid><dc:creator><![CDATA[Regenuluz]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to PathFinder.search giving strang results. on Invalid Date]]></title><description><![CDATA[<p>For completeness sake, what is your </p>
<pre class=" language-javascript"><code class=" language-javascript">module<span class="token punctuation">.</span>exports<span class="token punctuation">.</span>staticCostMatrix</code></pre>
<p>method doing?</p>]]></description><link>http://screeps.com/forum/post/5413</link><guid isPermaLink="true">http://screeps.com/forum/post/5413</guid><dc:creator><![CDATA[Dissi]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to PathFinder.search giving strang results. on Invalid Date]]></title><description><![CDATA[<p>Doh, updated the first post with the code. <img
      src="http://screeps.com/forum/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=a1k070tfs06"
      class="not-responsive emoji emoji-android emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>]]></description><link>http://screeps.com/forum/post/5414</link><guid isPermaLink="true">http://screeps.com/forum/post/5414</guid><dc:creator><![CDATA[Regenuluz]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to PathFinder.search giving strang results. on Invalid Date]]></title><description><![CDATA[<p>Yes it seems that the path finder is venturing into other rooms too frequently. This isn't costing a whole lot of CPU time, but it is counting against `maxRooms` which will make it so you can't find longer paths. I have a fix ready that will reduce the number of rooms the path finder looks at. Be on the look out for that later.</p>
<p>However, there are some changes you can make to your code right now to help out. This will also be helpful after the fix is live. First is { plainCost: 2, swampCost: 10 }. In the case that no road exists, this will increase the search area of your path exponentially as the path's length increases. I notice that your transport creeps have equal parts MOVE &amp; CARRY. In this case you can set { plainCost: 1, swampCost: 5 } and drastically reduce the path finding complexity (by not searching for roads). Additionally if you set `heuristicWeight` (a good starting point is 1.2) you can really improve search speed without much loss of accuracy.</p>]]></description><link>http://screeps.com/forum/post/5415</link><guid isPermaLink="true">http://screeps.com/forum/post/5415</guid><dc:creator><![CDATA[The_General]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to PathFinder.search giving strang results. on Invalid Date]]></title><description><![CDATA[<p>The patch has been deployed.</p>]]></description><link>http://screeps.com/forum/post/5416</link><guid isPermaLink="true">http://screeps.com/forum/post/5416</guid><dc:creator><![CDATA[artch]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to PathFinder.search giving strang results. on Invalid Date]]></title><description><![CDATA[<div class="console-message ng-scope">
<p class="timestamp ng-binding ng-scope">Awesome, this is a lot more reasonable and with heuristicWeight set to 1.9, it finds a path that's shorter than the first one. (It did that before the patch too)</p>
<pre class="timestamp ng-binding ng-scope"><br>W5N1 &lt;- Start<br>W6N1 &lt;- Target<br>W6N2 &lt;- Above target<br>W6N0 &lt;- Below target<br><br>ops: 594; len: 97;</pre>
<p class="timestamp ng-binding ng-scope">Thanks for the great work! Now I can use the PathFinder module in my second version of my code! <img
      src="http://screeps.com/forum/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=a1k070tfs06"
      class="not-responsive emoji emoji-android emoji--smile"
      title=":D"
      alt="😄"
    /></p>
</div>]]></description><link>http://screeps.com/forum/post/5417</link><guid isPermaLink="true">http://screeps.com/forum/post/5417</guid><dc:creator><![CDATA[Regenuluz]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to PathFinder.search giving strang results. on Invalid Date]]></title><description><![CDATA[<p>Path length is the wrong metric to be looking at, you should be looking at path cost. Increasing `heuristicWeight` will, by design, return non-ideal paths. If you don't care about walking on roads or walking over swamps you should adjust those costs accordingly.</p>]]></description><link>http://screeps.com/forum/post/5418</link><guid isPermaLink="true">http://screeps.com/forum/post/5418</guid><dc:creator><![CDATA[The_General]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to PathFinder.search giving strang results. on Invalid Date]]></title><description><![CDATA[<p>Well, I don't get the path cost returned(Feature request, right there.), so it's hard to look at that. However, the only difference in the path that's 98 and 97, is that at some point along the way it moves in direction 8, instead of moving 1 and then 7, all of it is on road, but since moving 1 step diagonally is both faster(tick wise) and costs the same as moving up and then left, the difference in cost would be 1.</p>]]></description><link>http://screeps.com/forum/post/5419</link><guid isPermaLink="true">http://screeps.com/forum/post/5419</guid><dc:creator><![CDATA[Regenuluz]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>