Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. //sweeper2.0
  2. var sweeper = window.appController.minesweeper
  3. var pId = sweeper.localPlayerId
  4. var me = sweeper.getPlayer(pId)
  5.  
  6. var BLANK = 9,
  7. BOMB = 0,
  8. FLAG = 16,
  9. BOMBHIT = 0,
  10. HIDDEN = 10,
  11. PROX1 = 1,
  12. PROX2 = 2,
  13. PROX3 = 3,
  14. PROX4 = 4,
  15. PROX5 = 5,
  16. PROX6 = 6,
  17. PROX7 = 7,
  18. PROX8 = 8,
  19. EDGE = 11
  20.  
  21. //returns the neigbors of the tile
  22. getNeighbors = function(x,y)
  23. {
  24. return sweeper.playGrid.getNeighbors(x,y)
  25. }
  26.  
  27. //returns the id of the tile
  28. getTileId = function(x,y)
  29. {
  30. return sweeper.playGrid.get(x,y)
  31. }
  32.  
  33. //returns if the tile is a flag or a hitbomb
  34. isPosDangerous = function(x,y)
  35. {
  36. var id = getTileId(x,y)
  37. return id == BOMBHIT || id > 11
  38. }
  39.  
  40. //returns if the tile is a flag or a hitbomb
  41. isDangerous = function(obj)
  42. {
  43. var id = getTileId(obj.x,obj.y)
  44. //console.log("DANGER ID:",id)
  45. //console.log(id == BOMBHIT || id > 11)
  46. return id == BOMBHIT || id > 11
  47. }
  48.  
  49. //returns true if the tile is a proxy
  50. isProxy = function(x,y)
  51. {
  52. var id = getTileId(x,y)
  53. return id > 0 && id < 9
  54. }
  55.  
  56. //returns true if the tile is an outdated proxy
  57. isOutdated = function(x,y)
  58. {
  59. if(isProxy(x,y))
  60. {
  61. var id = getTileId(x,y)
  62. //console.log("(",x,y,")is:",id)
  63. neighbors = getNeighbors(x,y)
  64. nearbyDangers = neighbors.filter(isDangerous)
  65. //console.log("neighbors_ filtered", nearbyDangers)
  66. //console.log("length: ", nearbyDangers.length)
  67. return id == nearbyDangers.length
  68. }
  69. else
  70. {
  71. //console.log("not proxy")
  72. }
  73. }
  74.  
  75. getHiddenNeighbors = function(x,y)
  76. {
  77. return getNeighbors(x,y).filter(function(obj){
  78. return HIDDEN == getTileId(obj.x,obj.y)
  79. })
  80. }
  81.  
  82. snipe = function()
  83. {
  84. var w = sweeper.playGrid.width
  85. var h = sweeper.playGrid.height
  86. for(i = 0; i < w; i++)
  87. {
  88. for(j = 0; j < h; j++)
  89. {
  90. if(isProxy(i,j))
  91. {
  92. //console.log("proxy")
  93. if(isOutdated(i,j))
  94. {
  95. gold = getHiddenNeighbors(i,j)
  96. if(gold.length > 0)
  97. {
  98. oldscore = me.points
  99. gold.forEach(function(obj)
  100. {
  101. sweeper.revealCell(obj.x,obj.y,sweeper.localPlayerId)
  102. //for debugging
  103. if(oldscore > me.points)
  104. {
  105. //console.log("lost score at: ", obj, getTileId(obj.x, obj.y))
  106. }
  107. else if(oldscore == me.points)
  108. {
  109. //console.log("no points gained:", obj, getTileId(obj.x, obj.y))
  110. }
  111. else
  112. {
  113. //console.log("", obj, getTileId(obj.x, obj.y))
  114. }
  115. //end of debugging
  116. })
  117. return true
  118. }
  119. }
  120. }
  121. }
  122. }
  123. return false
  124. }
  125.  
  126. sweep = function(seconds=1)
  127. {
  128.  
  129. window.setInterval(snipe, seconds*10);
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement