This repository has been archived on 2021-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
2019-01-30 19:46:22 +00:00
|
|
|
.pragma library
|
|
|
|
|
|
|
|
function htmlEscaped(str) {
|
|
|
|
str = str.replace(/</g, "<");
|
|
|
|
str = str.replace(/>/g, ">");
|
|
|
|
return str
|
|
|
|
}
|
2019-02-04 00:27:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
function getRandomInt(min, max) {
|
|
|
|
min = Math.ceil(min);
|
|
|
|
max = Math.floor(max);
|
|
|
|
return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseToGrid(x,y) {
|
|
|
|
return {"x":Math.floor(x/40), "y":Math.floor(y/40)}
|
|
|
|
}
|
|
|
|
|
|
|
|
function distance(a,b) {
|
|
|
|
let ax = Math.floor(a/16)
|
|
|
|
let ay = a%16
|
|
|
|
|
|
|
|
let bx = Math.floor(b/16)
|
|
|
|
let by = b%16
|
|
|
|
|
|
|
|
return Math.abs(ax-bx) + Math.abs(ay-by)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function scorePath(path) {
|
|
|
|
var pathLength = 0
|
|
|
|
for (var i=0;i<path.length-1;i++) {
|
|
|
|
pathLength += distance(path[i],path[i+1])
|
|
|
|
}
|
|
|
|
return ""+pathLength
|
|
|
|
}
|
|
|
|
|
|
|
|
function isGridOccupied(x, y, points) {
|
|
|
|
var inPoints = false
|
|
|
|
for (var i=0;i<points.length;i++) {
|
|
|
|
if (((x*16)+y) == points[i]) {
|
|
|
|
inPoints = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return inPoints
|
2020-08-24 22:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isGroup(id) {
|
|
|
|
return id.length == 32
|
|
|
|
}
|
|
|
|
|
|
|
|
function isPeer(id) {
|
|
|
|
return id.length == 56
|
2019-02-04 00:27:30 +00:00
|
|
|
}
|