So I have a 3 x 3 grid of squares - buttons - pictures etc.
I want to click 3 of the squares randomly
I know how to do picture search and move and click,
I just cant seem to work out how or where to start with the logic.
Also how to turn say, a random number into executing a particular action, i.e move then click.
Any hlp much appreciated as ever
random pick 3 squares in grid Topic is solved
Re: random pick 3 squares in grid
I apologize this is probably the most advanced way to handle it; but you will learn objects on the way and I also think it is the most scalable to click more locations.
If we save one set of coordinates and click on them like so:
Then we can make an array of coordinates like so and choose randomly from it:
If we save one set of coordinates and click on them like so:
Code: Select all
setOfCoords := {x: 100, y: 333}
click, % setOfCoords.x " " setOfCoords.y
Code: Select all
arrayOfCoords := [{x: 100, y: 333}
, {x: 200, y: 333}
, {x: 300, y: 999}
, {x: 400, y: 333}
, {x: 500, y: 338}
, {x: 600, y: 888}]
; choose a random number from 1 - arrayOfCoords Max
random, index, 1, % arrayOfCoords.count()
; pick the element out of the array
randomCoord := arrayOfCoords[index].clone()
click, % randomCoord.x " " randomCoord.y
Re: random pick 3 squares in grid
Hallo,
shorter without clone():
shorter without clone():
Code: Select all
; choose a random number from 1 - arrayOfCoords Max
random, index, 1, % arrayOfCoords.count()
click, % arrayOfCoords[index].x " " arrayOfCoords[index].y
Re: random pick 3 squares in grid
Once you've mastered that; use https://biga-ahk.github.io/biga.ahk/#/?id=samplesize to select three random elements from the array(no duplicates); then click each one.
Code: Select all
A := new biga() ; requires https://www.npmjs.com/package/biga.ahk
selection := A.sampleSize(arrayOfCoords, 3)
for key, value in selection {
click, % value.x " " value.y
sleep, 1000
}
Re: random pick 3 squares in grid
Thank you - this is the way I want to go - precise points to click . I will try it out and post back hereChunjee wrote: ↑07 Jun 2022, 23:22I apologize this is probably the most advanced way to handle it; but you will learn objects on the way and I also think it is the most scalable to click more locations.
If we save one set of coordinates and click on them like so:Then we can make an array of coordinates like so and choose randomly from it:Code: Select all
setOfCoords := {x: 100, y: 333} click, % setOfCoords.x " " setOfCoords.y
Code: Select all
arrayOfCoords := [{x: 100, y: 333} , {x: 200, y: 333} , {x: 300, y: 999} , {x: 400, y: 333} , {x: 500, y: 338} , {x: 600, y: 888}] ; choose a random number from 1 - arrayOfCoords Max random, index, 1, % arrayOfCoords.count() ; pick the element out of the array randomCoord := arrayOfCoords[index].clone() click, % randomCoord.x " " randomCoord.y
Re: random pick 3 squares in grid
I got that work fine thanks..
How do I pic 3 sets of coordinates without picking the same one twice ?
How do I pic 3 sets of coordinates without picking the same one twice ?
Re: random pick 3 squares in grid Topic is solved
You can also shuffle the array of coordinates and the first or last three will be both random, and non-repeating.Chunjee wrote: ↑08 Jun 2022, 01:35use https://biga-ahk.github.io/biga.ahk/#/?id=samplesize to select three random elements from the array(no duplicates); then click each one.
Vanilla ahk is a little more difficult; but here is perhaps a way with a little fn_noRepeatRand function that returns no-repeat numbers
Code: Select all
arrayOfCoords := [{x: 100, y: 333}
, {x: 200, y: 333}
, {x: 300, y: 999}
, {x: 400, y: 333}]
; choose 3 random indexes (no repeats)
indexes := fn_noRepeatRand(1, arrayOfCoords.count(), 3)
for key, value in indexes {
click, % arrayOfCoords[value].x " " arrayOfCoords[value].y
}
; functions
fn_noRepeatRand(start, stop, ammount)
{
output := []
memory := ""
while(ammount != output.count()) {
random, randomVar, % start, % stop
if (inStr(memory, randomVar)) {
continue
}
output.push(randomVar)
memory .= randomVar ","
}
return output
}
Re: random pick 3 squares in grid
@Chunjee That's is simply outstanding I so much appreciate the help people like yourself give in this forum - thank youChunjee wrote: ↑08 Jun 2022, 17:51You can also shuffle the array of coordinates and the first or last three will be both random, and non-repeating.Chunjee wrote: ↑08 Jun 2022, 01:35use https://biga-ahk.github.io/biga.ahk/#/?id=samplesize to select three random elements from the array(no duplicates); then click each one.
Vanilla ahk is a little more difficult; but here is perhaps a way with a little fn_noRepeatRand function that returns no-repeat numbersCode: Select all
arrayOfCoords := [{x: 100, y: 333} , {x: 200, y: 333} , {x: 300, y: 999} , {x: 400, y: 333}] ; choose 3 random indexes (no repeats) indexes := fn_noRepeatRand(1, arrayOfCoords.count(), 3) for key, value in indexes { click, % arrayOfCoords[value].x " " arrayOfCoords[value].y } ; functions fn_noRepeatRand(start, stop, ammount) { output := [] memory := "" while(ammount != output.count()) { random, randomVar, % start, % stop if (inStr(memory, randomVar)) { continue } output.push(randomVar) memory .= randomVar "," } return output }
- flyingDman
- Posts: 2848
- Joined: 29 Sep 2013, 19:01
Re: random pick 3 squares in grid
Or:
Code: Select all
arr := [[100,300],[200,600],[300,1000],[400,400]], nArr := []
loop, 3 ; number of clicks; max = arr.maxindex()
{
random, var, 1, arr.maxindex()
nArr.push(arr.removeat(var))
}
for a,b in nArr
Click, % b.1 " " b.2
14.3 & 1.3.7
Re: random pick 3 squares in grid
Or:
Code: Select all
Arr := [[100,300],[200,600],[300,1000],[400,400]]
Loop, 3 ; number of clicks; max = Arr.MaxIndex()
{
Random, Var, 1, Arr.MaxIndex()
Click,% (Var := Arr.RemoveAt(Var)).1 " " Var.2
}
- flyingDman
- Posts: 2848
- Joined: 29 Sep 2013, 19:01
Re: random pick 3 squares in grid
(though it might be confusing for some to call the new array "var" as well)
14.3 & 1.3.7
Who is online
Users browsing this forum: Hansielein, Lpanatt and 320 guests