-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.vold.js
executable file
·121 lines (102 loc) · 3.66 KB
/
bot.vold.js
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
function calculateDistance(first,second) {
return Math.sqrt(Math.pow(first[0] - second[0],2) + Math.pow(first[1] - second[1],2))
}
var lastDirect = "d"
function willDieAtPos(pos) {
for (var trail of gameState.trail) {
if (!trailcheat && trail[0] == pos[0] && trail[1] == pos[1]) {
return true
}
}
// edge collision
if (wallcheat) {
if (pos[0] < 0) {pos[0] = boardWidth - 1}
if (pos[1] < 0) {pos[1] = boardHeight - 1}
if (pos[0] > boardWidth) {pos[0] = 0}
if (pos[1] > boardHeight) {pos[1] = 0}
} else {
if (pos[0] < 0 ||
pos[0] >= boardWidth ||
pos[1] < 0 ||
pos[1] >= boardHeight) {
pos[0] -= gameState.direction[0]
pos[1] -= gameState.direction[1]
return true
}
}
return false
}
var maxSize = calculateDistance([0,0],[boardWidth,boardHeight])
var botIndicators = []
function putIndicator(pos,score,max) {
//return false
if (score == 9999) {
ctx.fillStyle = "#f00"
} else {
var c = 255 - Math.floor((score / max) * 255)
ctx.fillStyle = "#0000" + c.toString(16)
}
botIndicators.push([pos[0] * bWidth,pos[1] * bHeight,bWidth,bHeight,ctx.fillStyle])
}
function doOldBotLogic(x,y) {
botIndicators = []
/*if (x < gameState.position[0] && lastDirect != "d") {
lastDirect = "a"
window.onkeydown({key: "a"})
putIndicator([gameState.position[0] - 1, gameState.position[1]],1,1)
}
if (x > gameState.position[0] && lastDirect != "a") {
lastDirect = "d"
window.onkeydown({key: "d"})
putIndicator([gameState.position[0] + 1, gameState.position[1]],1,1)
}
if (y < gameState.position[1] && lastDirect != "s") {
lastDirect = "w"
window.onkeydown({key: "w"})
putIndicator([gameState.position[0], gameState.position[1] - 1],1,1)
}
if (y > gameState.position[1] && lastDirect != "w") {
window.onkeydown({key: "s"})
lastDirect = "s"
putIndicator([gameState.position[0], gameState.position[1] + 1],1,1)
}*/
var wPos = [gameState.position[0],gameState.position[1] - 1]
var wScore = calculateDistance(wPos,[x,y])
if (willDieAtPos(wPos)) { wScore = 9999}
if (lastDirect == "s") {wScore = 9999}
var aPos = [gameState.position[0] - 1,gameState.position[1]]
var aScore = calculateDistance(aPos,[x,y])
if (willDieAtPos(aPos)) { aScore = 9999}
if (lastDirect == "d") {aScore = 9999}
var sPos = [gameState.position[0],gameState.position[1] + 1]
var sScore = calculateDistance(sPos,[x,y])
if (willDieAtPos(sPos)) { sScore = 9999}
if (lastDirect == "w") {sScore = 9999}
var dPos = [gameState.position[0] + 1,gameState.position[1]]
var dScore = calculateDistance(dPos,[x,y])
if (willDieAtPos(dPos)) { dScore = 9999}
if (lastDirect == "a") {dScore = 9999}
var lowest = Math.min(wScore,aScore,sScore,dScore)
var max = 16
putIndicator(dPos,dScore,max)
putIndicator(sPos,sScore,max)
putIndicator(aPos,aScore,max)
putIndicator(wPos,wScore,max)
if (lowest == wScore) {
lastDirect = "w"
window.onkeydown({key: "w"})
} else if (lowest == aScore) {
lastDirect =("a")
window.onkeydown({key: "a"})
} else if (lowest == sScore) {
lastDirect =("s")
window.onkeydown({key: "s"})
} else if (lowest == dScore) {
lastDirect =("d")
window.onkeydown({key: "d"})
}
console.log(lastDirect, " won with score ", lowest)
if (lowest == 9999) {
console.log("%cI'M IN DANGER", "font-size: 36px;font-weight:900;")
}
}