-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryBot.js
More file actions
104 lines (93 loc) · 1.82 KB
/
MemoryBot.js
File metadata and controls
104 lines (93 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Made by Daniel Apushkinsky
// March 2018
var correctLoc;
var size = 3;
var state = 1;
var stop = false;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// get current state of the game
// where 0 is preview, 1 is other
function getState()
{
state = 1;
for (var i = 0; i < size; i++)
{
for (var j = 0; j < size; j++)
{
if (correctLoc[i][j] != 0)
{
state = 0;
break;
console.log(0);
}
}
}
}
// Updates the size of the board
function updateSize(){
var counter = 2;
while(document.body.getElementsByClassName("square-row")[counter] != null){
counter++
}
size = counter;
}
// get the current board layout stored as a 2d int array
// where 1 is an active square, and 0 is inactive
function getTiles()
{
correctLoc = new Array(size);
for (var i = 0; i < size; i++)
{
correctLoc[i] = new Array(size);
for (var j = 0; j < size; j++)
{
if (document.body.getElementsByClassName("square-row")[i].getElementsByClassName("square ng-scope")[j].className.match("(active)"))
{
correctLoc[i][j] = 1;
}
else
{
correctLoc[i][j] = 0;
}
}
}
}
// Click on the tile from given coordinates
function clickTile(a, b)
{
angular.element(document.body.getElementsByClassName("square-row")[a].getElementsByClassName("square ng-scope")[b]).triggerHandler('mousedown');
}
// run this method to stop the bot
function end()
{
stop = true;
}
// main method
async function run()
{
updateSize();
getTiles();
getState();
if (state == 0)
{
await sleep(1000);
for (var i = 0; i < size; i++)
{
for (var j = 0; j < size; j++)
{
if (correctLoc[i][j] == 1)
{
clickTile(i, j);
}
}
}
}
await sleep(200);
if (!stop)
{
run();
}
}
run();