Code viewer for Mind: Complex Mind (clone by Kri...

// Cloned by Krithika Sharon on 29 Nov 2020 from Mind "Complex Mind" by Starter user 
// Please leave this clone trail here.
 



// =================================================================================================
// Sample Mind for more complex starter World  
// =================================================================================================

// World tells us agent position and enemy position
// World does not tell us of existence of walls
// if return invalid move (not empty square) World just ignores it and we miss a turn 


 

	AB.mind.getAction = function ( x )		// x is an array of [ ai, aj, ei, ej ]
	{ 
		var ai = x[0];
		var aj = x[1];
		var ei = x[2];
		var ej = x[3];

/*
 var f = [];   //An array to store all the possible paths the enemy can take 
 var fmin = 0;
 var i,j;
 var min_1 = 0,min_2 = 0,min_3 = 0;
 var sum = true;
 
 if(ei < ai) {          
     
                               
         min_1 = (Math.abs((ei+1) - ai) + Math.abs(ej-aj));
         f.push(min_1);
                                    
         min_2 = (Math.abs(ei - ai) + Math.abs((ej+1) - aj));
         f.push(min_2);
   
         min_3 = (Math.abs(ei-ai) + Math.abs((ej-1) - ai));
         f.push(min_3);
    
    
    fmin =  Math.min.apply(Math,f);           //finding the minimum value in f
   console.log("f",f);
   console.log("fmin",fmin);
    
    if(fmin == min_1) {                     //returning the value if first 
     i = ei+1;
     j = ej;
     sum = false;
    }
    else if(fmin == min_2 && sum === true ) {
     i = ei;
     j = ej+1;
    }
    else if(fmin == min_3) {
     i = ei;
     j = ej-1;
    }
    
    if(!occupied(i,j)) {
        ei = i;
        ej = j;
    }
    
 }
 
 if(ei > ai) {
                             
         min_1 = (Math.abs((ei-1) - ai) + Math.abs(ej-aj));
         f.push(min_1);
     
    
         min_2 = (Math.abs(ei - ai) + Math.abs((ej+1)-aj));
          f.push(min_2);
                                        
         min_3= (Math.abs(ei-ai) + Math.abs((ej-1) - ai));
             f.push(min_3);
      
     fmin =  Math.min.apply(Math,f);  //finding the minimum value in f
     console.log("f",f);
   console.log("fmin",fmin);
    
    if(fmin == min_1) {
     i = ei-1;
     j = ej;
      sum = false;
    }
    else if(fmin == min_2 &&  sum === true) {
     i = ei;
     j = ej+1;
    }
  
    else if(fmin == min_3) {
     i = ei;
     j = ej-1;
    }
    
     
    if(!occupied(i,j)) {
        ei = i;
        ej = j;
    }
    
    
 }
 
    
    if(ej < aj) {
        
        
                                           
         min_1 = (Math.abs((ei+1) - ai) + Math.abs(ej-aj));
         f.push(min_1);
    
     
         min_2= (Math.abs((ei-1) - ai) + Math.abs(ej-aj));
         f.push(min_2);
     
     
         min_3 = (Math.abs(ei - ai) + Math.abs((ej+1) - aj));
         f.push(min_3);
     
    
    
      fmin =  Math.min.apply(Math,f);           //finding the minimum value in f
     console.log("f",f);
   console.log("fmin",fmin);
    
    if(fmin == min_1) {
     i = ei+1;
     j = ej;
      sum = false;
    }
    else if(fmin == min_2 &&  sum === true) {
     i = ei-1;
     j = ej;
    }
    else if(fmin == min_3) {
     i = ei;
     j = ej+1;
    }
   
    
    if(!occupied(i,j)) {
        ei = i;
        ej = j;
    }
    
    }     
  
  
    if(ej > aj) {
        
    
         min_1 = (Math.abs((ei+1) - ai) + Math.abs(ej-aj));
         f.push(min_1);
     
    
         min_2 = (Math.abs((ei-1) - ai) + Math.abs(ej-aj));
         f.push(min_2);
      
    
         min_3 = (Math.abs(ei-ai) + Math.abs((ej-1) - ai));
         f.push(min_3);
        
     fmin =  Math.min.apply(Math,f);           //finding the minimum value in f
     console.log("f",f);
   console.log("fmin",fmin);
    
    if(fmin == min_1) {
     i = ei+1;
     j = ej;
      sum = false;
    }
    else if(fmin == min_2 &&  sum === true) {
     i = ei-1;
     j = ej;
    }
    else if(fmin == min_3) {
     i = ei;
     j = ej-1;
    }
     
    if(!occupied(i,j)) {
        ei = i;
        ej = j;
    }
       
    

}
*/
	};