// Interactive Goopers Game 2.0.7
// Copyright 1999
// Andrew Coates ((Andrew@caltrop.claremont.ca.us) && Eric Gerdes (gerdes@uwyo.edu)
// DO not seal code !!!!
/////////////////////////////////////////////////////////////////////////////////////////////
//                                                                        Version 2.0.7
/////////////////////////////////////////////////////////////////////////////////////////////
// functions:
/////////////////////////////////////////////////////////////////////////////////////////////
// aquirelevel(selindex,isdefense) 
// changeeyeball(ro,co,withwhat) 
// changeplayer(towho) 
// changesettings() 
// closemessagewindow();
// closeoptions(reset); 
// computermove() 
// computerslide() 
// floathelp()
// getholes(found)
// goodendmove(chkrow,chkcol) 
// goodstartmove(chkrow,chkcol)
// goodsettings() 
// hideall() 
// hide(hideobj)
// init()
// hole_between(first_r, first_c, second_r, second_c)
// iscomputermove(who)
// isstuck(who) 
// layerWrite(id,nestref,text)
// maydisable(obj);
// messagewindow(message)
// mouseDown(e)
// mouseMove(e)
// mouseUp(e)
// movearrowto(x,y)
// movegooper(); 
// openoptions()  
// reload();
// replaceeyes(row,col)
// randomnumber (between)
// setupblock(obj,angle)
// show(showobj)
// showscore()  
// startover()

/////////////////////////////////////////////////////////////////////////////////////////////
// Globals:   (last updated: 2-02-99)
/////////////////////////////////////////////////////////////////////////////////////////////

n = (document.layers) ? true:false
ie = (document.all) ? true:false
readyformouse = false;
paused = false;

if ( (n == false) && (ie == false) ){
    alert("sorry you must have a css and dynamic html browser to view this site (Netscape 4.0+ IE 4.0+)... bye");
    //history.go(-1);
}

   helpreg = new Image
   helphigh = new Image
   optionsreg = new Image
   optionshigh = new Image
   homereg = new Image
   homehigh = new Image
   topslash = new Image
   tophome = new Image
   topoptions = new Image
   tophelp = new Image

   helpreg.src = 'qq.gif'
   helphigh.src = 'h_qq.gif'
   optionsreg.src = 'oh.gif'
   optionshigh.src = 'h_oh.gif'
   homereg.src = 'home.gif'
   homehigh.src = 'h_home.gif'
   topslash.src = 'slash.jpeg'
   tophome.src = 'home.jpeg'
   topoptions.src = 'options.jpeg'
   tophelp.src = 'help.jpeg'

var compthink = 100; 
var replacetime = 500;  // Timeout times.
var timebetween = 100;
var windowpop = 4500

var gameover = 0;   
var goopercount = 0;   // used for mousedown

var lastx = 0; 
var lasty = 0;
var comptox = 0;    // globals for move // need to be global for setTimeout!
var comptoy = 0;

var totalgreen = 0;
var totalred = 0;
var totalyellow = 0;    // total score
var totalmagenta = 0;

var redscore = 1;
var greenscore = 1;     // current score
var yellowscore = 1;
var magentascore = 1;

var showred = 0;
var showgreen = 0;      // flags that are = 1 when the alert for gooper can not move has 
var showmagenta = 0;    // been shown
var showyellow = 0;

var red = 4;      // numbers represent playing order of game 1 goes first 2 goes next...
var green = 1;    // -1 means not playing
var yellow = 2;    
var magenta = 3; 
var hole = 5;

var players = 4;
var numberofholes = 5;
var moved; // mouse down
var closed = false;  // popup window

var computerred = red;    // players that are run my the computer are positive 
var computergreen = -1;   // numbers here negative numbers means the computer is not playing 
var computeryellow = yellow;
var computermagenta = magenta;

// aggression is how much the computer values the other players goopers
// defence is how much it values its own goopers
var redaggression = 0.8;
var reddefence = 0.5;
var greenaggression = 0.9;
var greendefence = 0.5;
var yellowaggression = 1;
var yellowdefence = 0.5;
var magentaaggression = 1.2;
var magentadefence = 0.5;

var theboard  = new Array(7);
for (i=0; i <7; i++){ theboard[i]=new Array(7); }

var theboardsave  = new Array(7);    // used for when i show options
for (i=0; i <7; i++){ theboardsave[i]=new Array(7); }

var slidex = 0;
var slidey = 0;
var t_slidex = 0;
var t_slidey = 0;
var countslide = 0;

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: aquire level
 // def : 
 // last modified: 1-18-99

function aquirelevel(selindex,isdefense){
  if ( isdefense == 0){
     if (selindex == 0) { return 0.01 }
	 if (selindex == 1) { return 0.2 }
     if (selindex == 2) { return 0.4 }
     if (selindex == 3) { return 0.6 }
     if (selindex == 4) { return 0.8 }
     if (selindex == 5) { return 1.0 }
     if (selindex == 6) { return 1.2 }
     if (selindex == 7) { return 1.4 }
     if (selindex == 8) { return 1.6 }
     if (selindex == 9) { return 1.8 }
     if (selindex == 10) { return 2.0 }
	 if (selindex == 11) { return 2.2 }
  } else {
     if (selindex == 0) { return 2.2 }
     if (selindex == 1) { return 2.0 }
	 if (selindex == 2) { return 1.8 }
     if (selindex == 3) { return 1.6 }
     if (selindex == 4) { return 1.4 }
     if (selindex == 5) { return 1.2 }
     if (selindex == 6) { return 1.0 }
     if (selindex == 7) { return 0.8 }
     if (selindex == 8) { return 0.6 }
     if (selindex == 9) { return 0.4 }
     if (selindex == 10) { return 0.2 }
     if (selindex == 11) { return 0.01 }
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: changeeyeball
 // def : replace a space with a new eyeball 
 // last modified: 1-27-99 // added index for z-index

function changeeyeball(ro,co,withwhat){  
		  // delete what is there 
		  eval('destroyLayer("row'+ro+'col'+co+'Div") ');
          eval('delete '+'row'+ro+'col'+co); 

		  index = ((ro * 7) + co) + 9;
		  // place new eyeball
	      if (withwhat == green){ 
        	   createLayer('row'+ro+'col'+co+'Div',null,(157+(45*co)),(49+(41.5*ro)),36,36,'<IMG SRC="greeneye.gif" WIDTH=36 HEIGHT=36>','visible',index);
	           eval('row'+ro+'col'+co+' = new DynLayer("row'+ro+'col'+co+'Div")');
			   theboard[ro][co] = green;
			    }
	      if (withwhat == red) { 
        	   createLayer('row'+ro+'col'+co+'Div',null,(157+(45*co)),(49+(41.5*ro)),36,36,'<IMG SRC="redeye.gif" WIDTH=36 HEIGHT=36>','visible',index);
	           eval('row'+ro+'col'+co+' = new DynLayer("row'+ro+'col'+co+'Div")');
			   theboard[ro][co] = red;
			    }
	      if (withwhat == yellow) { 
        	   createLayer('row'+ro+'col'+co+'Div',null,(157+(45*co)),(49+(41.5*ro)),36,36,'<IMG SRC="yelloweye.gif" WIDTH=36 HEIGHT=36>','visible',index);
	           eval('row'+ro+'col'+co+' = new DynLayer("row'+ro+'col'+co+'Div")');
			   theboard[ro][co] = yellow;
			    }
	      if (withwhat == magenta) { 
        	   createLayer('row'+ro+'col'+co+'Div',null,(157+(45*co)),(49+(41.5*ro)),36,36,'<IMG SRC="magentaeye.gif" WIDTH=36 HEIGHT=36>','visible',index);
	           eval('row'+ro+'col'+co+' = new DynLayer("row'+ro+'col'+co+'Div")');
			   theboard[ro][co] = magenta;
			    }
		  if (withwhat == hole) { 
        	   createLayer('row'+ro+'col'+co+'Div',null,(157+(45*co)),(49+(41.5*ro)),36,36,'<IMG SRC="hole.gif" WIDTH=36 HEIGHT=36>','visible',index);
	           eval('row'+ro+'col'+co+' = new DynLayer("row'+ro+'col'+co+'Div")');
			   theboard[ro][co] = hole;
			    }
	      if (withwhat == 0) { 
        	   createLayer('row'+ro+'col'+co+'Div',null,(157+(45*co)),(49+(41.5*ro)),36,36,'<IMG SRC="blank.gif" WIDTH=36 HEIGHT=36>','visible',index);
	           eval('row'+ro+'col'+co+' = new DynLayer("row'+ro+'col'+co+'Div")');
			   theboard[ro][co] = 0;
			    }
}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: changeplayer
 // def : 
 // last modified: late late 1-23-99 

function changeplayer(towho){
moved = false;
var changeagain = 0;
  if (gameover == 0) {
   if (towho > players) { towho = 1; }
   if (isstuck(towho) == false){
    if (towho == green) { if (greenscore != 0) { currentplayer = green; movearrowto(473,67);} else {changeagain = 1;} }
    if (towho == red) {  if (redscore != 0) { currentplayer = red; movearrowto(533,67);} else {changeagain = 1;} }
    if (towho == magenta) {  if (magentascore != 0) { currentplayer = magenta; movearrowto(533,110);} else {changeagain = 1;} }
    if (towho == yellow) {  if (yellowscore != 0) { currentplayer = yellow;  movearrowto(473,110);} else {changeagain = 1;} }
    if ( (gameover == 0 ) && (changeagain == 0) && (iscomputermove(towho) == true) ) { setTimeout('computermove()',compthink); }
	if ( (changeagain == 1) && (gameover == 0) ) { changeplayer(towho+1); }
	}}
}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: change settings
 // def : change options vars
 // last modified: noon 1-24-99 

function changesettings(){
     green = document.myoptions.ordergreen.selectedIndex;
	 red = document.myoptions.orderred.selectedIndex;
	 yellow = document.myoptions.orderyellow.selectedIndex;
	 magenta = document.myoptions.ordermagenta.selectedIndex;
	 if (green == 0) green--;
	 if (yellow == 0) yellow--;
	 if (magenta == 0) magenta--;
	 if (red == 0) red--;
     if (document.myoptions.playinggreen.selectedIndex == 1) { computergreen = green;}
	 if (document.myoptions.playinggreen.selectedIndex == 2) { computergreen = -1;}
	 if (document.myoptions.playinggreen.selectedIndex == 0) { computergreen = -1; green=-1}
	 if (document.myoptions.playingred.selectedIndex == 1) { computerred = red; }
	 if (document.myoptions.playingred.selectedIndex == 2) { computerred = -1; }
	 if (document.myoptions.playingred.selectedIndex == 0) { computerred = -1; red=-1;}
	 if (document.myoptions.playingyellow.selectedIndex == 1) {computeryellow = yellow; }
	 if (document.myoptions.playingyellow.selectedIndex == 2) {computeryellow = -1;   }
	 if (document.myoptions.playingyellow.selectedIndex == 0) { computeryellow = -1;yellow=-1;}
	 if (document.myoptions.playingmagenta.selectedIndex == 1) {computermagenta = magenta; }
	 if (document.myoptions.playingmagenta.selectedIndex == 2) {computermagenta = -1; }
	 if (document.myoptions.playingmagenta.selectedIndex == 0) {computermagenta = -1; magenta=-1}
	 numberofholes = document.myoptions.numholes.selectedIndex;
	 greenaggression = aquirelevel(document.myoptions.modegreen.selectedIndex,0);
	 greendefence = aquirelevel(document.myoptions.modegreen.selectedIndex,1);
	 redaggression = aquirelevel(document.myoptions.modered.selectedIndex,0);
	 reddefence = aquirelevel(document.myoptions.modered.selectedIndex,1);
	 yellowaggression = aquirelevel(document.myoptions.modeyellow.selectedIndex,0);
	 yellowdefence = aquirelevel(document.myoptions.modeyellow.selectedIndex,1);
	 magentaaggression = aquirelevel(document.myoptions.modemagenta.selectedIndex,0);
	 magentadefence = aquirelevel(document.myoptions.modemagenta.selectedIndex,1);
	 if ( goodsettings() ){ startover(); }else { reload(); }
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: close message window
 // def : 
 // last modified: 1-27-99

function closemessagewindow(){
        if ( (closed == false) && (gameover == 0) ) {
		  closed = true;
		  paused = false;
   	      hide(popwindowblock);
          hide(popcontentblock);
		  }
}


/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: close options
 // def : 
 // last modified: 1-26-99 

function closeoptions(reset){
 if (reset == 1) { 
    window.location="#main";
    messagewindow('<font color=FFFFaa>Loading new game settings...</font>');
    changesettings();
	  }
}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: computermove
 // def : Choses the best possible move for the computer to take, then takes it
 // last modified: 2-02-99 
 //
 // currentplayer:	Who's turn it is
 // aggression:		How much the computer values taking anothers peice
 // defence:		How much the computer values protecting its own peices
 // movechoices:	Array of possible "best moves": randomly chooses which one to take
 // currentlength:	Number of "best moves" in the movechoices array
 // compfromx:		Row to move from
 // compfromy:		Col to move from
 // bestvalue:		Value of the best square yet
 
function computermove(){ 

if (paused == true) {
   setTimeout('computermove();',1000);
 }else {
if (currentplayer == red){
var aggression = redaggression;
var defence = reddefence;
} 

if (currentplayer == green){
var aggression = greenaggression;
var defence = greendefence;
}
if (currentplayer == yellow){
var aggression = yellowaggression;
var defence = yellowdefence;
}
if (currentplayer == magenta){
var aggression = magentaaggression;
var defence = magentadefence;
}

var movechoices  = new Array(100);
var currentlength = 0;

var compfromx = 0;
var compfromy = 0;
var bestvalue = -10;

  //Goes through the Array
  for ( var r = 0; r < 7; r++ ) {
    for ( var c = 0; c < 7; c++ ) { 
	  if (theboard[r][c] == currentplayer) {

        //Goes through all possible moves computer can make.
        for (var i = -2; i < 3; i++){
	      for (var j = -2; j < 3; j++){
			 if ( ((i+r) > -1) && ((i+r) < 7) && ((j+c) > -1) && ((j+c) < 7) ){

				 // Check if move is valid.
				 if (theboard[(i+r)][(j+c)] == 0)
				 {
				     if (!hole_between(r,c,i+r,j+c)) {

					  var value = 0;
					  var deduct = 0;
					  // this loop determines how much the computer will gain from its move
					       for (var q = -1; q < 2; q++){
			                  for (var w = -1; w < 2; w++){
							 
							   if ( ((i+r+q) > -1) && ((i+r+q) < 7) && ((j+c+w) > -1) && ((j+c+w) < 7) ){
							   						 
							      if( (theboard[(i+r+q)][(j+c+w)] != currentplayer) && (theboard[(i+r+q)][(j+c+w)] != 0) )value = value + aggression;
								  if (theboard[(i+r+q)][(j+c+w)] == currentplayer) value = value + defence;
 								  if (theboard[(i+r+q)][(j+c+w)] == hole) value = value - (aggression * .9);
								  }
							   }
						    }
					// this loop determines how much it will loose if it jumps
						if ( Math.sqrt( Math.pow( (0 - i), 2) + Math.pow( (0 - j), 2) ) > Math.sqrt(2) ) { 
					   	  for ( var r2 = 0; r2 < 6; r2++ ) {
                                for ( var c2 = 0; c2 < 6; c2++ ) { 
									if ( ((r+r2) > -1) && ((r+r2) < 7) && ((c+c2) > -1) && ((c+c2) < 7) ){
								  if (theboard[(r+r2)][(c+c2)] == currentplayer) deduct = deduct + defence;
								     }
							     }
						   }
						 }
						value = value - deduct;

							if ( bestvalue < value) {
							     currentlength = 0;
								 bestvalue = value;
                         	}  

						   // add to array of best moves 
						    if (bestvalue == value) {
							     movechoices[currentlength++] = (r+1);
								 movechoices[currentlength++] = (c+1);
							     movechoices[currentlength++] = (i+r+1);
							     movechoices[currentlength++] = (j+c+1);
                         	}  
					     }
					   }
                   }
			   }
		  }
	   }
    }
  }
  var length = ( currentlength/4 );
  guess = randomnumber (length) * 4;
  lastx = movechoices[guess++];
  lasty = movechoices[guess++];
  comptox = movechoices[guess++];
  comptoy = movechoices[guess++];

  goodstartmove(lastx,lasty);
  goodendmove(comptox,comptoy);
  computerslide(lastx,lasty,comptox,comptoy);
 }}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: computerslide
 // def : Slides the computers gooper to where it is moving to
 // last modified: 2-02-99 
 //
 
function computerslide(lasty,lastx,comptoy,comptox){ 
        x = (lastx * 45) + 142;
        y = (lasty * 41) + 38;

        goopercount++
		// create new layer
		if (currentplayer == green){
		createLayer('computergooperDiv',null,(x-25),(y-25),36,36,'<IMG SRC="greeneye.gif" WIDTH=36 HEIGHT=36>','visible',71)
        }
		if (currentplayer == yellow){
		createLayer('computergooperDiv',null,(x-25),(y-25),36,36,'<IMG SRC="yelloweye.gif" WIDTH=36 HEIGHT=36>','visible',71)
        }
		if (currentplayer == magenta){
		createLayer('computergooperDiv',null,(x-25),(y-25),36,36,'<IMG SRC="magentaeye.gif" WIDTH=36 HEIGHT=36>','visible',71)
        }
		if (currentplayer == red){
		createLayer('computergooperDiv',null,(x-25),(y-25),36,36,'<IMG SRC="redeye.gif" WIDTH=36 HEIGHT=36>','visible',71)
		}

        if (n) {
                computerblock = document.computergooperDiv;
        }
        if (ie) {
                computerblock = computergooperDiv.style;
        }
        slidex = x;
		slidey = y;
		t_slidex = (comptox * 45) + 142;
        t_slidey = (comptoy * 41) + 38;
		setupblock(computerblock,0)
        movegooper();
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: floathelp
 // def : 
 // last modified: 1-18-99 

function floathelp(){
    window.open('help.html', 'floatinghelp','noscrollbars,resizable height=400,width=348');
}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: getholes
 // def : 
 // last modified: 1-18-99 

function getholes(found){
theboard[0][1] = 7;
theboard[1][0] = 7;
theboard[1][1] = 7;
theboard[0][5] = 7;
theboard[1][6] = 7; // set so that there are no holes next to the starting goopers
theboard[1][5] = 7;
theboard[5][0] = 7;
theboard[5][1] = 7;
theboard[6][1] = 7;
theboard[5][5] = 7;
theboard[5][6] = 7;
theboard[6][5] = 7;

 if ( found != numberofholes) {
   var r = randomnumber(7);
   var c = randomnumber(7);
     if ( theboard[r][c] == 0 ) { changeeyeball(r,c,hole); getholes(found+1);} else { getholes(found); }
  }
theboard[0][1] = 0;
theboard[1][0] = 0;
theboard[1][1] = 0;
theboard[0][5] = 0;
theboard[1][6] = 0; // set back
theboard[1][5] = 0;
theboard[5][0] = 0;
theboard[5][1] = 0;
theboard[6][1] = 0;
theboard[5][5] = 0;
theboard[5][6] = 0;
theboard[6][5] = 0;
}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: goodendmove
 // def : returns true if good // replaces a blank with place if jumped two spaces
 // last modified: 1-23-99 

function goodendmove(chkrow,chkcol){
    if ( (chkcol < 1) || (chkcol > 7) || (chkrow < 1) || (chkrow > 7) ) { 
		  messagewindow('<font color=FFFFaa>you must move to a space that is on the board !!</font>');
		 return false;}
	if ( (lastx  < 1) || (lastx  > 7) || (lasty  < 1) || (lasty  > 7) ) { alert("goodend move has been called with negative move from variables?? (oh shit)"); return false }
	if ( theboard[(chkrow-1)][(chkcol-1)] != 0 ) {  return false }
	if ( Math.sqrt( Math.pow( (lastx - chkrow), 2) + Math.pow( (lasty - chkcol), 2) ) > Math.sqrt(8) ) { 
		  messagewindow('<font color=FFFFaa>you can only move two<br> or one spaces at a time !!</font>');
		 return false;}
	if ( hole_between (lastx-1, lasty-1, chkrow-1, chkcol-1)) { 
		  messagewindow('<font color=FFFFaa>There is a Hole in the Way !!</font>');
		 return false; }
	if ( Math.sqrt( Math.pow( (lastx - chkrow), 2) + Math.pow( (lasty - chkcol), 2) ) > Math.sqrt(2) ) { 
	changeeyeball((lastx-1),(lasty-1),0); }
	return true
}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: goodstartmove
 // def : 
 // last modified: 1-18-99 

function goodstartmove(chkrow,chkcol){
    if ( (chkcol < 1) || (chkcol > 7) || (chkrow < 1) || (chkrow > 7) ) { return false }
	if ( theboard[(chkrow-1)][(chkcol-1)] != currentplayer ) { return false }
	lastx = chkrow; lasty = chkcol;
	return true
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: goodsettings
 // def : 
 // last modified: late 1-23-99 

function goodsettings(){
     if ( (green == -1) && (red == -1) && (yellow == -1) && (magenta == -1) ){
		return false;}
	 if ( ((green == red) && (red != -1)) || ((green == yellow) && (yellow != -1)) ||
	      ((green == magenta) && (magenta != -1)) || 
	      ((red == yellow) && (yellow != -1)) || ((red == magenta) && (magenta != -1)) || 
		  ((yellow == red) && (red != -1)) || ((yellow == magenta) && (magenta != -1))) {
		return false;}
	return true
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: hideall
 // def : hides all of the menu divs
 // last modified: 1-18-99 

function hideall() {
   // hide all of the menu options before displaying a new one
  hide(slashblock);
  hide(helpblock);
  hide(optionsblock);
  hide(slashblock);
  hide(homeblock);
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: hide
 // def : 
 // last modified: 1-18-99 

function hide(hideobj) {
        if (n) hideobj.visibility = "hide"
        if (ie) hideobj.visibility = "hidden"
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: hole_between
 // def : Determines if there is a hole in between two squares
 // last modified: 1-23-99 @ 22:09
 //
 // first_r:	Row of first square
 // second_r:	Row of second square
 // first_c:	Column of first square
 // second_c:	Column of second square
 

function hole_between(first_r, first_c, second_r, second_c) {
        
	var junk;
	
	//alert(first_r + '\n' + first_c + '\n' + second_r + '\n' + second_c);
	
	// Make the first square less than second...to lessen possibilities to check
	
	if (first_r > second_r)
	{
		junk = first_r;
		first_r = second_r;
		second_r = junk;
	}
	
	if (first_c > second_c)
	{
		junk = first_c;
		first_c = second_c;
		second_c = junk;
	}

	// Check each possibility, for holes.

	//////////////////////////////////
	//Key:                          //
	//////////////////////////////////
	//S - start from                //
	//E - Going to (end)            //
	//? - Place to check for holes  //
	//* - unimportant square        //
	//////////////////////////////////

	// S?E  or  E?S
	
	if ((second_c - first_c == 0) && (second_r - first_r == 2))
	{
		if (theboard[first_r + 1][first_c] == hole)
			return true;
		else
			return false;
	}

	// S      E
	// ?  or  ?
	// E      S
	
	if ((second_r - first_r == 0) && (second_c - first_c == 2))
	{
		if (theboard[first_r][first_c + 1] == hole)
			return true;
		else
			return false;
	}

	// S**      E**      **S      **E
	// *?*  or  *?*  or  *?*  or  *?*
	// **E      **S      E**      S**
	
	if ((second_r - first_r == 2) && (second_c - first_c == 2))
	{
		if (theboard[first_r + 1][first_c + 1] == hole)
			return true;
		else
			return false;
	}

	// S?*  or  E?*  or *?S  or  *?E
	// *?E      *?S     E?*      S?*

	if ((second_r - first_r == 1) && (second_c - first_c == 2))
	{
		if ((theboard[first_r + 1][first_c + 1] == hole)
				&& (theboard[first_r][first_c + 1] == hole))
			return true;
		else
			return false;
	}

	// S*      E*      *S      *E
	// ??  or  ??  or  ??  or  ??
	// *E      *S      E*      S*

	if ((second_c - first_c == 1) && (second_r - first_r == 2))
	{
		if ((theboard[first_r + 1][first_c + 1] == hole)
				&& (theboard[first_r + 1][first_c] == hole))
			return true;
		else
			return false;
	}

	// No more possibilities left....return false
	return false;

}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: init
 // def : 
 // last modified: 1-24-99 11am

function init() {

// Setup Board
	createLayer('totalscoreDiv',null,495,190,220,220,'-','visible',63);
	createLayer('greenscoreDiv',null,495,60,50,50,'-','visible',64);
	createLayer('redscoreDiv',null,555,60,50,50,'-','visible',65);
	createLayer('yellowscoreDiv',null,495,100,50,50,'-','visible',66);
	createLayer('magentascoreDiv',null,555,100,60,60,'-','visible',67);
	createLayer('arrowDiv',null,473,65,50,50,'<img src=arrow.gif width=23 height=17>','visible',68);

// make blocks known by same name to both browsers
        if (n) {
                helpblock = document.thelpDiv;
                optionsblock = document.tohDiv;
                homeblock = document.thomeDiv;
                slashblock = document.slashDiv;
				arrowblock = document.arrowDiv;
			    arrowblock.xpos = parseInt(arrowblock.left);
	            arrowblock.ypos = parseInt(arrowblock.top);
				popwindowblock = document.popwindowDiv;
				popcontentblock = document.popcontentDiv;
        }
        if (ie) {
                helpblock = thelpDiv.style;
                optionsblock = tohDiv.style;
                homeblock = thomeDiv.style;
                slashblock = slashDiv.style;
				arrowblock = arrowDiv.style;
				arrowblock.xpos = parseInt(arrowblock.left);
	            arrowblock.ypos = parseInt(arrowblock.top);
				popwindowblock = popwindowDiv.style;
				popcontentblock = popcontentDiv.style;
        }

// initialize mouse events
	document.onmousedown = mouseDown
	document.onmousemove = mouseMove
	document.onmouseup = mouseUp
if (ns4) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)

// create Div layers for board eyeballs
  for ( var r = 0; r < 7; r++ ) {
     for ( var c = 0; c < 7; c++ ) {
         createLayer('row'+r+'col'+c+'Div',null,(159+(44*c)),(49+(44*r)),36,36,'<IMG SRC="blank.gif" WIDTH=36 HEIGHT=36>');
	     eval('row'+r+'col'+c+' = new DynLayer("row'+r+'col'+c+'Div")');
   }
 }
startover();
}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: iscomputermove
 // def : 
 // last modified: 1-18-99 

function iscomputermove(who){
 if ( ( who == computergreen) || ( who == computerred) || ( who == computeryellow) || ( who == computermagenta) )
 { return true; } else return false;
}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: isstuck
 // def : 
 // last modified: late 1-23-99 

function isstuck(who){
  for ( var r = 0; r < 7; r++ ) {
      for ( var c = 0; c < 7; c++ ) {
	     if (theboard[r][c] == who) {
		      for (var i = -2; i < 3; i++){
			      for (var j = -2; j < 3; j++){
				     if ( ((i+r) > -1) && ((i+r) < 7) && ((j+c) > -1) && ((j+c) < 7) ){
						if (!hole_between(r,c,i+r,j+c)) {
						  if (theboard[(i+r)][(j+c)] == 0) return false;
						}
					  }
                   }
			   }
		  }
	   }
   }
   if (gameover == 0){
    if (who == red) { 
      if (showred == 0) { 
        showred= 1; 
	    messagewindow('<font color=FFAAAA>Red can not move so<br> red forfits its move</font>');
	  }
	 }
    if (who == green) { 
      if (showgreen == 0) { 
        showgreen= 1; 
	    messagewindow('<font color=AAffAA>Green can not move so<br> Green forfits its move</font>');
	  }
	 }
    if (who == yellow) { 
      if (showyellow == 0) { 
        showyellow= 1; 
	    messagewindow('<font color=FFffAA>Yellow can not move so<br> Yellow forfits its move</font>');
	  }
	 }
    if (who == magenta) { 
      if (showmagenta == 0) { 
        showmagenta= 1; 
	    messagewindow('<font color=FFAAff>Magenta can not move so<br> Magenta forfits its move</font>');
	  }
	 }
   changeplayer(who+1); }
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: LayerWrite
 // def : 
 // last modified: 1-18-99 

function layerWrite(id,nestref,text) {
	if (ns4) {
		if (nestref) var lyr = eval('document.'+nestref+'.document.'+id+'.document')
		else var lyr = document.layers[id].document
		lyr.open()
		lyr.write(text)
		lyr.close()
	}
	else if (ie4) document.all[id].innerHTML = text
}

//////////////////////////////////////////////////////////////////////////////////////////////
 // Function maydisable(obj);
 // def: Disables the AI form element if needed
 // last modified: 8-20-99
function maydisable(obj)
{
	if (obj.value == 2 || obj.value == 0)
	{
		if (obj.name == "playinggreen")
		{
			document.myoptions.modegreen.disabled = true;
		}

		if (obj.name == "playingred")
		{
			document.myoptions.modered.disabled = true;
		}

		if (obj.name == "playingyello")
		{
			document.myoptions.modeyellow.disabled = true;
		}

		if (obj.name == "playingmagenta")
		{
			document.myoptions.modemagenta.disabled = true;
		}
	}
	else
	{
		if (obj.name == "playinggreen")
		{
			document.myoptions.modegreen.disabled = false;
		}

		if (obj.name == "playingred")
		{
			document.myoptions.modered.disabled = false;
		}

		if (obj.name == "playingyello")
		{
			document.myoptions.modeyellow.disabled = false;
		}

		if (obj.name == "playingmagenta")
		{
			document.myoptions.modemagenta.disabled = false;
		}

	}
}


//////////////////////////////////////////////////////////////////////////////////////////////
 // Function Messagewindow(message);
 // def: pops up a window with a message
 // last modified: 2-02-99

 function messagewindow(message){
          paused = true;
          closed = false;  
	      show(popwindowblock);
          layerWrite('popcontentDiv',null,message);
          show(popcontentblock);
          setTimeout('closemessagewindow();', windowpop);		 
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: MouseDown
 // def : 
 // last modified: 3-23-99 

function mouseDown(e) {
	if (iscomputermove(currentplayer) || moved)
		return false;

	if ((ns4 && e.which == 1) || ie4) {
		var x = (ns4)? e.pageX : event.x
		var y = (ns4)? e.pageY : event.y+document.body.scrollTop
		drag.mouseDown(x,y)
		chkcol = Math.ceil(((x - 142)/47));
		chkrow = Math.ceil(((y-38)/43));
		if (drag.active) {
			return false;
		}
		else if ( (goodstartmove(chkrow,chkcol)) ) { 
			moved = true;
	    	col = chkcol;
		    row = chkrow;
			// increment counter
			goopercount += 1

			// create new layer
			if (currentplayer == green){
			createLayer('smiley'+goopercount+'Div',null,(x-25),(y-25),36,36,'<IMG SRC="greeneye.gif" WIDTH=36 HEIGHT=36>','visible','50')
            }
			if (currentplayer == yellow){
			createLayer('smiley'+goopercount+'Div',null,(x-25),(y-25),36,36,'<IMG SRC="yelloweye.gif" WIDTH=36 HEIGHT=36>','visible','50')
            }
			if (currentplayer == magenta){
			createLayer('smiley'+goopercount+'Div',null,(x-25),(y-25),36,36,'<IMG SRC="magentaeye.gif" WIDTH=36 HEIGHT=36>','visible','50')
            }
			if (currentplayer == red){
			createLayer('smiley'+goopercount+'Div',null,(x-25),(y-25),36,36,'<IMG SRC="redeye.gif" WIDTH=36 HEIGHT=36>','visible','50')
			}
			// make DynLayer
			eval('smiley'+goopercount+' = new DynLayer("smiley'+goopercount+'Div")')
			
			// add to drag object
			drag.add(eval('smiley'+goopercount))
			
			// begin dragging the new layer
			drag.mouseDown(x,y)
			return false
		}
		else
			return true;
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: MouseMove
 // def : 
 // last modified: 1-18-99 

function mouseMove(e) {
	var x = (ns4)? e.pageX : event.x
	var y = (ns4)? e.pageY : event.y+document.body.scrollTop
	if (drag.active) {
		drag.mouseMove(x,y)
		return false
	}
	else return true
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: mouseUp
 // def : 
 // last modified: 1-23-99 

function mouseUp(e) {

	var x = (ns4)? e.pageX : event.x;
	var y = (ns4)? e.pageY : event.y+document.body.scrollTop;
	if (drag.active) {
		drag.mouseUp();
		 chkcol = Math.ceil(((x - 142)/47));
		 chkrow = Math.ceil(((y-38)/43));
		if ( goodendmove(chkrow,chkcol)) { 
		  row = chkrow;
		  col = chkcol;
		 changeeyeball((row-1),(col-1),currentplayer);
         // set down eye in array
		 if (currentplayer == green) {theboard[(row-1)][(col-1)] = green;}
		 if (currentplayer == red)   {theboard[(row-1)][(col-1)] = red;}
		 if (currentplayer == yellow) {theboard[(row-1)][(col-1)] = yellow;}
		 if (currentplayer == magenta) {theboard[(row-1)][(col-1)] = magenta;}
         eval('setTimeout("replaceeyes(row,col);",replacetime);');
        }
		else
			moved = false;
		// destroy layer
         destroyLayer(drag.obj.id)

	  // remove from drag object          
			drag.remove(drag.obj)
			
			// delete dynlayer

			eval('delete '+drag.obj.id.substr(0,drag.obj.id.length-3))
	}
	else return true
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: movearrow
 // def : 
 // last modified: 1-18-99 

function movearrowto(x,y)
{  
	arrowblock.xpos = x
	arrowblock.ypos = y
	arrowblock.left = arrowblock.xpos
	arrowblock.top = arrowblock.ypos

}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: movegooper
 // def : helps slides the computers gooper to where it is moving to
 // last modified: 2-02-99 
 //

function movegooper()
{
   if ( ((t_slidex != slidex) || (t_slidey != slidey)) && (countslide < 25) ){  
	  if (slidex < t_slidex) { computerblock.xpos += 3; slidex += 3;computerblock.left = computerblock.xpos; }
	  if (slidex > t_slidex) { computerblock.xpos -= 3; slidex -= 3;computerblock.left = computerblock.xpos; }
	  if (slidey > t_slidey) { computerblock.ypos -= 3; slidey -= 3;computerblock.top = computerblock.ypos; }
	  if (slidey < t_slidey) { computerblock.ypos += 3; slidey += 3;computerblock.top = computerblock.ypos; }
      countslide++;
	  setTimeout('movegooper();',0);
	} else {
	    countslide = 0;
		// destroy layer
         destroyLayer('computergooperDiv');

		// make DynLayer
		// eval('computer'+goopercount+' = new DynLayer("computer'+goopercount+'Div")')

		// delete dynlayer
		// eval('delete '+drag.obj.id.substr(0,drag.obj.id.length-3))

        changeeyeball((comptox-1),(comptoy-1),currentplayer);
        eval('setTimeout("replaceeyes((comptox),(comptoy));",replacetime);');
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: openoptions
 // def : 
 // last modified: 1-26-99 

function openoptions(){
 show(options3block);
 show(options2block);
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: reload
 // def : 
 // last modified: 2-02-99 

function reload(){
location.reload();
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: replaceeyes
 // def : 
 // last modified: 1-18-99 

function replaceeyes(row,col){
for (var i = -1; i < 2; i++){
  for (var j = -1; j < 2; j++){
     checkrow = row + i;
	 checkcol = col + j;
	 if ( (checkcol > 0) && (checkcol < 8) && (checkrow > 0) && (checkrow < 8) ){
	      if ( (theboard[(checkrow-1)][(checkcol-1)] != currentplayer) && (theboard[(checkrow-1)][(checkcol-1)] != 0) && (theboard[(checkrow-1)][(checkcol-1)] != 5) ){	 
          changeeyeball((checkrow-1),(checkcol-1),currentplayer);
		  theboard[(checkrow-1)][(checkcol-1)] = currentplayer; }
		}
   }
 }
showscore();
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: randomnumber
 // def : 
 // last modified: 1-18-99 

function randomnumber (between){
var x = new Date();
  var guessed = (x.getSeconds());
  guessed = Math.floor( (Math.random(guessed) * 1000) );
  guessed = ((guessed % between));
 return guessed;
 }

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: setupblock
 // def : sets up a block for moving
 // last modified: 2-02-99 
 //

function setupblock(myblock,angle){
// this function sets up the Div angle of direction

	myblock.xpos = parseInt(myblock.left)
	myblock.ypos = parseInt(myblock.top)
	myblock.angle = angle
	myblock.xinc = 5*Math.cos(myblock.angle*Math.PI/180)
	myblock.yinc = 5*Math.sin(myblock.angle*Math.PI/180)
	myblock.count = 0
}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: show
 // def : 
 // last modified: 1-18-99 

function show(showobj) {
        if (n) showobj.visibility = "show"
        if (ie) showobj.visibility = "visible"
}
/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: showscore
 // def : 
 // last modified: 1-18-99 

function showscore(){
redscore = 0;
greenscore = 0;
yellowscore = 0;
magentascore = 0;

for ( var r = 0; r < 7; r++ ) {
  for ( var c = 0; c < 7; c++ ) {
     if (theboard[r][c] == green )  greenscore++;
	 if (theboard[r][c] == red ) redscore++;
	 if (theboard[r][c] == yellow ) yellowscore++;
	 if (theboard[r][c] == magenta ) magentascore++;
	}
 }
  layerWrite('greenscoreDiv',null,'<font color=77FF77 size=+3><i>'+greenscore+'</i></font>');
  layerWrite('redscoreDiv',null,'<font color=FF7777 size=+3><i>'+redscore+'</i></font>');
  layerWrite('yellowscoreDiv',null,'<font color=FFFF77 size=+3><i>'+yellowscore+'</i></font>');
  layerWrite('magentascoreDiv',null,'<font color=FF77FF size=+3><i>'+magentascore+'</i></font>');

  if ( (greenscore == 0) && (yellowscore == 0 ) && (magentascore == 0 )) {
   messagewindow('<font color=FFAAAA>RED WINS !!!</font>');
   gameover = 1;}
  if ( (redscore == 0 ) && (yellowscore == 0 ) && (magentascore == 0 )){
   messagewindow('<font color=AAFFAA>GREEN WINS !!!</font>');
   gameover = 1;}
  if ( (greenscore == 0 ) && (redscore == 0) && (magentascore == 0 )){
   messagewindow('<font color=FFFFAA>YELLOW WINS !!!</font>');
   gameover = 1;}
  if ( (greenscore == 0 ) && (redscore == 0 ) && (yellowscore == 0 )){
   messagewindow('<font color=FFAAFF>MAGENTA WINS !!!</font>');
   gameover = 1;}
  if (  ( (greenscore+redscore+magentascore+yellowscore+numberofholes) == 49) )  {
    gameover = 1;
    if ( (greenscore > redscore) && (greenscore > yellowscore) && (greenscore > magentascore)){
	   messagewindow('<font color=AAFFAA>GREEN WINS !!!</font>');
	} else if ( (redscore > greenscore) && (redscore > yellowscore) && (redscore > magentascore)){
	   messagewindow('<font color=FFAAAA>RED WINS !!!</font>');
	} else if ( (yellowscore > greenscore) && (yellowscore > redscore) && (yellowscore > magentascore)){
	   messagewindow('<font color=FFFFAA>YELLOW WINS !!!</font>');
	} else if ( (magentascore > greenscore) && (magentascore > yellowscore) && (magentascore > redscore)){
	   messagewindow('<font color=FFAAFF>MAGENTA WINS !!!</font>');
	} else { messagewindow('<font color=FFFFFF> TIE GAME </font>'); }
   }

  if (gameover == 1){
	   totalred = totalred + redscore;
	   totalgreen = totalgreen + greenscore;
	   totalyellow = totalyellow + yellowscore;
	   totalmagenta = totalmagenta + magentascore;
           window.open('about.htm', 'floatinghelp','scrollbars,resizable, height=400,width=550');
	   startover();
    } else { setTimeout('changeplayer(currentplayer+1);',timebetween); }
}

/////////////////////////////////////////////////////////////////////////////////////////////
 // Function: startover
 // def : 
 // last modified: 1-24-99 noon

function startover(){
 // reset the board to start of game

  currentplayer = 1;

  // set everything in the array and board to blank 0
  for ( var r = 0; r < 7; r++ ) {
     for ( var c = 0; c < 7; c++ ) {
       changeeyeball(r,c,0);
   }
 }

  players = 4;
  showred = 0;
  showgreen = 0;
  showmagenta = 0;
  showyellow = 0;
  gameover = 0;
  // place beginning eyes
  if (green != -1) { changeeyeball(0,0,green); } else { players--;showgreen = 1; }
  if (red != -1) { changeeyeball(6,6,red);}else {players--;showred = 1;}
  if (magenta != -1) { changeeyeball(0,6,magenta);} else {players--; showmagenta = 1;}
  if (yellow != -1) { changeeyeball(6,0,yellow);} else {players--; showyellow = 1;}

  getholes(0);

  layerWrite('totalscoreDiv',null,'<font color=FF7777 size=+3><i>'+totalred+'</i></font><br><font color=77FF77 size=+3><i>'+totalgreen+'</i></font><br><font color=FFFF77 size=+3><i>'+totalyellow+'</i></font><br><font color=FF77FF size=+3><i>'+totalmagenta+'</i></font>');
  layerWrite('greenscoreDiv',null,'<font color=77FF77><i>green</i></font>');
  layerWrite('redscoreDiv',null,'<font color=FF7777><i>red</i></font>');
  layerWrite('yellowscoreDiv',null,'<font color=FFFF77><i>yellow</i></font>');
  layerWrite('magentascoreDiv',null,'<font color=FF77FF><i>magenta</i></font>');

readyformouse = 1;

// showscore();
hide(popwindowblock);
hide(popcontentblock);
changeplayer(1);
}



