1
\$\begingroup\$

Bands and Bonds is a browser clicker game about delving in a dungeon. It has the particularity that only one of the actions you may take can be auto-repeated at the same time: You may start several actions and have them count down in parallel, but only the last one you clicked will begin again after its end.

I thus started writing my own quick and dirty JS in the browser console:

setInterval( ()=>{ for(btn of document.getElementsByClassName("can-hold")){ btn.click() } },50) 

But quickly ran into several problems:

  • I want to avoid clicking abilties that have a cost, as that would drain my resources.
  • There are certain abilities that are straight up counter-productive, for example, one of them heals the enemy for no benefit.

Your task: Write a script, that when executed, starts autoclicking every wanted ability, but does not click unwanted ones, at least every 50 milliseconds.

Some rules:

  • All abilities have the css class .can-hold.
  • Abilities with a cost are unwanted. They all have a child that has the class .cost
  • Other unwanted abilities unfortunately do not have a nice and easy class. They all have a child that has text that contains one of ["restore", "Slows"], case sensitive. For the purposes of this challenge, assume these string are minimal.
  • What a script or program is is relaxed for this challenge. Pasting your submission in the browser console, using a bookmarklet, or even controlling the mouse through OS APIs (note that abilities may scroll off-screen!) are all allowed, as long as each ability ends up clicked at least every 50 ms.
  • It is allowed to manipulate the game's engine to consider all buttons clicked at all times, but you must demonstrate that this works according to the specs of the challenge.
  • This is mainly a challenge, but all languages are welcome if they can achieve the task.

Here's the ungolfed snippet I finished the game with, you can consider it a reference implementation:

setInterval(()=>{
for(entry of document.querySelectorAll(".can-hold:not(:has(.cost))")){
if(!["Slows", "restore"].some((phrase)=>entry.textContent.includes(phrase))){
entry.click()
}
}
},50)

This is .

\$\endgroup\$
5
  • \$\begingroup\$ sandbox \$\endgroup\$ Commented Oct 14 at 8:36
  • \$\begingroup\$ Please provide a complete list of the possible text content of each button as it may allow for golfing of the 2 words we want to avoid. \$\endgroup\$ Commented Oct 14 at 9:11
  • 2
    \$\begingroup\$ @Shaggy "assume these strings are minimal" means for the purposes of this challenge, these are to be considered the shortest string that only targets these unwanted buttons. there are upwards of 30 buttons, it's not feasible to include the text for all of them. \$\endgroup\$ Commented Oct 14 at 9:16
  • \$\begingroup\$ @Themoonisacheese I think your spoiler code sample as one } too many. \$\endgroup\$ Commented Oct 15 at 15:53
  • \$\begingroup\$ @odjo it had, in fact, one { too few. \$\endgroup\$ Commented Oct 16 at 16:27

2 Answers 2

3
\$\begingroup\$

125 123 121 111 bytes

Saved 2 bytes thanks to emanresu A.

setInterval(_=>{for(e of document.all)e.matches`.can-hold:not(:has(.cost`&!/Slows|restore/.test(e)&&e.click()}) 

Tested in Chrome only. Reportedly crashes Firefox.

117 115 105 bytes

Should work in theory, assuming an infinite stack. But would need to be run for each new battle.

(f=_=>{for(e of document.all)e.matches`.can-hold:not(:has(.cost`&!/Slows|restore/.test(e)&&e.click(f())}) 
\$\endgroup\$
6
  • \$\begingroup\$ forEach can just be map, no? also you might be able to use innerText (edit: right, querySelectorAll returns a NodeList and not an array because Javascript is like that - leaving this comment in case anyone else gets confused) \$\endgroup\$ Commented Oct 14 at 10:00
  • \$\begingroup\$ @emanresuA this is actually one of the problems i encountered when doing this for real, i didn't think it would be relevant here though \$\endgroup\$ Commented Oct 14 at 11:31
  • \$\begingroup\$ perhaps this is a firefox/chrome thing but this completely freezes the page when I paste it in my browser console. ff 143.0.4 \$\endgroup\$ Commented Oct 14 at 11:35
  • \$\begingroup\$ I've only tested in Chrome, @Themoonisacheese. \$\endgroup\$ Commented Oct 14 at 11:44
  • \$\begingroup\$ at least it doesn't crash the tab in chrome but it does require i click somewhere each time. the task is that every button gets clicked every 50ms which is not happening here. \$\endgroup\$ Commented Oct 14 at 13:20
1
\$\begingroup\$

129 bytes

setInterval(_=>{for(i of document.querySelectorAll(".can-hold:not(:has(.cost))"))/Slows|restore/.test(i.textContent)||i.click()}) 

Pure golf of the given reference implementation as a beginning

setInterval with no time input click per 4ms IIRC

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.