Navigation

    forum

    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    1. Home
    2. Regenuluz
    • Flag Profile
    • block_user
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Groups
    • Blog

    Regenuluz

    @Regenuluz

    4
    Posts
    863
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Regenuluz Follow

    Posts made by Regenuluz

    • RE: PathFinder.search giving strang results.

      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.

      posted in Technical Issues and Bugs
      Regenuluz
    • RE: PathFinder.search giving strang results.

      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)


      W5N1 <- Start
      W6N1 <- Target
      W6N2 <- Above target
      W6N0 <- Below target

      ops: 594; len: 97;

      Thanks for the great work! Now I can use the PathFinder module in my second version of my code! 😄

      posted in Technical Issues and Bugs
      Regenuluz
    • RE: PathFinder.search giving strang results.

      Doh, updated the first post with the code. 🙂

      posted in Technical Issues and Bugs
      Regenuluz
    • PathFinder.search giving strang results.

      Hey folks,

      So I'm playing around with the new PathFinder module and it is giving me some bizarre results.

      When trying to path between two adjecent rooms. which are directly connected, MY roomCallback is called 13 times, for different rooms.

      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: 

      W5N1 <- Search from here
      W4N1 <- Not even directly accessible from W5N1.
      W6N1 <- To here
      W6N2 <-- To get here you pass through W6N1 (The target room)
      W5N0
      W6N0
      W5N2
      W5S0
      W6S0
      W6S1
      W4N0
      W7N1
      W7N0

      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.

      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.

      Now, I suppose my question is, am I doing something wrong, or is the PathFinder module bugged?

      Some additional detail:

      I'm calling the function like this:

      PathFinder.search(from, {pos: to, range: 1}, {
          plainCost: 2,
          swampCost: 10,
          roomCallback: module.exports.staticCostMatrix,
          maxRooms: 16,
      });
      Number of ops: 1347
      And the path it creates: 88111111111188888811887777778877777767778887777777776663666665556565556666666777777777887888888111
       
      Converted to directions from start to end, for compactness. The path is correct, though and is 98 steps.
       
      Edit: Added the staticCostMatrix code:
      module.exports.staticCostMatrix = function(roomName) {
          var room = Game.rooms[roomName];
          console.log(roomName);
          if(!room) {
              return;
          }

          Memory.pathfinder = Memory.pathfinder || {};
          Memory.pathfinder[roomName] = Memory.pathfinder[roomName] || {};

          if(Memory.pathfinder[roomName].costMatrix && (Game.time - Memory.pathfinder[roomName].updated) < 100) {
              return PathFinder.CostMatrix.deserialize(Memory.pathfinder[roomName].costMatrix);
          }

          var costMatrix = new PathFinder.CostMatrix;

          var structures = room.find(FIND_STRUCTURES);
          for(var i = 0; i < structures.length; i++) {
              var structure = structures[i];

              if(structure.structureType == STRUCTURE_ROAD) {
                  costMatrix.set(structure.pos.x, structure.pos.y, 1);
              } else if(structure.structureType !== STRUCTURE_RAMPART || !structure.my) {
                  costMatrix.set(structure.pos.x, structure.pos.y, 0xFF);
              }
          }

          Memory.pathfinder[roomName].costMatrix = costMatrix.serialize();
          Memory.pathfinder[roomName].updated = Game.time;
          console.log("Recalculated costMatrix for " + roomName);
          return costMatrix;
      };
      posted in Technical Issues and Bugs
      Regenuluz