let drawpathline;
function showPath(pathArray) {
if (pathArray === null) return null;
if(drawpathline !== undefined && drawpathline !== null)
ABWorld.scene.remove(drawpathline);
let line = new THREE.LineDashedMaterial({
color: "green",
linewidth: 1,
scale: 1,
dashSize: 50,
gapSize: 50,
linecap: 'round',
linejoin: 'round'
});
let i, j, points = [];
for (let l = 0; l < pathArray.length; l++) {
i = pathArray[l].i,
j = pathArray[l].j,
points.push(translate(i, j));
}
let geom = (new THREE.BufferGeometry()).setFromPoints(points),
pathLine = new THREE.Line(geom, line);
ABWorld.scene.add(pathLine);
return pathLine;
}
let drawPathToTrap;
function showPathToTrap(pathArray) {
if (pathArray === null) return null;
if(drawPathToTrap !== undefined && drawPathToTrap !== null)
ABWorld.scene.remove(drawPathToTrap);
let line = new THREE.LineDashedMaterial({
color: "red",
linewidth: 1,
scale: 1,
dashSize: 50,
gapSize: 50,
linecap: 'round',
linejoin: 'round'
});
let i, j, points = [];
for (let l = 0; l < pathArray.length; l++) {
i = pathArray[l].i,
j = pathArray[l].j,
points.push(translate(i, j));
}
let geom = (new THREE.BufferGeometry()).setFromPoints(points),
pathLine = new THREE.Line(geom, line);
ABWorld.scene.add(pathLine);
return pathLine;
}
let drawPathToAttackCell;
function showPathToAttackCell(pathArray) {
if (pathArray === null) return null;
if(drawPathToAttackCell !== undefined && drawPathToAttackCell !== null)
ABWorld.scene.remove(drawPathToAttackCell);
let line = new THREE.LineDashedMaterial({
color: "blue",
linewidth: 1
});
let i, j, points = [];
for (let l = 0; l < pathArray.length; l++) {
i = pathArray[l].i,
j = pathArray[l].j,
points.push(translate(i, j));
}
let geom = (new THREE.BufferGeometry()).setFromPoints(points),
pathLine = new THREE.Line(geom, line);
ABWorld.scene.add(pathLine);
return pathLine;
}
let linecol = '#00ffee';
let drawTLDiagonal;
function showTLDiagonal() {
if(drawTLDiagonal !== undefined && drawTLDiagonal !== null)
ABWorld.scene.remove(drawTLDiagonal);
let line = new THREE.LineDashedMaterial({
color: linecol,
linewidth: 1,
});
points = [];
points.push(translate(ai, aj));
let coords = getTopLeftDiag();
points.push(translate(coords.i, coords.j));
let geom = (new THREE.BufferGeometry()).setFromPoints(points);
let pathLine = new THREE.Line(geom, line);
ABWorld.scene.add(pathLine);
return pathLine;
}
let drawTRDiagonal;
function showTRDiagonal() {
if(drawTRDiagonal !== undefined && drawTRDiagonal !== null)
ABWorld.scene.remove(drawTRDiagonal);
let line = new THREE.LineDashedMaterial({
color: linecol,
linewidth: 1,
});
points = [];
points.push(translate(ai, aj));
let coords = getTopRightDiag();
points.push(translate(coords.i, coords.j));
let geom = (new THREE.BufferGeometry()).setFromPoints(points);
let pathLine = new THREE.Line(geom, line);
ABWorld.scene.add(pathLine);
return pathLine;
}
let drawBLDiagonal;
function showBLDiagonal() {
if(drawBLDiagonal !== undefined && drawBLDiagonal !== null)
ABWorld.scene.remove(drawBLDiagonal);
let line = new THREE.LineDashedMaterial({
color: linecol,
linewidth: 1,
});
points = [];
points.push(translate(ai, aj));
let coords = getBottomLeftDiag();
points.push(translate(coords.i, coords.j));
let geom = (new THREE.BufferGeometry()).setFromPoints(points);
let pathLine = new THREE.Line(geom, line);
ABWorld.scene.add(pathLine);
return pathLine;
}
let drawBRDiagonal;
function showBRDiagonal() {
if(drawBRDiagonal !== undefined && drawBRDiagonal !== null)
ABWorld.scene.remove(drawBRDiagonal);
let line = new THREE.LineDashedMaterial({
color: linecol,
linewidth: 1,
});
points = [];
points.push(translate(ai, aj));
let coords = getBottomRightDiag();
points.push(translate(coords.i, coords.j));
let geom = (new THREE.BufferGeometry()).setFromPoints(points);
let pathLine = new THREE.Line(geom, line);
ABWorld.scene.add(pathLine);
return pathLine;
}
function getTopLeftDiag() {
let i = ai, j = aj;
while(i !== 0 && j !== 0) {
i--, j--;
}
return {i: i, j: j};
}
function getBottomLeftDiag() {
let i = ai, j = aj;
while(i !== 0 && j !== gridsize-1) {
i--, j++;
}
return {i: i, j: j};
}
function getBottomRightDiag() {
let i = ai, j = aj;
while(i !== gridsize-1 && j !== gridsize-1) {
i++, j++;
}
return {i: i, j: j};
}
function getTopRightDiag() {
let i = ai, j = aj;
while(i !== gridsize-1 && j !== 0) {
i++, j--;
}
return {i: i, j: j};
}
function getMockGrid() {
let gr = [];
for(let i = 0; i < GRID.length; i++) {
let row = [];
for(let j = 0; j < GRID[i].length; j++) {
row.push(GRID[i][j]);
}
gr.push(row);
}
return gr;
}
function getBottomArea() {
let mock = getMockGrid();
for(let i = 0; i < gridsize; i++) {
for(let j = 0; j < gridsize; j++) {
let ya0 = (ai - aj);
let ya = (j + ya0);
let yb0 = (ai + aj);
let yb = (-j + yb0);
if(i >= ya && i >= yb) {
if(GRID[i][j] == GRID_BLANK) mock[i][j] = GRID_ATTACK_AREA;
}
}
}
return mock;
}
function getTopArea() {
let mock = getMockGrid();
for(let i = 0; i < gridsize; i++) {
for(let j = 0; j < gridsize; j++) {
let ya0 = (ai - aj);
let ya = (j + ya0);
let yb0 = (ai + aj);
let yb = (-j + yb0);
if(i <= ya && i <= yb) {
if(GRID[i][j] == GRID_BLANK) mock[i][j] = GRID_ATTACK_AREA;
}
}
}
return mock;
}
function getLeftArea() {
let mock = getMockGrid();
for(let i = 0; i < gridsize; i++) {
for(let j = 0; j < gridsize; j++) {
let ya0 = (ai - aj);
let ya = (j + ya0);
let yb0 = (ai + aj);
let yb = (-j + yb0);
if(i >= ya && i <= yb) {
if(GRID[i][j] == GRID_BLANK) mock[i][j] = GRID_ATTACK_AREA;
}
}
}
return mock;
}
function getRightArea() {
let mock = getMockGrid();
for(let i = 0; i < gridsize; i++) {
for(let j = 0; j < gridsize; j++) {
let ya0 = (ai - aj);
let ya = (j + ya0);
let yb0 = (ai + aj);
let yb = (-j + yb0);
if(i <= ya && i >= yb) {
if(GRID[i][j] == GRID_BLANK) mock[i][j] = GRID_ATTACK_AREA;
}
}
}
return mock;
}
function printGrid(GRID) {
let s = '';
for(let i in GRID) {
for(let j in GRID[i]) {
if(i == ai && j == aj) {
s += 'A ';
}
else s += GRID[i][j] + ' ';
}
s += '\n';
}
console.log(s);
}
function cleanGrid() {
for (let i = 0; i < gridsize; i++) {
for(let j = 0; j < gridsize; j++) {
if(GRID[i][j] == GRID_ATTACK_AREA) {
GRID[i][j] = GRID_BLANK;
}
}
}
}
function isInTrap() {
return GRID[ai-1][aj] != GRID_BLANK && GRID[ai][aj+1] != GRID_BLANK && GRID[ai][aj-1] != GRID_BLANK ||
GRID[ai+1][aj] != GRID_BLANK && GRID[ai][aj+1] != GRID_BLANK && GRID[ai][aj-1] != GRID_BLANK ||
GRID[ai+1][aj] != GRID_BLANK && GRID[ai-1][aj] != GRID_BLANK && GRID[ai][aj-1] != GRID_BLANK ||
GRID[ai+1][aj] != GRID_BLANK && GRID[ai-1][aj] != GRID_BLANK && GRID[ai][aj+1] != GRID_BLANK;
}