Advertisement
purplemonday

Untitled

Oct 25th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. /*
  2. * Module code goes here. Use 'module.exports' to export things:
  3. * module.exports.thing = 'a thing';
  4. *
  5. * You can import it from another modules like this:
  6. * var mod = require('main.path');
  7. * mod.thing == 'a thing'; // true
  8. */
  9.  
  10. module.exports =
  11. {
  12.  
  13. find : function (input)
  14. {
  15. var hash = ""
  16. if (_.isArray(input))
  17. {
  18.  
  19.  
  20. hash = input[0].x+" "+ input[0].y+" "+ input[0].roomName+" "+ input[1].x+" "+input[1].y+" "+input[1].roomName
  21. // need to convert it to a hash
  22.  
  23.  
  24. } else if (_.isString(input)){
  25. // it is a string
  26. hash = input
  27. console.log("HASH!!")
  28.  
  29. }
  30. var found_path = []
  31. if (this.memory[hash] == undefined)
  32. {
  33.  
  34. if (_.isString(input))
  35. {
  36. // reconstruct the paramaters from the hash
  37. var hash_arr = hash.split(" ")
  38. var pos1 = new RoomPosition(hash_arr[0], hash_arr[1], hash_arr[2]);
  39. var pos2 = new RoomPosition(hash_arr[3], hash_arr[4], hash_arr[5]);
  40. found_path = pos1.findPathTo( pos2)
  41.  
  42. } else {
  43. found_path = input[0].findPathTo( input[1])
  44. this.memory[hash] =found_path
  45. }
  46. } else {
  47. found_path = this.memory[hash]
  48.  
  49. }
  50.  
  51. console.log(">>"+hash+" path length "+this.memory[hash])
  52. return [hash,found_path]
  53. },
  54. continue_to : function (creep,dest)
  55. {
  56. var path_data = ""
  57. if (creep.memory.path_hash == undefined && dest != undefined)
  58. {
  59. path_data = this.find([creep.pos, dest.pos])
  60. creep.memory.path_hash = path_data[0]
  61. } else if (creep.memory.path_hash != undefined) {
  62. path_data = this.find(creep.memory.path_hash)
  63. }
  64. if (creep.memory.path_step == undefined)
  65. {
  66. creep.memory.path_step = 0
  67. }
  68. //console.log("dir "+ path_data[1][creep.memory.path_step].direction)
  69. if (path_data[1][creep.memory.path_step] == undefined || path_data[1][creep.memory.path_step].direction == undefined)
  70. {
  71. delete creep.memory.path_step
  72. delete creep.memory.path_hash
  73. } else if (creep.move(path_data[1][creep.memory.path_step].direction) == 0){
  74. creep.memory.path_step = creep.memory.path_step + 1
  75. }
  76.  
  77. // move(direction)
  78.  
  79. }
  80.  
  81. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement