// javascript:
// -----------------------------------------------------------------------
// Copyright 1999 Manuel de la Herrán Gascón
// mherran@aircenter.net Madrid (Spain).
// http://www.aircenter.net/gaia
// -----------------------------------------------------------------------
// Este código han sido creado originariamente por Manuel de la Herrán Gascón
// -----------------------------------------------------------------------
// Otras contribuciones / Contributed by
// (Tu nombre aquí / Your name here)
// -----------------------------------------------------------------------
// DO NOT REMOVE THIS COPYRIGHT LINES!
// You can copy and paste this code in your own web pages, if you keep this lines.
// You can modify, distribute and sell this code, but keep the copyright lines
// and add your name in "Contributed by". If you are interested in just some 
// special procedures, copy them, and you don't have to keep this lines.
// NO QUITAR ESTAS LINEAS DE COPYRIGHT!
// Puedes copiar y pegar este código en tus propias páginas web, pero manten estas lineas.
// Puedes modificar, distribuir y vender este código, manteniendo las lineas de
// copyright e incluyendo tu nombre en "Otras contribuciones". Si sólo estás
// interesando en unas rutinas, copialas y no hace falta que mantengas estas lineas.
// -----------------------------------------------------------------------
// This program is provided "as is" without any express or implied warranties.
// The author assumes no responsibility for errors, omissions or damages
// resulting from the use of it.
// Este programa se distribuye tal cual, si ninguna garantía implícita o explícita
// El autor no asume ninguna responsabilidad por errores, omisiones o daños
// provocados por su uso
// -----------------------------------------------------------------------
// GENERAL FUNCTIONS======================================================
// randDistContUnif01
// randDistDiscUnif1Ub1
// sumCirc2
// dist2ptos2d
// calculateNewRowLocation8D
// calculateNewColLocation8D
// 
// -----------------------------------------------------------------------

  // --------------------------------------------------------------
  function randDistContUnif01() {
  //Devuelve un valor entre cero (incusive) y uno (exclusive) (esto esta por confirmar)
  //La probabilidad es igual para todos los números
    return Math.random();
  }
  // --------------------------------------------------------------
  function randDistDiscUnif1Ub1(Ub) {
  //Devuleve un número al azar entero
  //entre 1 y fin, inclusive ambos
  //La probabilidad es igual para todos los números
      return Math.ceil(Ub*randDistContUnif01());
  }
  // --------------------------------------------------------------
  function sumCirc2(maximo,val1,val2) {
    var ret=val1+val2;
    if (ret < 0) ret = ret + maximo;
    ret=ret % maximo;
    if (ret == 0) ret=maximo;
    if (ret > maximo) alert('Error');
    if (ret <= 0) alert('Error');
    return ret;
  }
  // --------------------------------------------------------------
  function sumCirc6(maximo,v1,v2,v3,v4,v5,v6) {
    var ret=0;
    ret=(v1+v2+v3+v4+v5+v6) % maximo;
    if (ret == 0) ret=maximo;
    if (ret > maximo) alert('Error');
    if (ret <= 0) alert('Error');
    return ret;
  }
  // --------------------------------------------------------------
  function sumCirc12(maximo,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12) {
    var ret=0;
    ret=(v1+v2+v3+v4+v5+v6+v7+v8+v9+v10+v11+v12) % maximo;
    if (ret == 0) ret=maximo;
    if (ret > maximo) alert('Error');
    if (ret <= 0) alert('Error');
    return ret;
  }
  // --------------------------------------------------------------
  function dist2ptos2d(ax,ay,bx,by) {
    return Math.sqrt(Math.pow(ax-bx,2)+Math.pow(ay-by,2));
  }
  // --------------------------------------------------------------
  function calculateNewRowLocation8D(currentCellD,currentCellR,totalRows) {
    switch (currentCellD){
       case 1 : // Norte
         return sumCirc2(totalRows,currentCellR,-1);
         break;
       case 2 : // NorEste
         return sumCirc2(totalRows,currentCellR,-1);
         break;
       case 3 : // Este
         return currentCellR;
         break;
       case 4 : // SurEste
         return sumCirc2(totalRows,currentCellR,1);
         break;
       case 5 : // Sur
         return sumCirc2(totalRows,currentCellR,1);
         break;
       case 6 : // SurOeste
         return sumCirc2(totalRows,currentCellR,1);
         break;
       case 7 : // Oeste
         return currentCellR;
         break;
       case 8 : // NorOeste
         return sumCirc2(totalRows,currentCellR,-1);
         break;
       default : 
         return -1;
         alert('ERRORS CONTROL: Error'); 
       }
  }
  // --------------------------------------------------------------
  function calculateNewColLocation8D(currentCellD,currentCellC,totalCols) {
    switch (currentCellD){
       case 1 : // Norte
         return currentCellC;
         break;
       case 2 : // NorEste
         return sumCirc2(totalCols,currentCellC,1);
         break;
       case 3 : // Este
         return sumCirc2(totalCols,currentCellC,1);
         break;
       case 4 : // SurEste
         return sumCirc2(totalCols,currentCellC,1);
         break;
       case 5 : // Sur
         return currentCellC;
         break;
       case 6 : // SurOeste
         return sumCirc2(totalCols,currentCellC,-1);
         break;
       case 7 : // Oeste
         return sumCirc2(totalCols,currentCellC,-1);
         break;
       case 8 : // NorOeste
         return sumCirc2(totalCols,currentCellC,-1);
         break;
       default : 
         return -1;
         alert('ERRORS CONTROL: Error'); 
       }
  }

