Code viewer for Mind: sheepdog3mind(Submission) ...

// Cloned by Aaron Crawford on 13 Nov 2022 from Mind "sheepdog3mind(Submission)" by Neil Geoghegan 
// Please leave this clone trail here.
 














/*
====== ====== ======
  1     2/pen   3
====== ====== ======
  4      5      6
====== ====== ======
  7      8      9
====== ====== ======
The dog/mind will use the zones to determine where to move

if the dog is in a different zone to the sheep it will go find it

once in the same zone the dog will try to push the sheep into another zone
the goal is to push the sheep into the middle so they can then be pushed into
the pen






*/


function randomPick ( a, b )
{
 if ( randomBoolean() )
  return a;
 else
  return b;
}
/*uses location of the enemy and agent

*/
function agentGetAction(agenti, agentj, enemyi ,enemyj){
  if( (zone(agenti,agentj) == zone(enemyi,enemyj)) && (zone(enemyi,enemyj) == 1) ){

    if( (agentj >= enemyj) && (agenti != enemyi)){
      return ( ACTION_UP)
    }
    if( (agentj < enemyj) && (agenti > enemyi)){
      return ( ACTION_LEFT)
    }
    if( (agentj < enemyj) && (agenti < enemyi)){
      return ( ACTION_RIGHT)
    }
    if( (agentj < enemyj) && (agenti == enemyi)){
      return ( ACTION_DOWN)
    }
    if( (agentj > enemyj) && (agenti == enemyi)){
      return randomPick(ACTION_LEFT, ACTION_RIGHT)
    }
  }
  //zone2
  if( (zone(agenti,agentj) == zone(enemyi,enemyj)) && (zone(enemyi,enemyj) == 2) ){

  }
  //zone3
  if( (zone(agenti,agentj) == zone(enemyi,enemyj)) && (zone(enemyi,enemyj) == 3) ){
    if( (agentj >= enemyj) && (agenti != enemyi)){
      return ( ACTION_UP)
    }
    if( (agentj < enemyj) && (agenti > enemyi)){
      return ( ACTION_LEFT)
    }
    if( (agentj < enemyj) && (agenti < enemyi)){
      return ( ACTION_RIGHT)
    }
    if( (agentj < enemyj) && (agenti == enemyi)){
      return ( ACTION_DOWN)
    }
    if( (agentj > enemyj) && (agenti == enemyi)){
      return randomPick(ACTION_LEFT, ACTION_RIGHT)
    }
  }
  //zone4
  if( (zone(agenti,agentj) == zone(enemyi,enemyj) ) && (zone(enemyi,enemyj) == 4) ){
    if( (agenti >= enemyi) && (agentj != enemyj)){
      return ( ACTION_LEFT)
    }
    if( (agenti < enemyi) && (agentj > enemyj)){
      return ( ACTION_UP)
    }
    if( (agenti < enemyi) && (agentj < enemyj)){
      return ( ACTION_DOWN)
    }
    if( (agenti < enemyi) && (agentj == enemyj)){
      return ( ACTION_RIGHT)
    }
    if( (agenti > enemyi) && (agenti == enemyi)){
      return randomPick(ACTION_LEFT)
    }
  }
  //zone5
  if( (zone(agenti,agentj) == zone(enemyi,enemyj)) && (zone(enemyi,enemyj) == 5) ){
    if((agenti == enemyi) && (agentj < enemyj)){
      return randomPick(ACTION_LEFT,ACTION_RIGHT)
    }
  }
  //zone6
  if( (zone(agenti,agentj) == zone(enemyi,enemyj)) && (zone(enemyi,enemyj) == 6) ){

    if( (agenti <= enemyi) && (agentj != enemyj)){
      return ( ACTION_RIGHT)
    }
    if( (agenti > enemyi) && (agentj < enemyj)){
      return ( ACTION_DOWN)
    }
    if( (agenti > enemyi) && (agentj > enemyj)){
      return ( ACTION_UP)
    }
    if( (agenti > enemyi) && (agentj == enemyj)){
      return ( ACTION_LEFT)
    }
    if( (agentj > enemyj) && (agenti == enemyi)){
      return randomPick(ACTION_UP,ACTION_DOWN)
    }

  }
  //zone7
  if( (zone(agenti,agentj) == zone(enemyi,enemyj)) && (zone(enemyi,enemyj) == 7) ){
    if( (agenti > enemyi) && (agenti != enemyi)){
      return ( ACTION_LEFT)
    }
    if( (agenti < enemyi) && (agentj > enemyj)){
      return ( ACTION_UP)
    }
    if( (agenti < enemyi) && (agentj < enemyj)){
      return ( ACTION_DOWN)
    }
    if( (agenti < enemyi) && (agentj == enemyj)){
      return ( ACTION_RIGHT)
    }
    if( (agentj == enemyj) && (agenti > enemyi)){
      return randomPick(ACTION_UP, ACTION_DOWN)
    }
  }
  //zone8
  if( (zone(agenti,agentj) == zone(enemyi,enemyj)) && (zone(enemyi,enemyj) == 8) ){
    if((agenti == enemyi) && (agentj < agentj)){
      return randomPick(ACTION_LEFT,ACTION_RIGHT)
    }
  }
  //zone9
  if( (zone(agenti,agentj) == zone(enemyi,enemyj)) && (zone(enemyi,enemyj) == 9) ){
    if( (agenti <= enemyi) && (agentj != enemyj)){
      return ( ACTION_RIGHT)
    }
    if( (agenti > enemyi) && (agentj < enemyj)){
      return ( ACTION_DOWN)
    }
    if( (agenti > enemyi) && (agentj > enemyj)){
      return ( ACTION_UP)
    }
    if( (agenti > enemyi) && (agentj == enemyj)){
      return ( ACTION_LEFT)
    }
    if( (agentj < enemyj) && (agenti == enemyi)){
      return randomPick(ACTION_UP, ACTION_DOWN)
    }
  }
  //if not in same zone, dog will search for sheep
  if ( agentj <= enemyj ) 	return ( ACTION_DOWN)
  if ( (agentj > enemyj) && (agenti < enemyi) ) 	return ( ACTION_RIGHT)
  if ( (agentj > enemyj) && (agenti > enemyi) ) 	return ( ACTION_LEFT)
  if ( (agentj > enemyj) && (agenti = enemyi) ) 	return ( ACTION_UP)
  if ( (agentj < enemyj) && (agenti = enemyi) ) 	return (randomPick(ACTION_LEFT,ACTION_RIGHT))

}


function zone(i,j){
  if( (i => 1) && (i <= 6) && (j => 1) && (j <= 6 ) ) return 1
	if( (i > 6) && (i <= 12) && (j => 1) && (j <= 6 ) ) return 2
	if( (i > 12) && (i <= 18) && (j => 1) && (j <= 6 ) ) return 3

	if( (i => 1) && (i <= 7) && (j > 6) && (j <= 12 ) ) return 4
	if( (i > 7) && (i <= 11) && (j > 6) && (j <= 12 ) ) return 5
	if( (i >= 12) && (i <= 18) &&(j > 6) && (j <= 12 ) ) return 6

	if( (i => 1) && (i <= 7) && (j > 12) && (j <= 18 ) ) return 7
	if( (i > 7) && (i <= 11) && (j > 12) && (j <= 18 ) ) return 8
	if( (i >= 12) && (i <= 18) &&(j > 12) && (j <= 18 ) ) return 9
}



function Mind() {

  var ignoreEnemy1 = false;
  var ignoreEnemy2 = false;
  var ignoreEnemy3 = false;
  //dog knows if a sheep has been put in the pen


//--- public functions / interface / API ----------------------------------------------------------


	this.newRun = function()
	{
	};

	this.endRun = function()
	{
	};



	this.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 e2i = x[4];
    var e2j = x[5];

    var e3i = x[6];
    var e3j = x[7];



        //System.log("Enemy in zone " + zone(ei, ej));

  //looks for sheep in order 1,2,3
  //improvement would be to look for nearset sheep
		if(ignoreEnemy1 == false){
      if(zone(ei,ej) == 2){
        ignoreEnemy1 = true;
      }
      return agentGetAction(ai,aj,ei,ej)
    }
    else if(ignoreEnemy2 == false){
      if(zone(e2i,e2j) == 2){
        ignoreEnemy2 = true;
      }
      return agentGetAction(ai,aj,e2i,e2j)
    }
    else if(ignoreEnemy3 == false){
      if(zone(e3i,e3j) == 2){
        ignoreEnemy3 = true;
      }
      return agentGetAction(ai,aj,e3i,e3j)
    }
    else{
      return (ACTION_DOWN)
    }
	};



}