Code viewer for World: A* Boot Strap - Scratch X0...
// Cloned by Venkatraman Palani on 5 Nov 2023 from World "A* Boot Strap - Scratch X0" by Venkatraman Palani 
// Please leave this clone trail here.
 
//A* BootStraper - Scratch X0
//Venkatraman Palani

//CA 686: FX of AI
//Practicum 1;

var cols=5;
var rows=5;
var grid=new Array(cols);
//searchSpace

var oSet=[];
//openSet
var cSet=[];
//closedSet
var s;
var e;
var c;
//start, end & current;

var w,h;
//canvas width & height

//var u,v,w=0;
//initial state of grid node 'n' f(n)=g(n)+h(n)

function node(i,j){
    this.x=i;
    this.y=j;
    /*this.f=u;
    this.g=v;
    this.h=w;*/
    this.f;this.g;this.h;
    
    /*if(this.x>s.x){
        this.nx=node(i-1,j);
    }
    if(this.y>s.y){
        this.nx=node(i,j-1);
    }
    if(this.x<e.x){
        this.nx=node(i+1,j);
    }
    if(this.x<e.y){
        this.nx=node(i,j+1);
    }*/
    
    this.show=function(r0,g0,b0){
        //fill(255);
        //stroke(0);
        //rect((this.x*w)+1,(this.y*h)+1,w-1,h-1);
        fill(r0,g0,b0);
        rect(this.x*w,this.y*h,w-5,h-5);
        //rect(0,0,w,h)
    }
    //debug trace x
}
//grid node & node objects

function setup(){
    createCanvas(700,700);
    console.log('A*');
    //initialize canvas & log header
    
    w=width/cols;
    h=height/rows;
    //node pixel density (w*h) across canvas per unit grid
    
    for(var i=0; i<cols; i++){
        grid[i]=new Array(rows);
    }
    //create 2D array
    
    for(var i=0; i<cols; i++){
        for(var j=0; j<rows; j++){
            grid[i][j]=new node(i,j);
        }
    }
    console.log(grid);
    //initialize grid indexes with node objects; grid log.
    
    s=grid[0][0];
    s.f,s.g,s.h=0;
    e=grid[cols-1][rows-1];
    //searchSpace** start at grid node = top left & end at grid node = bottom right; **Note: can be randomized.
    
    oSet.push(s);
    console.log(oSet);
    //openSet loaded with start grid node; log track.
}

function draw(){
    background(255,0,0);
    //indefinite animate loop (equivalent/~= while 1) & static background
    
/*    if(oSet.length>0){
        //traverse further if openSet is not empty***; - ***comment revision required
        for(i>0; i<oSet.length; i++){
            if(oSet[i].f<oSet[x]){}
            
        }
    }else{
        //end traversal
    } */
    
    /*if(oSet.lenght>0){
        
    }else{
        if(c.x==e.x && c.y==e.y){
            console.log('Solution/ Path Found: ');
            console.log(c.f);
        }else{
            console.log('No Optimal Path exist!');
        }
        //noLoop();
    }*/
    
    for(i=0; i<cols; i++){
        for(j=0; j<rows; j++){
            grid[i][j].show(255,255,0);
        }
    }
    //debug trace 0 - grid nodes
    
    for(i=0; i<cols; i++){
        for(j=0; j<rows; j++){
            oSet[i].show(0,255,0);
        }
    }
    //debug trace 1 - openSet nodes
    
    for(i=0; i<cols; i++){
        for(j=0; j<rows; j++){
            cSet[i].show(255,0,0);
        }
    }
    //debug trace 2 - closedSet nodes
}