-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautosolverbotproplus.js
More file actions
122 lines (94 loc) · 3.13 KB
/
autosolverbotproplus.js
File metadata and controls
122 lines (94 loc) · 3.13 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
console.log("Hej");
var gameBoard= [];
numBombs = bombs.value;
// fordi html-elementet table har rækker som yderste element og celler som inderste,
// (og det er faktisk det letteste når man skal skrive det ud i console,)
// så kommer y koordinaten før x koordinaten. Det er altså omvendt!
function grabBoard() {
for (var y = 0; y < minesweeper.rows.length; y++) {
gameBoard[y] = []
for (var x = 0; x < minesweeper.rows[y].cells.length; x++) {
gameBoard[y][x] = minesweeper.rows[y].cells[x].innerText;
// her ^ ^ og her ^ ^
}
}
}
function grabGameInit() {
numBombs = bombs.value;
grabBoard();
}
function dump() {
console.log("Bomber ", numBombs)
console.log(gameBoard)
}
// var ev3 = new MouseEvent("contextmenu", {
// bubbles: true,
// cancelable: false,
// view: window,
// button: 2,
// buttons: 0,
// clientX: 3,
// clientY: 2
// });
// minesweeper.rows[1].cells[1].dispatchEvent(ev3)
var stepOn = function(x, y) {
minesweeper.rows[x].cells[y].dispatchEvent(new MouseEvent("click", { bubbles: true}))
}
var markOn = function(x, y) {
minesweeper.rows[x].cells[y].dispatchEvent(new MouseEvent("contextmenu", { bubbles: true}))
}
var initSolver = function()
{
console.log("init")
grabGameInit()
dump()
}
var solveStep = function() {
console.log('step')
grabBoard();
dump();
}
var getNeighbours = function(x,y) {
var neighbours = [];
// add neighbours counterclockwise, from top (= north N), and a round
if (x > 0)
neighbours.push(gameBoard[y][x-1]); // N
if (x > 0 && y > 0)
neighbours.push(gameBoard[y-1][x-1]); // NE
if (y > 0)
neighbours.push(gameBoard[y-1][x]); // E
if (x < gameBoard[0].length-1 && y > 0)
neighbours.push(gameBoard[y-1][x+1]); // SE
if (x < gameBoard[0].length-1)
neighbours.push(gameBoard[y][x+1]); // S
if (x < gameBoard[0].length-1 && y < gameBoard.length-1)
neighbours.push(gameBoard[y+1][x+1]); // SW
if (y < gameBoard[0].length-1)
neighbours.push(gameBoard[y+1][x]); // W
if (x > 0 && y < gameBoard.length-1)
neighbours.push(gameBoard[y+1][x-1]); // NW
return neighbours;
};
var createRiskMap = function(board) {
var riskMap = [];
};
var tileClicked = function(event) {
console.log("clicked: ", event);
// vi skal have en forsinkelse for at spillets egne kode kan nå at behandle mussekliket
var timerID = window.setTimeout(solveStep, 200);
//solveStep()
} ;
// når siden ER loaded
window.addEventListener('load', function(event){
initSolver()
document.querySelector("#new-game").addEventListener('click', function(event){
initSolver()
// inject click on gameBoard tiles
for (let tile of document.querySelectorAll('#minesweeper td')) {
tile.addEventListener("click", tileClicked)
}
}, {capture: false})
for (let tile of document.querySelectorAll('#minesweeper td')) {
tile.addEventListener("click", tileClicked, {capture: false})
}
})