I had meant to respond to this earlier, but I had a crazy last few months. If I am reading the script correctly you are simply starting at barrel 1 and incrementing to open every single barrel one at a time. There should be a better process for this.
You should be able to figure out where every normal drink is by only opening two barrels per line. Alcohol is found in clusters of four two on this row and two on the corresponding squares directly beneath. So if we think about the Barrel Full of Barrels as a 6 by 6 grid and if we call the colums 1 through 6 and the verticles A through F, you should be able to locate where the drinks are on the first two rows by say, clicking on 1A and 4A and then b3 and b6. Where the grid is shown below. This will not get you every drink but you will know where the cluster of four is located at this point.
1 2 3 4 5 6
a
b
c
d
e
f
But it could take even less than 4 probes. If you probel 1a and find a drink (as is the case around 1/3rd of the time) then you know the other three on this level (3 levels comprising two veritcle lines each) are 2a 1b and 2b and need go no further probing. So instead of having to click 12 times to find everything on the first level, you could do it in as little as 4 or in the worst-case scenario 7 turns.
Now as for coding this, I assume you could increment by three and look for results. If booze is found, you would try to determine where that block of four is located and grab them all. The one thing you do know with a surety, it that if there is booze at say, A3 then there is definitely booze at B3, what you might not know for sure is if the block extends to A4 or A2 and below.