xxxxxxxxxx
3272
//wall order = []
var reset_toggle = false;
var grid = [];
var grids = [];
var total_players = 10;
var bank = false;
var x_padding = -0.1;
var x_Padding;
var rand = []
var yoffset = 0;
var y_padding = 0;
var y_Padding;
var mousedown = false;
var menuxy = [805,50];
var xmap = 0;
var ymap = 0;
var offset = 0;
var offsetx;
var xx = 0;
var yy = 0;
var wallbackup = [];
var gridbackup = [];
var primewall = [];
var len = 20;
var a = 0;
var ylen = 16;
//function updateLength(){};
var b = 1;
var co = [];
//function resetSketch(){};
var width = 1100;
var pathfinder = [];
var pathbackup = [];
var pathhist = []
var pathreset;
var nodesindex = [];
var nodestar = [];
var backupstar = [];
var starhist = [];
var key_Node = [];
var key_Node2 = [];
var nodestack = [];
var nodehist = [];
var stackstar = [];
var resetNodes;
var stack2 = [];
var buttons = [];
var sliders = [];
var slidersminimize;
var slidersdrag;
function Nodes(){};
var toggles;
var turn;
var info;
var switches;
var completed;
var game;
var start;
var paths;
var menu;
var menudrag;
var target;
var targetbackup;
var pathfind;
var pathfind2;
var findnodes;
var load;
var minimize;
var sliderPlayers;
var slidersMenu;
var length;
var height;
var v = width/(len);
var u = width -v/5;
var w ;
var toggle = 0;
var end = false;
var moves = 0;
var sides = 6;
var theta = 360/sides;
var nodes = [];
var current = [];
var stack = [];
var hist = [];
var start_array = [];
var start_backup = [];
var scores = [];
var plants = [];
var rocks = [];
var animals = [];
var ratio;
//important variables
var grid_count = 0;
var count = 0;
var nodes_counted = false;
var nodes_count = 0;
var nodes_connected = false;
var calculate_distance = false;
var neighbours_connected = false;
var nodescreated = 0;
var nodes_array_Created = false;
var grid_Cleared = false;
var paths_explored = false;
var paths_evaluated = 0;
var paths_completed = false;
var find_node_count = 0;
var paths_count = 0;
var total_paths = 0;
var node_check = 0;
var node_check_complete = false;
//
//function createGrid(){};
//function createPlayers(){};
//function home(){};
function setup(){
createCanvas(1100,660);
angleMode(DEGREES);
function createGrid(){
w = width/(len);
ratio = w/2 * sin(theta);
var wx = 1100/(ratio*2);
var ww = wx/len/2;
var ku = 660/ylen;
var kuu = ku/ylen/2;
for (var j=0;j<ylen;j++){
for(var i=0;i<len;i++){
var k = pow(-1,j);
var x = (ratio*1.5)+(ratio*2-ww+x_padding)*i+ratio/2*k;
var y = (w/2)+(ku-kuu-y_padding)*j;
var id = i+j*(len);
grid.push(new Cell(x,y,id,j,i));
gridbackup.push(new Cell(x,y,id,j,i));
}}
for(var i=0;i<grid.length;i++){
grid[i].init();
}
};
function createPlayers(a){
for (var i=0;i<a;i++){
var start = round(random(0,grid.length-1));
var x = round(random(0,len-1));
var y = round(random(0,ylen-1))
if(y===9&&(x>4&&x<15)){
y=y-1;
}
var yy = y;
current.push(grid[x+yy*len]);
stack[i]=[];
hist[i]=[];
start_array.push(grid[x+yy*len]);
scores[i]=[];
}
for(var i=0;i<current.length;i++){
var node_info = round(random(0,255));
var c2 = round(random(0,255));
var c3 = round(random(0,255));
var col = color(node_info,c2,c3);
current[i].pcol = col;
start_array[i].pcol = col;
}
};
function initialize(a){
createGrid();
createPlayers(a);
};
function home(x,y,w){
for(var i=0;i<w;i++){
var a = grid[x+i+y*len];
a.visited = true;
a.id = 0.01;
for(var j=0;j<a.walls.length;j++){
}
}
};
function pathfinders(a){
if(target){
target = targetbackup;
}
completed = false;
var r = round(random(0,grid.length-1));
for( var i=0;i< a;i++){
pathfinder.push(grid[r]);
pathbackup.push(grid[r]);
//pathbackup[i]
stack2[i] = [];
pathhist[i] = [];
}
var r = round(random(0,grid.length-1));
target = grid[r];
wallbackup = grid[r].walls;
//target.walls = [false,false,false,false,false,false];
targetbackup = grid[r];
for( var i=0;i< pathfinder.length;i++){
var c1 = round(random(0,255));
var c2 = round(random(0,255));
var c3 = round(random(0,255));
var col = color(c1,c2,c3);
//pathfinder[i].visited = true;
pathfinder[i].pcol2 = col;
pathfinder[i].depth = 0;
pathfinder[i].walls = [false,false,false,false,false,false];
}
}
function Nodes(array,bool){
for(var i=0;i<array.length;i++){
array[i].pathconnected = false;
array[i].node=undefined;
}
for(var i=0;i<array.length;i++){
if(array[i].total!==2){
if(!bool){
nodestar.push(grid[i]);
stackstar.push([]) ;
backupstar.push(grid[i]);
starhist.push([]);
}
nodesindex.push(grid[i]);
key_Node.push(grid[i]);
nodehist.push([]);
nodestack.push([]);
nodescreated ++;
}}
if(!bool){
for(var i=0;i<2;i++){
nodestar.push(nodesindex[i]);
stackstar.push([]) ;
backupstar.push(nodesindex[i]);
starhist.push([]);
}}
for(var i=0;i<nodesindex.length;i++){
nodesindex[i].node_to_node_dist[nodesindex[i].original_id] = 0;
nodesindex[i].path_ref = {};
nodesindex[i].path_ref[nodesindex[i].original_id] = [nodesindex[i]];
nodesindex[i].best_paths = [];
nodesindex[i].temp_paths = [];
}
};
function randomizeMap(){
for(var i=0;i<grid.length-1;i++){
var r = round(random(0,grid.length-1));
grid[r].walls = [false,false,false,false,false,false];
//}
}
};
function resetSketch(){
// xx=0;
// yy=0;
paths_explored = false;
nodescreated = 0;
neighbours_connected = false;
grid_Cleared = false;
grid_count = 0;
nodes_counted = false;
nodes_count = 0;
nodes_connected = false;
calculate_distance = false;
count = 0;
paths_completed = false;
nodes_array_Created = false;
paths_evaluated = 0;
nodes_count = 0;
find_node_count = 0;
paths_count = 0;
total_paths = 0;
node_check = 0;
node_check_complete = false;
xmap = 0;
ymap = 0;
toggles = 0;
turn = 0;
current = [];
grid = [];
hist = [];
stack = [];
start_array = [];
nodesindex = [];
key_Node = [];
key_Node2 = [];
nodestack = [];
nodehist = [];
stack2 = [];
pathfinder = [];
pathbackup = [];
pathhist = [];
target;
completed = false;
createGrid();
createPlayers(total_players);
if(bank){
//home(5,9,10);
}
pathfinders(1);
};
function resetPath(a){
completed = false;
stack2 = [];
pathfinder = [];
pathfinder2 = [];
pathbackup = [];
pathhist = [];
//target = targetbackup;
target ;
grid = gridbackup;
pathfinders(a);
for(var i=0;i<grid.length;i++){
grid[i].visited2 = false;
grid[i].visited3 = false;
}
};
function noded(){
if(calculate_distance&&!nodes_array_Created){
nodesindex = [];
key_Node = []
key_Node2 = [];
nodehist = [];
nodestack = [];
Nodes(grid,false);
nodes_array_Created = true;
}
};
resetSketch();
function amend(){
// total_players = sliderPlayers.value;
if(sliderPlayers.value&&sliderPlayers.toggle===1){
total_players = sliderPlayers.value;
}
if(height.value&&height.toggle===1){
ylen = height.value;
}
if(length.value&&length.toggle===1){
len = length.value;
}
//grid = [];
resetSketch();
}
textSize(12);
//randomizeMap();
menu = new button({
x:menuxy[0]+xx,
y:menuxy[1]+yy-10,
width:190+12,
height:320,
col:color(255,255,255,20),
label:"",
onClick: function(){
setups();
}
});
game = new button({
x:menuxy[0]+xx,
y:menuxy[1]+yy,
width:190,
height:30,
col:color(255,255,255,20),
label:"Map",
onClick: function(){
setups();
}
});
start = new button({
x:menuxy[0]+xx,
y:menuxy[1]+40+yy,
width:190,
height:30,
col:color(255,255,255,20),
label:"Start",
onClick: function(){
turns();
}
});
paths = new button({
x:menuxy[0]+xx,
y:menuxy[1]+40*2+yy,
width:95,
height:30,
col:color(255,255,255,20),
label:"Paths",
onClick: function(){
cellNeighbours();
}
});
reset = new button({
x:menuxy[0]+xx,
y:menuxy[1]+40*7+yy,
width:190,
height:30,
col:color(255,255,255,20),
label:"Reset",
onClick: function(){
resetSketch();
}
});
pathfind = new button({
x:menuxy[0]+xx,
y:menuxy[1]+40*3+yy,
width:160,
height:30,
col:color(255,255,255,20),
label:"Djikstra",
onClick: function(){
//mapPath();
}
});
pathfind2 = new button({
x:menuxy[0]+xx,
y:menuxy[1]+40*4+yy,
width:160,
height:30,
col:color(255,255,255,20),
label:"Djikstra Node",
onClick: function(){
//mapPath();
}
});
pathfind3 = new button({
x:menuxy[0]+xx,
y:menuxy[1]+40*5+yy,
width:160,
height:30,
col:color(255,255,255,20),
label:"Super Pathfinder",
onClick: function(){
//mapPath3();
}
});
pathfind4 = new button({
x:menuxy[0]+xx,
y:menuxy[1]+40*6+yy,
width:160,
height:30,
col:color(255,255,255,20),
label:"Multi Pathfinder",
onClick: function(){
//cellNeighbours();
}
});
pathreset = new button({
x:menuxy[0]+160+xx,
y:menuxy[1]+40*3+yy,
width:30,
height:30,
col:color(255,255,255,20),
label:"X",
onClick: function(){
resetPath(1);
}
});
resetNode = new button({
x:menuxy[0]+160+xx,
y:menuxy[1]+40*4+yy,
width:30,
height:30,
col:color(255,255,255,20),
label:"X",
onClick: function(){
noded(grid);
}
});
generateNodes = new button({
x:menuxy[0]+xx,
y:menuxy[1]+40*5+yy,
width:190,
height:30,
col:color(255,255,255,20),
label:"Generate Nodes",
onClick: function(){
noded(grid);
}
});
findnodes = new button({
x:menuxy[0]+xx,
y:menuxy[1]+40*6+yy,
width:190,
height:30,
col:color(255,255,255,20),
label:"Findnodes",
onClick: function(){
//findnode();
}
});
switches = new button({
x:menuxy[0]+95+xx,
y:menuxy[1]+40*2+yy,
width:95,
height:30,
col:color(255,255,255,20),
label:"Walls On/Off",
onClick: function(){
//setups();
}
});
menudrag = new button({
x:menuxy[0]+xx,
y:menuxy[1]+yy-10,
width:190,
height:10,
col:color(255,255,255,20),
label:"",
onClick: function(){
//setups();
},
id : 1
});
load = new button({
x:menuxy[0]+xx+4,
y:menuxy[1]+40*8+yy,
width:190,
height:30,
col:color(255,255,255,20),
label:"Load",
onClick: function(){
setups();
}
});
minimize = new button({
x:menuxy[0]+xx+190+2,
y:menuxy[1]+yy,
width:10,
height:10,
col:color(255,255,255,20),
label:"-",
onClick: function(){
hideMenu();
},
id: 1
});
var y = 560
var x = 90
var sw =6;
sliderPlayers = new button({
x:x,
y:y,
width:190,
height:sw,
col:color(255,255,255,20),
label:"No of Players",
value:1,
onClick: function(){
amend();
}
});
length = new button({
x:x,
y:y+14*1,
width:190,
height:sw,
col:color(255,255,255,20),
label:"XLen",
onClick: function(){
amend();
}
});
slidersMenu = new button({
x:x,
y:y-10,
width:190,
height:sw,
col:color(255,255,255,20),
label:"",
onClick: function(){
//setups();
}
});
height = new button({
x:x,
y:y+14*3,
width:190,
height:sw,
col:color(255,255,255,20),
label:"Ylen",
onClick: function(){
amend();
}
});
x_Padding = new button({
x:x,
y:y+14*4,
width:190,
height:sw,
col:color(255,255,255,20),
label:"X Padding",
onClick: function(){
amend();
}
});
slidersminimize = new button({
x:x,
y:y+14*4,
width:190,
height:sw,
col:color(255,255,255,20),
label:"-",
onClick: function(){
amend();
}
});
slidersdrag = new button({
x:x,
y:y+14*4,
width:190,
height:sw,
col:color(255,255,255,20),
label:"-",
onClick: function(){
amend();
}
});
y_Padding = new button({
x:x,
y:y+14*5,
width:190,
height:sw,
col:color(255,255,255,20),
label:"Y Padding",
onClick: function(){
amend();
}
});
buttons = [menu,game,start,paths,reset,pathfind,pathfind2,pathfind3,pathfind4,pathreset,generateNodes,findnodes,switches,load,sliderPlayers,minimize,menudrag,slidersMenu,slidersdrag,slidersminimize];
sliders = [sliderPlayers,length,height,x_Padding,y_Padding];
for(var i=0;i<sliders.length;i++){
if(sliders[i].toggle ===1){
//resetSketch();
}}
};
function button(config){
this.x = config.x;
this.y = config.y;
this.w = config.width;
this.h = config.height;
this.col = config.col;
this.id = config.id;
this.col2 = color(0);
this.label = config.label;
this.onClick = config.onClick||function(){};
//this.value = config.value;
this.toggle = 0;
this.toggle2 = 0;
this.bw = 6;
this.bh = 6;
this.bxo = 0;
this.bxo1 = this.x;
this.stroke = 4;
this.textSize = 12;
this.visible = true;
this.this = this;
this.slide = function(){
if(this.buttonPos&&mouseIsPressed&&mouseX<this.x+this.w&&mouseX>this.x){
this.value = abs(round(map(mouseX,this.x,this.x+this.w,0,40)));
}
}
this.draw = function(){
if(this.y+this.h<menu.h+menu.y+4+10&&this.y+4>menu.y){
if(this.toggle===1){
this.col =color(255,255,255,200);
this.stroke = 0;
this.col2 = color(0,0,0,120);
}
if(this.toggle===0){
this.stroke = 0;
this.col2 = color(0)
this.col =(255,255,255,80);
}
fill(this.col);
stroke(this.col2);
strokeWeight(this.stroke);
rect(this.x+xx,this.y+yy,this.w,this.h);
fill(255);
text(toggle,10,10);
fill(0);
strokeWeight(1);
textSize(this.textSize);
text(this.label,this.x+20+xx,this.y+20+yy);
//text(this.toggle,this.x+170,this.y+20)
strokeWeight(0);
}
};
this.draw2 = function(){
if(this.y+this.h<menu.h+menu.y+4&&this.y>menu.y-10){
if(this.toggle===1){
this.col =color(255,255,255,200);
this.stroke = 0;
this.col2 = color(0,0,0,120);
}
if(this.toggle===0){
this.stroke = 0;
this.col2 = color(0)
this.col =(255,255,255,80);
}
fill(this.col);
stroke(this.col2);
strokeWeight(this.stroke);
rect(this.x+xx,this.y+yy,this.w,30);
fill(255);
text(toggle,10,10);
fill(0);
strokeWeight(1);
textSize(this.textSize);
text(this.label,this.x+this.w/2-5+xx,this.y+20+yy);
//text(this.toggle,this.x+170,this.y+20)
strokeWeight(0);
}
};
this.draw3 = function(){
if(this.toggle===1){
this.col =color(255,255,255,200);
this.stroke = 0;
this.col2 = color(0,0,0,120);
}
if(this.toggle===0){
this.stroke = 0;
this.col2 = color(0)
this.col =(255,255,255,80);
}
fill(this.col);
stroke(this.col2);
strokeWeight(this.stroke);
rect(this.x+xx,this.y+yy,this.w,this.h);
fill(255);
text(toggle,10,10);
fill(0);
strokeWeight(2);
textSize(this.textSize);
text(this.label,this.x+this.w/2-5+xx+2,this.y+20+yy-10);
//text(this.toggle,this.x+170,this.y+20)
strokeWeight(0);
};
this.draw4 = function(){
if(this.toggle===1){
this.col =color(255,255,255,200);
this.stroke = 0;
this.col2 = color(0,0,0,120);
}
if(this.toggle===0){
this.stroke = 0;
this.col2 = color(0)
this.col =(255,255,255,80);
}
fill(this.col);
stroke(this.col2);
strokeWeight(this.stroke);
rect(this.x,this.y,this.w,this.h);
//this.bxo1 = this.x;
fill(255)
textSize(12);
text(this.label,this.x-80,this.y+5)
if(this.toggle===1){
rect(this.bxo,this.y-1,this.bw+2,this.bh+2);
this.bxo1 = this.bxo;
}
else{
rect(this.bxo1,this.y-1,this.bw,this.bh);
}
fill(255);
//if(this.toggle===1){
var k = round(map(this.bxo1,this.x,this.x+this.w,0,40));
text(k,this.x+this.w,this.y);
//}
fill(0);
strokeWeight(2);
strokeWeight(0);
};
this.checkmpos = function(){
if(this.id===1&&!switches.checkmpos()){
return mouseX>this.x+xx && mouseX <(this.x + this.w+xx) && mouseY>this.y+yy && mouseY <(this.y + this.h+yy);
}else{
if(this.y+this.h<menu.h+menu.y+4&&this.y+4>menu.y){
return mouseX>this.x+xx && mouseX <(this.x + this.w+xx) && mouseY>this.y+yy && mouseY <(this.y + this.h+yy);
}}
};
this.hover = function(){
if(this.checkmpos2()){
this.textSize += 0.5;
this.col2 = color(255);
this.col = color(255);
}
else{
this.textSize = 12;
}
if(this.textSize>=14){
this.textSize = 14;
}
return true;
};
this.checkmpos2 = function(){
return mouseX>this.x+xx && mouseX <(this.x + this.w+xx) && mouseY>this.y+yy && mouseY <(this.y + this.h+yy);
};
this.mouseClick = function(){
if(this.y+this.h<menu.h+menu.y+4+10&&this.y+4>menu.y){
if(this.checkmpos()&&mouseClicked){
if(this.toggle===0){
this.toggle=1;
this.onClick();
this.col =color(255,255,255,200);
this.stroke = 5;
this.col2 = color(0,0,0,120);
}
else{
this.toggle=0;
this.stroke = 4;
this.col2 = color(0)
this.col =(255,255,255,80);
}
}
}
};
this.mouseClick2 = function(){
if(this.y+this.h<menu.h+menu.y+4+10&&this.y+4>menu.y){
if(this.checkmpos()&&mouseIsPressed){
this.toggle=1;
this.stroke = 5;
}
else if(this.checkmpos()&&mouseReleased&&this.toggle===1||!this.checkmpos()&&this.toggle===1){
this.toggle=0;
this.onClick();
this.stroke = 4;
}}
};
this.mouseClick3 = function(){
if(this.y+this.h<menu.h+menu.y+4+10&&this.y+4>menu.y){
if(this.checkmpos()&&mouseIsPressed&&!mousedown){
this.toggle=1;
}
else if(mouseReleased){
this.toggle=0;
}
}
};
this.mouseClick4 = function(){
if(this.checkmpos()&&mouseClicked){
if(this.toggle===0){
this.toggle = 1;
}
else{
this.toggle=0;
menu.toggle2=0;
}}
};
this.mouseClick5 = function(){
if(this.checkmpos2()&&mouseIsPressed){
this.toggle=1;
this.stroke = 5;
}
else if(this.checkmpos2()&&mouseReleased&&this.toggle===1||!this.checkmpos2()&&this.toggle===1){
this.toggle=0;
this.stroke = 4;
}
};
this.buttonPos = function(){
var a;
for(var i=0;i<sliders.length;i++){
if(sliders[i].toggle===1&&sliders[i]!==this){
a = 1;
}
}
if(mouseX>this.x&&mouseX<this.x+this.w&&mouseY>this.y-2&&mouseY<this.y+this.h+2&&a!==1){
return true;
}
}
this.buttonClick = function(){
if(this.buttonPos()&&mouseIsPressed){
this.toggle=1;
mousedown = true;
}
if(this.toggle ===1&&mouseDragged&&mouseIsPressed){
//mousedown = false;
this.onClick();
//reset_toggle = true;
if(this.toggle===1&&mouseX<this.x+this.w&&mouseX>this.x){
this.bxo = mouseX
}
this.bxo = mouseX;
if(mouseX> this.x+this.w){
this.bxo = this.x+this.w;
}
if(mouseX< this.x){
this.bxo = this.x;
}}
//resetSketch()
};
if(this.toggle===0){
reset_toggle = false;
mousedown = false;
}
};
function index (i,j){
if(i<0||i>len-1||j<0||j>ylen-1){
return undefined;
}
else{
return i+j*len;
}
};
function lShape (x,y,colour,array,object){
for(var i=0;i<array.length;i++){
if(array[i]===true){
var thetab = theta * i;
var thetac = theta * i+theta;
stroke(colour);
strokeWeight(2);
line(x+w/2*sin(thetab),y+w/2*cos(thetab),x+w/2*sin(thetac),y+w/2*cos(thetac));
}else{
//noStroke();
}
}
};
function lShape2 (x,y,colour,array,object){
for(var i=0;i<array[c].length;i++){
//for (var j=0;j<array[c].)
//var a =
if(array[c][i]===true){
var thetab = theta * i+a;
var thetac = theta * i+theta+a;
stroke(colour);
strokeWeight(2);
line(x+w/2*sin(thetab),y+w/2*cos(thetab),x+w/2*sin(thetac),y+w/2*cos(thetac));
}else{
noStroke();
}
}
};
function hideMenu(){
var t = 3;
var height = menu.h;
if(minimize.toggle===1){
t++;
menu.h+=-30;
if(menu.h<=0){
menu.h = 0;
menu.toggle2=1;
}
}
if(minimize.toggle===0){
t++;
menu.h+=30;
if(menu.h>=320){
menu.h = 320;
menu.toggle2=0;
}
}
noStroke();
fill(51)
//rect(menuxy[0],menuxy[1],menuxy[0]+190,menuxy[1]+400);
};
function Cell (x,y,id,ypos,xpos,col){
this.original_id = id;
this.x = x+xmap;
this.y = y+ymap;
this.z = 0;
this.xpos = xpos;
this.ypos = ypos;
this.id = id;
this.nid = id;
this.walls = [];
this.edge = [];
this.fpos = [];
this.neighbour_cluster = [];
this.col = color(255, 255, 234);
this.pcol = this.col;
this.col2 = color(0, 0, 0);
this.vertex = [];
this.length = 0;
this.t = 0;
this.n1 = -1;
this.n2 = -1;
this.neighbours = [];
this.total = 0;
this.path = {};
this.node = false;
this.parent = [];
this.node_to_node_dist = {};
this.node_info = [];
this.myfootprint = {};
this.connections = [];
this.cons = [];
this.steps_to_nodes = 1;
this.child = [];
this.dist = 0;
this.found = [];
this.connections_to_Node = [];
this.addresstable = [];
this.pathtable = {};
this.pathtable_ref = {};
this.connectedNodes = {};
this.pathconnected = false;
this.imprinted_by = {};
this.nodesconnected = {};
this.score2 = 0;
this.nodes = 0;
this.init = function(){
var theta = 360/sides;
for (var i=0;i<total_players;i++){
//this.walls[i]=[true,true,true,true,true,true];
}
for (var i=0;i<sides;i++){
var thetab = theta * i;
var thetac = theta * i+theta;
this.walls.push(true);
this.node_info.push([null])
this.edge.push([this.x+w/2*sin(thetab),this.y+w/2*cos(thetab),this.x+w/2*sin(thetac),this.y+w/2*cos(thetac)]);
this.vertex.push([this.x+w/2*sin(thetac),this.y+(w/2)*cos(thetac)]);
this.length = dist(this.x+w/2*sin(thetab),this.y+w/2*cos(thetab),this.x+w/2*sin(thetac),this.y+w/2*cos(thetac));
}
};
this.showid = function(){
strokeWeight(0);
};
this.draw = function() {
// for(var i=0;i<this.walls.length;i++){
// for(var j=0;j<this.walls[i].length;j++){
// if(this.walls[i][j]!==false){
// //this.walls[i][j]=true;
// }
// }
// }
lShape(this.x,this.y,this.col2,this.walls,grid[this.original_id]);
if(this.t===1){
//this.visited = true;
}
if(this.visited ===true){
fill(255, 0, 0);
}
strokeWeight(0);
};
this.draw2 = function(c) {
lShape(this.x,this.y,this.col2,this.walls[0],grid[this.original_id]);
if(this.t===1){
this.visited = true;
}
if(this.visited ===true){
fill(255, 0, 0);
}
var b = this.walls;
strokeWeight(0);
};
this.fill = function(){
beginShape();
for(var k=0;k<sides;k++){
var thetab = theta * k;
var thetac = theta * k+theta;
fill(this.col);
if (this.visited) {
fill(this.pcol);
}
if(this.visited2){
fill(this.pcol2);
}
noStroke();
vertex(this.vertex[k][0],this.vertex[k][1]);
}
endShape();
};
this.highlight = function(){
beginShape();
for(var k=0;k<sides;k++){
noStroke();
var thetab = theta * k;
var thetac = theta * k+theta;
fill(0, 0, 255, 100);
vertex(this.x+w/2*sin(thetac),this.y+w/2*cos(thetac));
}
endShape();
};
this.highlight2 = function(){
beginShape();
for(var k=0;k<sides;k++){
noStroke();
var thetab = theta * k;
var thetac = theta * k+theta;
fill(this.pcol);
vertex(this.x+w/2*sin(thetac),this.y+w/2*cos(thetac));
}
endShape();
};
this.checkNeighbors = function(){
var x = this.xpos;
var y = this.ypos;
var neighbours = [];
//due to the offset introduced to make the hexagonal grid a slight adjustment needs to be made for the x values
var k = pow(-1,y);
if(k===1){
x=x+1;
}
var btmL = grid[index(x-1,y+1)];
var btmR = grid[index(x,y+1)];
var topL = grid[index(x-1,y-1)];
if(k===-1){
x=x-1;
}
if(k===1){
x=x-1;
}
var topR = grid[index(x+1,y-1)];
if(k===-1){
x=x+1;
}
var left = grid[index(x-1,y)];
var right = grid[index(x+1,y)];
var n = neighbours.length;
fill(255, 0, 0);
if(right){
//text(right.id,this.x,this.y);
}
if(topL&&!topL.visited&&topL.id!==100000){
topL.rpos = 3;
neighbours.push(topL);
}
if(topR&&!topR.visited&&topR.id!==100000){
topR.rpos = 2;
neighbours.push(topR);
}
if(right&&!right.visited&&right.id!==100000){
right.rpos = 1;
neighbours.push(right);
}
if(btmR&&!btmR.visited&&btmR.id!==100000){
btmR.rpos = 0;
neighbours.push(btmR);
}
if(btmL&&!btmL.visited&&btmL.id!==100000){
btmL.rpos = 5;
neighbours.push(btmL);
}
if(left&&!left.visited&&left.id!==100000){
left.rpos = 4;
neighbours.push(left);
}
var n = neighbours.length-1;
if(neighbours.length>0){
var r = round(random(0,n));
return neighbours[r];
}
else{
return undefined;
}
};
this.checkNeighbors2 = function(a){
var x = this.xpos;
var y = this.ypos;
var neighbours = [];
//due to the offset introduced to make the hexagonal grid a slight adjustment needs to be made for the x values
var k = pow(-1,y);
if(k===1){
x=x+1;
}
var btmL = grid[index(x-1,y+1)];
var btmR = grid[index(x,y+1)];
var topL = grid[index(x-1,y-1)];
if(k===-1){
x=x-1;
}
if(k===1){
x=x-1;
}
var topR = grid[index(x+1,y-1)];
if(k===-1){
x=x+1;
}
var left = grid[index(x-1,y)];
var right = grid[index(x+1,y)];
var n = neighbours.length;
fill(255, 0, 0);
if(right){
//text(right.id,this.x,this.y);
}
if(topL&&!topL.array2[a]&&topL.id!==100000){
topL.rpos = 3;
neighbours.push(topL);
}
if(topR&&!topR.array2[a]&&topR.id!==100000){
topR.rpos = 2;
neighbours.push(topR);
}
if(right&&!right.array2[a]&&right.id!==100000){
right.rpos = 1;
neighbours.push(right);
}
if(btmR&&!btmR.array2[a]&&btmR.id!==100000){
btmR.rpos = 0;
neighbours.push(btmR);
}
if(btmL&&!btmL.array2[a]&&btmL.id!==100000){
btmL.rpos = 5;
neighbours.push(btmL);
}
if(left&&!left.array2[a]&&left.id!==100000){
left.rpos = 4;
neighbours.push(left);
}
var n = neighbours.length-1;
if(neighbours.length>0){
var r = round(random(0,n));
if(neighbours.length>1){
var s = round(random(0,n));
}
return neighbours[r];
}
else{
return undefined;
}
};
this.nthPass = function(){
var x = this.xpos;
var y = this.ypos;
var neighbours = [];
//due to the offset introduced to make the hexagonal grid a slight adjustment needs to be made for the x values
var k = pow(-1,y);
if(k===1){
x=x+1;
}
var btmL = grid[index(x-1,y+1)];
var btmR = grid[index(x,y+1)];
var topL = grid[index(x-1,y-1)];
if(k===-1){
x=x-1;
}
if(k===1){
x=x-1;
}
var topR = grid[index(x+1,y-1)];
if(k===-1){
x=x+1;
}
var left = grid[index(x-1,y)];
var right = grid[index(x+1,y)];
var n = neighbours.length;
var left = grid[index(x-1,y)];
var right = grid[index(x+1,y)];
if(topL && this.id!==topL.id&&topL.id!==100000&&topL.score!==1&&this.score!==1&&topL.id!==this.neighbour_cluster[0]&&topL.score2<3&&this.score2<3){
topL.rpos = 3;
neighbours.push(topL);
}
if(topR && this.id!==topR.id&&topR.id!==100000&&topR.score!==1&&this.score!==1&&topR.id!==this.neighbour_cluster[0]&&topR.score2<3&&this.score2<3){
topR.rpos = 2;
neighbours.push(topR);
}
if(right && this.id!==right.id&&right.id!==100000&&right.score!==1&&this.score!==1&&right.id!==this.neighbour_cluster[0]&&right.score2<3&&this.score2<3){
right.rpos = 1;
neighbours.push(right);
}
if(btmR && this.id!==btmR.id&&btmR.id!==100000&&btmR.score!==1&&this.score!==1&&btmR.id!==this.neighbour_cluster[0]&&btmR.score2<3&&this.score2<3){
btmR.rpos = 0;
neighbours.push(btmR);
}
if(btmL && this.id!==btmL.id&&btmL.id!==100000&&btmL.score!==1&&this.score!==1&&btmL.id!==this.neighbour_cluster[0]&&btmL.score2<3&&this.score2<3){
btmL.rpos = 5;
neighbours.push(btmL);
}
if(left && this.id!==left.id&&left.id!==100000&&left.score!==1&&this.score!==1&&left.id!==this.neighbour_cluster[0]&&left.score2<3&&this.score2<3){
left.rpos = 4;
neighbours.push(left);
}
if(neighbours.length>0){
var r = round(random(0,neighbours.length-1));
return neighbours[r];
}
else{
return undefined;
}
};
this.drawpath = function(){
if(paths_explored||paths.toggle===1){
var x = this.xpos;
var y = this.ypos;
var a = [];
//due to the offset introduced to make the hexagonal grid a slight adjustment needs to be made for the x values
var k = pow(-1,y);
if(k===1){
x=x+1;
}
var btmL = grid[index(x-1,y+1)];
var btmR = grid[index(x,y+1)];
var topL = grid[index(x-1,y-1)];
if(k===-1){
x=x-1;
}
if(k===1){
x=x-1;
}
var topR = grid[index(x+1,y-1)];
if(k===-1){
x=x+1;
}
var left = grid[index(x-1,y)];
var right = grid[index(x+1,y)];
if(topL&&topL.walls[0]===false&&this.walls[3]===false){
a.push(topL);
this.dir = "nw";
}
if(topR&&topR.walls[5]===false&&this.walls[2]===false){
a.push(topR);
this.dir = "ne";
}
if(right&&right.walls[4]===false&&this.walls[1]===false){
a.push(right);
this.dir = "e";
}
if(btmR&&btmR.walls[3]===false&&this.walls[0]===false){
a.push(btmR);
this.dir = "se";
}
if(btmL&&btmL.walls[2]===false&&this.walls[5]===false){
a.push(btmL);
this.dir = "s";
}
if(left&&left.walls[1]===false&&this.walls[4]===false){
a.push(left);
this.dir = "sw";
}
if (a.length > 0) {
this.total = a.length
this.connect(a);
}
}
strokeWeight(0);
};
this.connect = function(a){
if(this.total !==2&&paths.toggle===1){
strokeWeight(10);
stroke(0, 0, 0);
point(this.x,this.y);
}
for(var i=0;i<a.length;i++){
stroke(0);
strokeWeight(2);
if(paths_explored){
this.neighbours[i] = a[i];
}
if(this.pathconnected===true&&findnodes.toggle===1){
stroke(255);
}
if(paths.toggle===1){
line(this.x,this.y,a[i].x,a[i].y);
}
}
if(paths_explored){
this.connected = true;
}
};
this.find = function (b,toggle,stack_array){
var x = this.xpos;
var y = this.ypos;
var neighbours = [];
//due to the offset introduced to make the hexagonal grid a slight adjustment needs to be made for the x values
var k = pow(-1,y);
if(k===1){
x=x+1;
}
var btmL = grid[index(x-1,y+1)];
var btmR = grid[index(x,y+1)];
var topL = grid[index(x-1,y-1)];
if(k===-1){
x=x-1;
}
if(k===1){
x=x-1;
}
var topR = grid[index(x+1,y-1)];
if(k===-1){
x=x+1;
}
var left = grid[index(x-1,y)];
var right = grid[index(x+1,y)];
var a = 0;
if(topL&&topL.walls[0]===false&&this.walls[3]===false&&!topL.visited2){
neighbours.push(topL);
}
if(topR&&topR.walls[5]===false&&this.walls[2]===false&&!topR.visited2){
neighbours.push(topR);
}
if(right&&right.walls[4]===false&&this.walls[1]===false&&!right.visited2){
neighbours.push(right);
}
if(btmR&&btmR.walls[3]===false&&this.walls[0]===false&&!btmR.visited2){
neighbours.push(btmR);
}
if(btmL&&btmL.walls[2]===false&&this.walls[5]===false&&!btmL.visited2){
neighbours.push(btmL);
}
if(left&&left.walls[1]===false&&this.walls[4]===false&&!left.visited2){
neighbours.push(left);
}
if(neighbours.length>0){
var targeta = this.forward(neighbours,b,toggle,stack_array);
var targetb = this.nearest(neighbours,b,toggle,stack_array);
if(targeta){
line(this.x,this.y,b.x,b.y);
return targeta;
}
else{
line(this.x,this.y,b.x,b.y);
return targetb;
}}
};
this.find2 = function (){
var x = this.xpos;
var y = this.ypos;
var neighbours = [];
//due to the offset introduced to make the hexagonal grid a slight adjustment needs to be made for the x values
var k = pow(-1,y);
if(k===1){
x=x+1;
}
var btmL = grid[index(x-1,y+1)];
var btmR = grid[index(x,y+1)];
var topL = grid[index(x-1,y-1)];
if(k===-1){
x=x-1;
}
if(k===1){
x=x-1;
}
var topR = grid[index(x+1,y-1)];
if(k===-1){
x=x+1;
}
var left = grid[index(x-1,y)];
var right = grid[index(x+1,y)];
var a = 0;
if(topL&&topL.walls[0]===false&&this.walls[3]===false&&!topL.visited2){
neighbours.push(topL);
}
if(topR&&topR.walls[5]===false&&this.walls[2]===false&&!topR.visited2){
neighbours.push(topR);
}
if(right&&right.walls[4]===false&&this.walls[1]===false&&!right.visited2){
neighbours.push(right);
}
if(btmR&&btmR.walls[3]===false&&this.walls[0]===false&&!btmR.visited2){
neighbours.push(btmR);
}
if(btmL&&btmL.walls[2]===false&&this.walls[5]===false&&!btmL.visited2){
neighbours.push(btmL);
}
if(left&&left.walls[1]===false&&this.walls[4]===false&&!left.visited2){
neighbours.push(left);
}
if(neighbours.length>0){
var r = round(random(0,neighbours.length-1));
return neighbours[r];
}
else{
return false;
}
};
this.forward = function(a,k,toggle,stack_array){
var b = this;
var c;
for(var i=0;i<a.length;i++){
c = a[i];
var d1 = dist(b.x,b.y,k.x,k.y);
var d2 = dist(a[i].x,a[i].y,k.x,k.y);
if(d1===d2){
if(toggle){
c.depth = this.depth+1;
pathfinder.push(c);
stack2.push(stack_array);
pathhist.push([]);
}
}else{
if(d1>d2){
b = c;
}
else{
if(toggle===1){
c.depth = this.depth+1;
pathfinder.push(c);
stack2.push(stack_array);
pathhist.push([]);
}
c = false;
}
}
}
return c;
};
this.nearest = function(a,k,toggle,stack_array){
var ta = 0;
var tb = 0;
var b = a[0];
var c;
for(var i=0;i<a.length-1;i++){
c = a[i+1];
var d1 = dist(b.x,b.y,k.x,k.y);
var d2 = dist(c.x,c.y,k.x,k.y);
if(d1===d2){
if(toggle){
c.depth = this.depth+1;
pathfinder.push(c);
stack2.push(stack_array);
pathhist.push([]);
}
}else{
if(d1>d2){
if(toggle){
b.depth = this.depth+1;
pathfinder.push(b);
stack2.push(stack_array);
pathhist.push([]);
}
b = c;
}
else{
if(toggle){
c.depth = this.depth+1;
pathfinder.push(c);
stack2.push(stack_array);
pathhist.push([]);
//c = b;
}
}}
}
return b;
};
this.findnode = function(){
if((nodes_connected)){
// if(!nodesindex[0]){
// fill(255)
// text("please generate nodes",30, 10)
// }
// else{
if(this.id!==100000){
var x = this.xpos;
var y = this.ypos;
var a = [];
//due to the offset introduced to make the hexagonal grid a slight adjustment needs to be made for the x values
var k = pow(-1,y);
if(k===1){
x=x+1;
}
var btmL = grid[index(x-1,y+1)];
var btmR = grid[index(x,y+1)];
var topL = grid[index(x-1,y-1)];
if(k===-1){
x=x-1;
}
if(k===1){
x=x-1;
}
var topR = grid[index(x+1,y-1)];
if(k===-1){
x=x+1;
}
var left = grid[index(x-1,y)];
var right = grid[index(x+1,y)];
if(!this.node){
if(topL&&topL.walls[0]===false&&this.walls[3]===false){
if(topL.node&&!this.node){
if(this.parent[0]&&this.parent[0]!==topL){
this.parent[1] = topL
}
else{
this.parent[0] = topL;
}
}
}
if(topR&&topR.walls[5]===false&&this.walls[2]===false){
if(topR.node&&!this.node){
if(this.parent[0]&&this.parent[0]!==topR){
this.parent[1] = topR
}
else{
this.parent[0] = topR;
}
}
}
if(right&&right.walls[4]===false&&this.walls[1]===false){
if(right.node&&!this.node){
if(this.parent[0]&&this.parent[0]!==right){
this.parent[1] = right;
}
else{
this.parent[0] = right;
}}
}
if(btmR&&btmR.walls[3]===false&&this.walls[0]===false){
if(btmR.node&&!this.node){
if(this.parent[0]&&this.parent[0]!==btmR){
this.parent[1] = btmR;
}
else{
this.parent[0] = btmR;
}}
}
if(btmL&&btmL.walls[2]===false&&this.walls[5]===false){
if(btmL.node&&!this.node){
if(this.parent[0]&&this.parent[0]!==btmL){
this.parent[1] = btmL;
}
else{
this.parent[0] = btmL;
}}
}
if(left&&left.walls[1]===false&&this.walls[4]===false){
if(left.node&&!this.node){
if(this.parent[0]&&this.parent[0]!==left){
this.parent[1] = left;
}
else{
this.parent[0] = left;
}}
}
}
if(this.node){
this.parents = [];
}
if(this.parent&&!this.parent[0]){
if(!this.node&&!this.neighbours[0].node&&!this.parent[0]&&this.neighbours[0].parent[0]){
this.parent[0] = this.neighbours[0].parent[0];
}
if(!this.node&&!this.neighbours[1].node&&!this.parent[0]&&this.neighbours[1].parent[0]){
this.parent[0] = this.neighbours[1].parent[0];
this.step = 1;
}
}
if(this.parent[0]&&!this.parent[1]){
if(!this.node&&!this.neighbours[0].node&&this.parent[0]&&!this.parent[1]&&this.neighbours[0].parent[0]&&this.neighbours[0].parent[0]!==this.parent[0]){
this.parent[1] = this.neighbours[0].parent[0];
}
if(!this.node&&!this.neighbours[0].node&&this.parent[0]&&!this.parent[1]&&this.neighbours[0].parent[1]&&this.neighbours[0].parent[1]!==this.parent[0]){
this.parent[1] = this.neighbours[0].parent[1];
}
if(!this.node&&!this.neighbours[1].node&&this.parent[0]&&!this.parent[1]&&this.neighbours[1].parent[0]&&this.neighbours[1].parent[0]!==this.parent[0]){
this.parent[1] = this.neighbours[1].parent[0];
}
if(!this.node&&!this.neighbours[1].node&&this.parent[0]&&!this.parent[1]&&this.neighbours[1].parent[1]&&this.neighbours[1].parent[1]!==this.parent[0]){
this.parent[1] = this.neighbours[1].parent[1];
}
}
}
//}
}
strokeWeight(0);
};
this.travelpath = function(){
var x = this.xpos;
var y = this.ypos;
var a = [];
//due to the offset introduced to make the hexagonal grid a slight adjustment needs to be made for the x values
var k = pow(-1,y);
if(k===1){
x=x+1;
}
var btmL = grid[index(x-1,y+1)];
var btmR = grid[index(x,y+1)];
var topL = grid[index(x-1,y-1)];
if(k===-1){
x=x-1;
}
if(k===1){
x=x-1;
}
var topR = grid[index(x+1,y-1)];
if(k===-1){
x=x+1;
}
var left = grid[index(x-1,y)];
var right = grid[index(x+1,y)];
if(topL&&topL.walls[0]===false&&this.walls[3]===false){
if(topL.node){
a.push(topL);
}
else{
//this.parent = topL;
}}
if(topR&&topR.walls[5]===false&&this.walls[2]===false){
if(topR.node){
a.push(topR);
}
else{
//this.parent = topR;
}}
if(right&&right.walls[4]===false&&this.walls[1]===false){
if(right.node){
a.push(right);
}
else{
//this.parent = right;
}}
if(btmR&&btmR.walls[3]===false&&this.walls[0]===false){
if(topL.node){
a.push(btmR);
}
else{
//this.parent = btmR;
}}
if(btmL&&btmL.walls[2]===false&&this.walls[5]===false){
if(btmL.node){
a.push(btmL);
}
else{
//this.parent = topL;
}}
if(left&&left.walls[1]===false&&this.walls[4]===false){
if(left.node){
a.push(left);
}
else{
//this.parent = topL;
}}
if (a.length>0) {
var r = round(random(0,a.length-1));
return a[r];
}
else{
return false;
}
};
this.histScore = function(){
//this.score = 0;
var x = this.xpos;
var y = this.ypos;
var neighbours = [];
//due to the offset introduced to make the hexagonal grid a slight adjustment needs to be made for the x values
var k = pow(-1,y);
if(k===1){
x=x+1;
}
var btmL = grid[index(x-1,y+1)];
var btmR = grid[index(x,y+1)];
var topL = grid[index(x-1,y-1)];
if(k===-1){
x=x-1;
}
if(k===1){
x=x-1;
}
var topR = grid[index(x+1,y-1)];
if(k===-1){
x=x+1;
}
var left = grid[index(x-1,y)];
var right = grid[index(x+1,y)];
var a = 0;
if(topL&&topL.walls[0]===false&&this.walls[3]===false&&this.id!==topL.id){
topL.rpos = 3;
neighbours.push(topL);
a ++;
}
if(topR&&topR.walls[5]===false&&this.walls[2]===false&&this.id!==topR.id){
topR.rpos = 2;
neighbours.push(topR);
a ++;
}
if(right&&right.walls[4]===false&&this.walls[1]===false&&this.id!==right.id){
right.rpos = 1;
neighbours.push(right);
a ++;
}
if(btmR&&btmR.walls[3]===false&&this.walls[0]===false&&this.id!==btmR.id){
btmR.rpos = 0;
neighbours.push(btmR);
a ++;
}
if(btmL&&btmL.walls[2]===false&&this.walls[5]===false&&this.id!==btmL.id){
btmL.rpos = 5;
neighbours.push(btmL);
a ++ ;
}
if(left&&left.walls[1]===false&&this.walls[4]===false&&this.id!==left.id){
left.rpos = 4;
neighbours.push(left);
a ++;
}
var n = neighbours.length;
if (n > 0) {
fill(255, 0, 0);
this.score = 1;
}else{
}
};
this.hover = function(){
var x = mouseX-xmap;var y = mouseY-ymap;
var a = this.edge;
for(var i=0;i<a.length;i++){
var x1 = a[i][0];
var y1 = a[i][1];
var x2 = a[i][2];
var y2 = a[i][3];
var d1 = dist(x,y,x1,y1);
var d2 = dist(x,y,x2,y2);
var d3 = dist(x1,y1,x2,y2);
var d4 = d1+d2;
var d5 = dist(this.x,this.y,x,y);
var dy = y1-y2;
var dx = x1-x2;
var dy2 = y2-y1;
var dx2 = x2-x1;
var dmx = x-x1;
var dmy = y-y1;
var dmx2 = x-x2;
var dmy2 = y-y2;
//fill(255, 0, 0);
var thetaXY1 = atan2(dy,dx);
var thetaXY2= atan2(dy2,dx2);
var thetaMXY2 = atan2(dmy,dmx);
var thetaMXY1 = atan2(dmy2,dmx2);
if((thetaXY1>=0&&thetaMXY1>=thetaXY1&&thetaMXY1>=0&&d1<=this.length&&d2<=this.length)||(thetaXY1<=0&&thetaMXY1<=0&&thetaMXY1>=thetaXY1&&d1<=this.length&&d2<=this.length)||(thetaXY2>=0&&thetaMXY2>=0&&thetaMXY2<=thetaXY2&&d1<=this.length&&d2<=this.length)||(thetaXY2<=0&&thetaXY2<=0&&thetaMXY2<=thetaXY2&&d1<=this.length&&d2<=this.length)||d5<=this.length/1.5){
//text("hello",this.x,this.y);
return true;
}
}
};
this.ppos = function(){
};
this.checkp = function(){
if(this.hover()&&mouseOver){
this.col = color(29, 131, 240);
this.col2 = color(212, 8, 8);
}
else{
this.col = color(0, 204, 255);
this.col2 = color(162, 0, 255);
}
};
this.toggle = function(){
if(this.hover()&&mouseClicked){
this.t++;
if(this.t===2){this.t=0;}
}
};
this.info = function(){
if(xmap<-200){
xmap = -200;
}
if(ymap<-200){
ymap = -200;
}
if(xmap>500){
xmap = 500;
}
if(ymap>350){
ymap = 350;
}
var a = 815-xmap;
var b = 410-ymap;
if((this.hover()&&mousePressed&&(game.toggle===1||paths.toggle===1||start.toggle===1||findnodes.toggle===1)||this.toggle===1)&&!mousedown){
fill(255)
stroke(0)
rect(a,b-10,190,250)
fill(0)
text(this.walls,a,b);
text("Total" +" " + this.total,a,b+20);
text("Node" +" " + this.node,a,b+20*2);
text("Node" +" " + this.nodeNode,a+90,b+20*2);
text("Id" +" " +this.original_id,a,b+20*3);
text("Cluster " +" " +this.id,a,b+20*4);
text("Neighbours" +" " +this.neighbours.length,a,b+20*5);
for(var i=0;i<this.neighbours.length;i++){
text(this.neighbours[i].original_id,a+30*i,b+20*6)
}
text("Toggle " +" " +this.t,a,b+20*7);
text("Visited:" + " " + this.visited,a,b+20*8);
//}
text("Path connected:" +" " + this.pathconnected,a,b+20*9);
text("Parents :",a,b+20*10);
if(this.parent[0]){
for(var i=0;i<2;i++){
stroke(51);
strokeWeight(0)
if(this.parent[i]){
text(this.parent[i].original_id,60 + a+40*i,b+20*10);
}}}
text("Connections :",a,b+20*11);
var d = -1;
for(var i=0;i<this.node_info.length;i++){
d ++;
if(this.node_info[i][1]){
text("[ "+this.node_info[i][1].original_id+ " :"+ this.node_info[i][0]+"], ",80+a+60*d,b+20*11);
}
else{
d --;
}
}
if(this.node){
text("Children :", a,b+20*12);
for(var i=0;i<this.child.length;i++){
text(this.child[i][1].original_id +", ", a+50+25*i,b+20*12);
}}}
};
this.neighbour_Node = function(a){
var neighbours = []
for(var i=0;i<this.neighbours.length;i++){
if(!this.neighbours[i].connectedNodes[a]){
neighbours.push(this.neighbours[i]);
}
}
if(neighbours.length>0){
var r = round(random(0,neighbours.length-1));
return neighbours[r];
}
else{
return undefined;
}
};
this.path_to_node = function(){
if(this.neighbours.length===2){
this.connection = [Object.keys(this.connectedNodes)];
}
if(this.neighbours.length===2){
for(var i=0;i<this.connection[0].length;i++){
this.connections[i] = grid[parseInt(this.connection[0][i],10)];
}}
};
this.connectallnodes = function(objName,obj){
this.connections_to_Node = [Object.keys(this.nodesconnected),Object.values(this.nodesconnected)];
for(var i=0;i<this.connections_to_Node[0].length;i++){
this.addresstable[i] = [grid[parseInt(this.connections_to_Node[0][i])],this.connections_to_Node[1][i]]
}
this.temp_paths = [Object.keys(this.pathtable),Object.values(this.pathtable)];
for(var i=0;i<this.temp_paths[0].length;i++){
this.best_paths[i] = [grid[parseInt(this.temp_paths[0][i])],this.temp_paths[1][i]];
}
for(var i=0;i<this.temp_paths[0].length;i++){
this.best_paths[i] = [grid[parseInt(this.temp_paths[0][i])],this.temp_paths[1][i]];
}
};
this.flattenDeep = function (arr1) {
return arr1.reduce((acc, val) => Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val), []);
};
this.neighbourNode = function(toggle,b,c){
var neighbour_Node = [];
//console.log(b);
for(var i=0;i<this.node_info.length;i++){
var a = this.node_info[i];
if(a[0]){
var k = a[1].node_to_node_dist[b];
if(a[1].imprinted_by[b]){
if(k>this.node_to_node_dist[b] + a[0]){
neighbour_Node.push(a);
}
}
else{
neighbour_Node.push(a);
}}
}
if(neighbour_Node.length>1){
var a = this.shortestPath(neighbour_Node,c,toggle);
if(a){
//var a = neighbour_Node[0]
return a;
}}
else if(neighbour_Node.length===1){
return neighbour_Node[0];
}
};
this.shortestPath = function(a,c,toggle){
//console.log(c.original_id);
var neighbour_Node = a[0];
for(var i=1;i<a.length;i++){
if(neighbour_Node[0]>a[i][0] ){
neighbour_Node = a[i];
}
else{
if(toggle){
a[i][1].node_to_node_dist[c.original_id] = this.node_to_node_dist[c.original_id] + a[i][0];
c.nodesconnected[a[i][1].original_id] = a[i][1].node_to_node_dist[c.original_id];
if(!this.path_ref[c.original_id]){
this.path_ref[c.original_id] = [this]
}
a[i][1].path_ref[c.original_id] = [this.path_ref[c.original_id],a[i][1]];
a[i][1].path_ref[c.original_id] = a[i][1].path_ref[c.original_id].flat();
c.pathtable[a[i][1].original_id] = [a[i][1].path_ref[c.original_id]];
backupstar.push(c);
nodestar.push(a[i][1]);
stackstar.push([]);
}
}
}
return neighbour_Node;
};
this.nextNode = function(a,toggle,stack_array){
var neighbour_Node = [];
var child;
for(var i=0;i<this.child.length;i++){
var a = this.child[i];
if(a[1] === target){
child = a;
}
}
if(!child){
for(var i=0;i<this.node_info.length;i++){
var a = this.node_info[i];
if(a[0]){
if(!a[1].visited2){
neighbour_Node.push(a);
}}
}
if(neighbour_Node.length>1){
var a = this.shortestPath2(neighbour_Node);
if(a){
if(this.child.length>0&&toggle){
for(var i=0;i<this.child.length;i++){
var k = this.child[i][1];
var b = k.parent[0];
var c = k.parent[1];
if((this===b&&a[1]===c)||(this===c&&a[1]===b)){
//this.seen = true;
stack_array.push(k);
k.pcol2 = color(0,0,0,150);
k.depth = this.depth;
k.visited2 = true;
}
}
}
return a[1];
}}
else if(neighbour_Node.length===1){
var a = neighbour_Node[0][1];
if(this.child.length>0&&toggle){
for(var i=0;i<this.child.length;i++){
var k = this.child[i][1];
var b = k.parent[0];
var c = k.parent[1];
//this.seen = true;
if((this===b&&a===c)||(this===c&&a===b)){
stack_array.push(k);
k.pcol2 = color(0,0,0,150);
k.depth = this.depth;
k.visited2 = true;
}
}}
return a;
}
else{
return undefined;
}
}
else{
this.parentNode(stack_array,toggle,child);
return target;
}
};
this.parentNode = function(stack_array,toggle,child){
var step;
for(var i=0;i<this.child.length;i++){
var a = this.child[i];
if(a[1] ===target){
step = a[0];
}}
var a;
var b;
var c;
for(var i=0;i<2;i++){
var x = target.node_info[i];
if(a){
b = x;
}
else if(!a){
a = x;
}}
var d1 = dist(a[1].x,a[1].y,target.x,target.y);
var d2 = dist(b[1].x,b[1].y,target.x,target.y);
var array = [];
for(var i=0;i<this.child.length;i++){
var k = this.child[i];
var d = k[1].node_info[0];
var c = k[1].node_info[1];
if(d[1]!==a[1]&&c!==b[1]&&c[1]!==a[1]){
array.push(k)
}}
if(array.length>0){
for(var i=0;i<array.length;i++){
var k = array[i];
var d = k[1].node_info[0];
var c = k[1].node_info[1];
// if(){
k[1].pcol2 = color(0,0,0,150);
k[1].depth = this.depth;
k[1].visited2 = true;
}}
//return target;
// if(a[0]<step&a[1]===this){
// for(var i=0;i<a[1].child.length;i++){
// var k = a[1].child[i];
// var d = k[1].node_info[0];
// var c = k[1].node_info[1];
//
// if((d[1]===a[1]&&d[0]<=step-1||c[1]===a[1]&&c[0]<=step-1)){
// stack_array.push(k[1]);
// k[1].pcol2 = color(0,0,0,150);
// k[1].depth = this.depth;
// k[1].visited2 = true;
// }}
// return target;
// }
// else if(b[1]===this){
// for(var i=0;i<b[1].child.length;i++){
// var k = b[1].child[i];
// var d = k[1].node_info[0];
// var c = k[1].node_info[1];
//
// if(d[1]===b[1]&&d[0]<=step-1||c[1]===b[1]&&c[0]<=step-1){
// stack_array.push(k[1]);
// k[1].pcol2 = color(0,0,0,150);
// k[1].depth = this.depth;
// k[1].visited2 = true;
// }}
// return target;
// }
};
this.shortestPath2 = function(a){
//console.log(c.original_id);
var node = a[0];
for(var i=1;i<a.length;i++){
var d1 = dist(node[1].x,node[1].y,target.x,target.y);
var d2 = dist(a[i][1].x,a[i][1].y,target.x,target.y);
if(d1>d2){
node = a[i];
}
}
return node;
};
this.check_node_info = function(){
var temp = 0;
for(var i=0;i<this.node_info.length;i++){
if(this.node_info[i][0]){
temp ++;
}
}
this.nodes = temp;
};
this.dd = function(){
text(this.depth,this.x-5,this.y+5);
};
};
function shortestPath(a){
};
function check (a, b) {
return (a.length !== b.length) ? false :
!(a.some(function(row, index) {
return a[index] !== b[index];
}));
};
// this function has been amended from its previous iteration, the neighbor/neighbour function now updates its target cel with a reference position this.rpos which can be called to more easily locate the required walls to remove. Reference position will return a position from 0-n according to the number of sides, for the hexagon it returns 0-5 with 0 being the bottom right line and moving counter clockwise. 0 is paired with 3, 1 with 4, 2 with 5, 3 with 0, 4 with 1, and 5 with 2.
function removeWalls (a, b) {
if (b.rpos === 0) {
a.walls[0] = false;
b.walls[3] = false;
} else if (b.rpos === 1) {
a.walls[1] = false;
b.walls[4] = false;
} else if (b.rpos === 2) {
a.walls[2] = false;
b.walls[5] = false;
} else if (b.rpos === 3) {
a.walls[3] = false;
b.walls[0] = false;
} else if (b.rpos === 4) {
a.walls[4] = false;
b.walls[1] = false;
} else if (b.rpos === 5) {
a.walls[5] = false;
b.walls[2] = false;
}
};
function rebootPlayers(){
current = [];
if(len>20){
for (var i=0;i<current.length;i++){
start_array[i]= current.slice(i,1);
start_array[i].pcol = current[i].pcol;
}
}
else{
for (var i=0;i<start_array.length;i++){
start_array[i]= current.slice(i,1);
start_array[i].pcol = current[i].pcol;
}
}
};
function setups(){
for(var i=0;i<grid.length;i++){
if(grid[i].total!==2&&grid[i].neighbours.length>0){
grid[i].node = true;
}
if(grid[i].total===2&&grid[i].neighbours.length>0){
grid[i].node = false;
}
}
if(game.toggle===1){
if(reset.toggle===1){
start.toggle=0
switches.toggle=0
game.toggle=0;
reset.toggle=0;
//paths.toggle=0;
pathfind.toggle=0;
}
for(var i=0;i<grid.length;i++){
grid[i].fill();
grid[i].hover();
grid[i].info();
grid[i].checkp();
grid[i].histScore();
}
fill(255);
text("PRESS LEFT MOUSE TO START",100,10);
}
for (var i = 0; i < current.length; i++) {
var a = current[i].original_id;
//current[i].visited = true;
}
};
// grid.histscore is called before and populates each cell with a score. The function checks if a neighbouring cell contains the same id, and if that neighbouring cell has an open wall with the cell in question. If yes the cell score is updated to 1. A binary figure is the only thing thats required because here were just checking how many open ends each path has. On toggle 2 the program will select a random wall shared with a neighbour with a different id, remember that as a "current" cell moves it imprints its own id onto the new cell. "Note if you wanted yo know the original id this is stored in this.original_id". So now some "currents" once returned to their starting position have an open wall, we now need another open wall to guarantee that the maze is completable. To accomplish this we step through the history array. A 2d array which stores all the histories of the "currents" and total the scores in each path. For a path to be open it should have a score of at least 2, meaning its connected to two other paths of different id's. If the score therefore is less than two we return true.
function checkhist(a){
var score = [];
var score2 = [];
var result = true;
for(var i=0;i<a.length;i++){
if(a[i].score2 >=2){
result = false;
}
}
return result;
};
// This function is used to check if neighbouring cells have the same id. It takes an array and returns the neighbouring cell along with the original cell which produced the neighbour, this information can then be passed into the remove wall function.
function randomNth(a){
var t = [];
for(var i=0;i<a.length;i++){
var next = a[i].nthPass();
if(next){
t.push([a[i],next]);
}
}
if(t.length>0){
var r = round(random(0,t.length-1));
t[r][0].nthPass();
t[r][0].score = 1;
t[r][1].score = 1;
// t[r][0].score2 ++;
// t[r][1].score2 ++;
if(!t[r][0].neighbour_cluster[0]){
t[r][0].neighbour_cluster[0] = t[r][1].id;
if(!t[r][1].neighbour_cluster[0]){
t[r][1].neighbour_cluster[0] = t[r][0].id;
}
else{
t[r][1].neighbour_cluster[1] = t[r][0].id;
t[r][1].score2 = 2;
}
}
else{
t[r][0].neighbour_cluster[1] = t[r][1].id;
t[r][0].score2 = 2;
if(!t[r][1].neighbour_cluster[0]){
t[r][1].neighbour_cluster[0] = t[r][0].id;
}
else{
t[r][1].neighbour_cluster[1] = t[r][0].id;
t[r][1].score2 = 2;
}
}
neighbouringCluster(t[r][0]);
neighbouringCluster(t[r][1]);
return t[r];
}else{return false;}
};
function neighbouringCluster(a){
for(var i=0;i<grid.length;i++){
if(grid[i].id===a.id){
grid[i].neighbour_cluster = a.neighbour_cluster;
grid[i].score2 = a.score2;
}
}
};
function trimStack(a,b){
for(var i=a.length-1;i>-1;i--){
var next = a[i].checkNeighbors();
if(!next&&a[i]!==b){
a.splice(i,1);
}}
};
function trimStackStar(a,b){
for(var i=a.length-1;i>-1;i--){
var next = a[i].neighbourNode(false,b);
if(!next){
a.splice(i,1);
}}
};
function turns(){
text(toggle,10,10);
if(reset.toggle===1){
findnodes.toggle = 0;
start.toggle=0
switches.toggle=0
game.toggle=0;
generateNodes.toggle = 0;
pathfind.toggle=0;
}
if(start.toggle===1&&!!!paths_explored){
for (var i = 0; i < current.length; i++) {
var a = start_array[i].original_id;
//current[i].myfootprint[a] =true;
var next = current[i].checkNeighbors();
current[i].highlight();
if (next) {
next.id=current[i].id;
next.pcol=current[i].pcol;
next.visited = true;
//next.myfootprint[a] = true;
// STEP 2
stack[i].push(current[i]);
hist[i].push(current[i]);
// STEP 3
removeWalls(current[i], next);
// STEP 4
current[i] = next;
trimStack(stack[i],start_array[i]);
}
else if (stack[i].length > 0) {
current[i] = stack[i].pop();
turn++;
}
}
}
//Histscore assigns a score to each cell based on its id. if it has an open wall shared with a neighbour of a different id, then it assigns a score of one. As the history is a two dimentional array checkhist is used to check each checking cell history path. It totals the scores of the history and if the score is less than 2 it returns true. If score equals 0, then that section of the maze is completely self contained and therefore inaccessible. if it is equal to one it means that it only has one open path. If there are to many sections with only one open path they can create sections of the maze which is shared by another with only one open path and again becaome self contained and inaccessible. So we need a score of 2 or more.
if(grid_Cleared){
var temp =[];
for (var i=hist.length-1;i>-1;i--) {
var a = checkhist(hist[i]);
if(a){
temp.push(hist[i]);
//hist[i].pop();
}}
// The checking cell histories with a score of less than 2 are pushed into the temp array. RandomNth is used to pick a random cell with a neighbour of a different id, and removeWalls is used to effect the removal of the wall. Temp is cleared to disable a loop.
for (var i=temp.length-1;i>-1; i--){
var pickCell = randomNth(temp[i]);
if(pickCell){
removeWalls(pickCell[0],pickCell[1]);
}
else{
temp.pop();
}
}
if(temp.length===0){
paths_explored = true;
}
}
gridbackup = grid;
};
function cellNeighbours (){
if(reset.toggle===1){
start.toggle=0;
switches.toggle=0;
game.toggle=0;
pathfind.toggle=0;
pathfind2.toggle=0;
pathfind3.toggle=0;
pathfind4.toggle=0;
}
for (var i = 0; i < grid.length; i++) {
if(grid[i].visited2&&!grid[i].visited3){
grid[i].fill();
grid[i].dd();
//grid[i].draw();
}
grid[i].drawpath();
if(pathfind2.toggle!==1&&pathfind.toggle!==1){
grid[i].findnode();
grid[i].path_to_node();
grid[i].connectallnodes();
}
grid[i].info();
grid[i].hover();
grid[i].check_node_info();
if(switches.toggle===1){
grid[i].draw(sides);
}
if(grid[i].node&&grid[i].parent.length>0){
grid[i].parent = [];
}
if(grid[i].visited&&!grid[i].counted){
grid_count++;
grid[i].counted = true;
}
if(grid_count===grid.length){
grid_Cleared = true;
}
if(grid[i].connected&&!grid[i].neighbour_counted&&grid_Cleared){
nodes_count++;
grid[i].neighbour_counted = true;
}
if(nodes_count===grid.length){
nodes_connected = true;
}
if(nodes_connected){
calculate_distance = true;
}
if(calculate_distance&&!nodes_array_Created){
generateNodes.toggle=1;
}
if(switches.toggle===1){
grid[i].draw(sides);
}
}
if(nodes_array_Created){
for(var i=0;i<nodesindex.length;i++){
if(!key_Node[i].travelling&&key_Node[i].stopped){
paths_evaluated ++;
}
}
}
if(paths_evaluated >= total_paths+nodesindex.length&&nodes_array_Created){
//gridbackup = grid;
paths_completed = true;
}
if(x_Padding.value&&x_Padding.toggle===1){
x_padding = x_Padding.value;
}
if(y_Padding.value&&y_Padding.toggle===1){
y_padding = y_Padding.value;
}
};
function restoreColor(a){
for(var i=0;i<a.length;i++){
a[i].pcol2 = gridbackup[a[i].original_id].pcol2
}
};
function updateStack(a,pathfinder){
var a = 0;
for(var i=a.length-1;i>-1;i--){
if(a<2){
a[i].parent_path = pathfinder.parent_path;
if(a[i].node){
a++;
}}
}
};
function trimpathStack(a,b){
for(var i=a.length-1;i>-1;i--){
var next = a[i].find(target);
var next1 = a[i].find2();
if(next){
a[i].pcol2 = color(0,0,0,150)
return;
}
else if(!next&&a.length>1&&a[i].depth!==b){
a[i].visited3 = true;
a[i].pcol2 = color(0,0,0,150);
a.splice(i,1);
}}
};
function djikstra(){
if(pathfind.toggle===1){
target.visited = true;
//target.walls = [false,false,false,false,false,false];
target.pcol = color(255,0,0);
target.fill();
for( var i=pathfinder.length-1;i>-1;i--){
pathbackup[0].pcol2 = color(0);
pathfinder[i].pcol2 = color(0,0,0,150);
stroke(0);
strokeWeight(1);
//line(pathfinder[i].x,pathfinder[i].y,target.x,target.y);
strokeWeight(0);
if(pathfinder[i]&&(pathfinder[i].y!==target.y||pathfinder[i].x!==target.x)&&!completed){
var next = pathfinder[i].find(target,false);
pathfinder[i].visited2 = true;
if(next){
next.pcol2 = color(0,0,0,150);
next.depth = pathfinder[i].depth;
pathfinder[i].highlight();
pathfinder[i].visited3 = false;
stack2[i].push(pathfinder[i]);
pathhist[i].push(next)
pathfinder[i] = next;
}
else if(stack2[i].length>0){
var next1 = pathfinder[i].find(target,false);
if(next1){
if(!pathfinder[i].visited3){
pathfinder[i].pcol2 = color(0,0,0,150);
}
else{
pathfinder[i].pcol2 = pathfinder[i].pcol;
}}
else {
pathfinder[i].visited3 = true;
pathfinder[i].pcol2 = color(0,0,0,0);
}
trimpathStack(stack2[i],1);
pathfinder[i] = stack2[i].pop();
}
}
else{
fill(255);
text("success",10,10);
pathfinder[i].completed = true;
completed = true;
}
if(pathfinder[i].completed){
}
if(completed&&!pathfinder[i].completed){
}
}}
};
function trimpathStack2(a){
for(var i=a.length-1;i>-1;i--){
var next;;
if(!a[i].node){
next = a[i].find2(target);
}
if(a[i].node){
next = a[i].nextNode(target,false);
}
if(next&&next!==target){
a[i].pcol2 = color(0,0,0,150)
return;
}
else if(!next&&a.length>1){
a[i].visited3 = true;
a[i].pcol2 = color(0,0,0,150);
a.splice(i,1);
}}
};
function mapPath2(){
if(pathfind2.toggle===1){
target.visited = true;
target.pcol = color(255,0,0);
target.fill();
for( var i=pathfinder.length-1;i>-1;i--){
pathbackup[0].pcol2 = color(0);
pathfinder[i].pcol2 = color(0,0,0,150);
stroke(0);
strokeWeight(1);
//line(pathfinder[i].x,pathfinder[i].y,target.x,target.y);
strokeWeight(0);
var next;
if(pathfinder[i]!==target&&!completed){
if(!pathfinder[i].node){
next = pathfinder[i].find(target,false,stack2[i]);
}
else if(pathfinder[i].node){
next = pathfinder[i].nextNode(target,true,stack2[i]);
}
pathfinder[i].visited2 = true;
if(next){
next.pcol2 = color(0,0,0,150);
next.depth = pathfinder[i].depth;
pathfinder[i].highlight();
pathfinder[i].visited3 = false;
stack2[i].push(pathfinder[i]);
pathhist[i].push(next)
pathfinder[i] = next;
}
else if(stack2[i].length>0){
var next1 = false;
if(!pathfinder[i].node){
next1 = pathfinder[i].find2(target,false);
}
else if(pathfinder[i].node){
next1 = pathfinder[i].nextNode(target,false);
}
if(next1){
if(!pathfinder[i].visited3){
pathfinder[i].pcol2 = color(0,0,0,150);
}
else{
pathfinder[i].pcol2 = pathfinder[i].pcol;
}}
else {
pathfinder[i].visited3 = true;
pathfinder[i].pcol2 = color(0,0,0,0);
}
trimpathStack2(stack2[i],99);
pathfinder[i] = stack2[i].pop();
}
}
else{
fill(255);
text("success",10,10);
pathfinder[i].completed = true;
//pathfinder[i].walls = wallbackup;
completed = true;
}
if(pathfinder[i].completed){
}
if(completed&&!pathfinder[i].completed){
}
}}
};
function super_path(){
if(pathfind3.toggle===1){
for(var i=nodestar.length-1;i>-1;i--){
var b = backupstar[i].original_id;
nodestar[i].imprinted_by[b] = true;
var next = nodestar[i].neighbourNode(true,b,backupstar[i]);
nodestar[i].highlight();
if(next){
next[1].node_to_node_dist[b] = nodestar[i].node_to_node_dist[b] + next[0];
backupstar[i].nodesconnected[next[1].original_id] = next[1].node_to_node_dist[b];
if(!nodestar[i].path_ref[b]){
nodestar[i].path_ref[b] = [nodestar[i]]
}
next[1].path_ref[b] = [nodestar[i].path_ref[b],next[1]];
next[1].path_ref[b] = next[1].path_ref[b].flat();
backupstar[i].pathtable[next[1].original_id] = [next[1].path_ref[b]];
stackstar[i].push(nodestar[i]);
trimStackStar(stackstar[i],b)
nodestar[i] = next[1];
}
else if(!next&&stackstar[i].length>0){
nodestar[i] = stackstar[i].pop();
}
else{
backupstar.splice(i,1);
nodestar.splice(i,1);
stackstar.splice(i,1);
//i += -1;
}
}}
};
function mapPath4(){
if(pathfind4.toggle===1){
target.visited = true;
//target.walls = [false,false,false,false,false,false];
target.pcol = color(255,0,0);
target.fill();
for( var i=pathfinder.length-1;i>-1;i--){
pathbackup[0].pcol2 = color(0);
pathfinder[i].pcol2 = color(0,0,0,150);
stroke(0);
strokeWeight(1);
//line(pathfinder[i].x,pathfinder[i].y,target.x,target.y);
strokeWeight(0);
if(pathfinder[i]&&(pathfinder[i].y!==target.y||pathfinder[i].x!==target.x)&&!completed){
var next = pathfinder[i].find(target,true,stack2[i]);
pathfinder[i].visited2 = true;
if(next){
next.pcol2 = color(0,0,0,150);
next.depth = pathfinder[i].depth;
pathfinder[i].highlight();
pathfinder[i].visited3 = false;
stack2[i].push(pathfinder[i]);
pathhist[i].push(next)
pathfinder[i] = next;
}
else if(stack2[i].length>0&&pathfinder[i].depth!==0){
var next1 = pathfinder[i].find(target,false);
if(next1){
if(!pathfinder[i].visited3){
// pathfinder[i].pcol2 = color(0,0,0,150);
}
else{
// pathfinder[i].pcol2 = pathfinder[i].pcol;
}}
else {
// pathfinder[i].visited3 = true;
// pathfinder[i].pcol2 = color(0,0,0,0);
}
trimpathStack(stack2[i]);
pathfinder[i] = stack2[i].pop();
}
}
else{
fill(255);
text("success",10,10);
pathfinder[i].completed = true;
completed = true;
}
if(pathfinder[i].completed){
}
if(completed&&!pathfinder[i].completed){
}
}}
};
function checktoggle (){
for(var i=0;i<sliders.length;i++){
if(sliders[i].toggle===1){
findnodes.toggle =0;
}
}
};
function findnode(){
if(nodes_array_Created&&!paths_completed&&pathfind2.toggle!==1&&pathfind.toggle!==1){
var counts = nodesindex.length;
fill(255)
//text("problem",50,10);
while(node_check<counts){
total_paths += nodesindex[node_check].neighbours.length;
node_check++;
}
for(var i=0;i<nodesindex.length;i++){
var b = key_Node[i].original_id;
nodesindex[i].connectedNodes[b] = true;
var next = nodesindex[i].neighbour_Node(b);
var steps_to_nodes = key_Node[i].steps_to_nodes;
find_node_count ++;
if(key_Node[i].nodes<key_Node[i].neighbours.length){
if(next){
nodesindex[i].highlight();
if(next.node){
next.connectedNodes[b]=true;
var a = nodesindex[i].parent[0]
var b = nodesindex[i].parent[1]
if((a&&b)&&(a==b)){
}
if(a === key_Node[i]){
var node_info = [];
for(var j=0;j<key_Node[i].node_info.length;j++){
if(!key_Node[i].node_info[j][0]&&node_info.length<1){
node_info = key_Node[i].node_info[j];
}}
if(node_info.length>0){
node_info[0] = steps_to_nodes;
node_info[1] = next;
}
}
else if(b === key_Node[i]){
var node_info = [];
for(var j=0;j<key_Node[i].node_info.length;j++){
if(!key_Node[i].node_info[j][0]&&node_info.length<1){
node_info = key_Node[i].node_info[j];
}}
if(node_info.length>0){
node_info[0] = steps_to_nodes;
node_info[1] = next;
}
}
if(nodesindex[i].node){
var node_info= [];
for(var j=0;j<next.node_info.length;j++){
if(!key_Node[i].node_info[j][0]&&node_info.length<1){
node_info = key_Node[i].node_info[j];
}}
if(node_info.length>0){
node_info[0] = steps_to_nodes;
node_info[1] = next;
}
}
key_Node[i].steps_to_nodes = 1;
nodesindex[i] = key_Node[i];
key_Node[i].nodes ++;
//paths_evaluated ++;
}
else{
key_Node[i].steps_to_nodes ++;
if(!next.node_info[0][1] ){
next.node_info[0][0] = steps_to_nodes;
next.node_info[0][1] = key_Node[i];
}
else{
next.node_info[1][0] = steps_to_nodes;
next.node_info[1][1] = key_Node[i];
}
key_Node[i].child.push([steps_to_nodes,next]);
nodesindex[i] = next;
}
}
else {
nodesindex[i] = key_Node[i];
paths_evaluated++;
if(count>0){
key_Node[i].steps_to_nodes = 1;
}}}}}
};
var count;
function shortestPath(a,b){
var starting_Node ;
var finishing_Node
if(!a.node){
if(a.connections[0]<a.connections[1]){
starting_Node = a.connections[0];
}
else{
starting_Node = a.connections[1];
}}
if(!b.node){
if(b.connections[0]<b.connections[1]){
finishing_Node = b.connections[0];
}
else{
finishing_Node = b.connections[1];
}}
for(var i=0;i<nodesindex.length;i++){
}
};
function checkToggles(){
for(var i=0;i<sliders.length;i++){
if(sliders[i].toggle===1)
return true;
}
}
function draw(){
checktoggle();
push();
translate(xmap,ymap)
background(51);
setups();
turns();
findnode();
cellNeighbours();
djikstra();
mapPath2();
super_path();
mapPath4();
pop();
//----------------------------------------
minimize.draw3();
hideMenu();
game.draw();
start.draw();
paths.draw();
reset.draw();
pathfind.draw();
pathfind2.draw();
pathfind3.draw();
pathfind4.draw();
pathreset.draw2();
// generateNodes.draw();
//resetNode.draw2();
//findnodes.draw();
switches.draw();
if(!mousedown){
reset.mouseClick2();
pathreset.mouseClick2();
generateNodes.mouseClick2();
menudrag.mouseClick2();
}
menu.mouseClick3();
//sliderPlayers.draw4();
menudrag.draw3();
//sliderPlayers.buttonClick();
if(!mousedown){
menudrag.mouseClick5();
}
//length.draw4();
for(var i=0;i<sliders.length;i++){
sliders[i].draw4();
//if(!mousedown){
sliders[i].slide();
sliders[i].buttonClick();
//}
}
for(var i=0;i<buttons.length;i++){
if(!mousedown){
buttons[i].hover();
}
}
};
function mouseClicked(){
if(game.toggle===1||paths.toggle===1){
for(var i=0;i<grid.length;i++){
grid[i].toggle();
}}
};
function mouseOver(){
};
function mouseIsPressed(){
};
function mouseReleased(){
mousedown = false;
rest_toggle = false;
for(var i=0;i<sliders.length;i++){
sliders[i].toggle = 0;
}
};
function mouseDragged(){
if(mousedown&&(menudrag.toggle!==1&&slidersdrag.toggle!==1)&&!checkToggles()){
xmap += mouseX-pmouseX;
ymap += mouseY-pmouseY;
}
if(menudrag.toggle===1){
mousedown = true;
xx = mouseX-menuxy[0]-190/2;
yy = mouseY-menuxy[1];
}
if(slidersdrag.toggle===1){
mousedown = true;
xx = mouseX-menuxy[0]-190/2;
yy = mouseY-menuxy[1];
}
};
function mousePressed(){
if(!menu.checkmpos()){
mousedown = true;
}
game.mouseClick();
start.mouseClick();
paths.mouseClick();
findnodes.mouseClick();
pathfind.mouseClick();
pathfind2.mouseClick();
pathfind3.mouseClick();
pathfind4.mouseClick();
//resetNode.mouseClick();
switches.mouseClick();
minimize.mouseClick4();
slidersminimize.mouseClick4();
//menudrag.mouseClick5();
for(var i=0;i<sliders.length;i++){
//sliders[i].buttonClick();
}
if(!mousedown){
reset.mouseClick2();
pathreset.mouseClick2();
generateNodes.mouseClick2();
}
};