Parag’s Den

Dedicated to my adored friends…..

TicTac 3D

Posted by paragdongre on November 13, 2007


Hi Friends!
Simply copy this javascript code in notepad and save it as “.HTML” file format. Also download the images by clicking link below -> Tictac-3d.zip(Click to download)

[Note: Save the “.html”  file in downloaded folder i.e. tictac-3d. Plz dont make any type of updation in the code before copying it.]
—————————————————————————————–

 Javascript Code->

<HEAD>
<SCRIPT LANGUAGE=”JavaScript”>

<!– Begin
var i, j, k, RotAng, XMouseOver, YMouseOver, LastEvent, IsOver=true, IsStart0;
var Max, NDraw, Start, I_Sel, J_Sel, Start0;
var NeedBallDown, MoveCount, MaxMoveCount;
IsPlayer = new Array(2);
Level = new Array(2); 
Fld = new Array(4);
for (i=0; i<4; i++)
  Fld[i] = new Array(4);
for (i=0; i<4; i++)
{ for (j=0; j<4; j++)
    Fld[i][j] = new Array(4); 
}
ScreenFld = new Array(4);
for (i=0; i<4; i++)
  ScreenFld[i] = new Array(4);
for (i=0; i<4; i++)
{ for (j=0; j<4; j++)
    ScreenFld[i][j] = new Array(2); 
}
FldCount = new Array(4);
for (i=0; i<4; i++)
  FldCount[i] = new Array(4);
Value = new Array(4);
for (i=0; i<4; i++)
  Value[i] = new Array(4);
History = new Array(64);
for (i=0; i<64; i++)
  History[i] = new Array(2);
Pic= new Array(4);
Pic[0] = new Image(); Pic[0].src=”tt3d_0.gif” mce_src=”tt3d_0.gif”;
Pic[1] = new Image(); Pic[1].src=”tt3dred.gif” mce_src=”tt3dred.gif”;
Pic[2] = new Image(); Pic[2].src=”tt3d_1.gif” mce_src=”tt3d_1.gif”;
Pic[3] = new Image(); Pic[3].src=”tt3dblue.gif” mce_src=”tt3dblue.gif”;

IsStart0=true;
IsPlayer[0]=true;
IsPlayer[1]=false;
Level[0]=2;
Level[1]=3;

function Init()
{ var ii, jj, kk;
  for (ii=0; ii<4; ii++)
  { for (jj=0; jj<4; jj++)
    { for (kk=0; kk<4; kk++)
        Fld[ii][jj][kk]=0;
      FldCount[ii][jj]=0;
    }
  }
  if (IsStart0) Start0=true;
  else Start0=false;
  LastEvent=””;
  NeedBallDown=0;
  I_Sel=-1; J_Sel=-1;
  MoveCount=0;
  MaxMoveCount=0;
  RotAng=0;
  XMouseOver=-1;
  YMouseOver=-1;
  RefreshScreen();
  IsOver=false;
}

function SetOption(nn, mm)
{ if (nn<2)
  { if (mm==0)
      IsPlayer[nn]=true;
    else
      IsPlayer[nn]=false;
  }
  else IsStart0=mm;
}

function SetLevel(nn, mm)
{ Level[nn]=mm;
}

function Timer()
{ if (IsOver) return;
  if (NeedBallDown==0)
  { if ((((MoveCount+Start0)%2==1)&&(IsPlayer[0]))||
        (((MoveCount+Start0)%2==0)&&(IsPlayer[1])));
    else
    { if (LastEvent==””) GetBestMove(((MoveCount+1+Start0)%2)*2-1);
      if (LastEvent==”TurnLeft”) { TurnLeft(); LastEvent=””; }
      if (LastEvent==”TurnRight”) { TurnRight(); LastEvent=””; }
      if (LastEvent==”Back”) { Back(); LastEvent=””; }
      if (LastEvent==”Replay”) { Replay(); LastEvent=””; }       
    }
  }
  if (NeedBallDown>0)
  { if (Fld[I_Sel][J_Sel][NeedBallDown-1]==0)
    { if (NeedBallDown<4)
        window.document.images[13*(YMouseOver+3-NeedBallDown)+XMouseOver].src = Pic[2].src;
      if ((MoveCount+Start0)%2==1)
        window.document.images[13*(YMouseOver+4-NeedBallDown)+XMouseOver].src = Pic[1].src;
      else
        window.document.images[13*(YMouseOver+4-NeedBallDown)+XMouseOver].src = Pic[3].src;
    }
    if (NeedBallDown>1)
    { if (Fld[I_Sel][J_Sel][NeedBallDown-2]!=0)
        NeedBallDown=1;
    }
    if (NeedBallDown==1)
    { window.document.OptionsForm.Moves.value=MoveCount+1;
      MakeMove();
    }
    NeedBallDown–;
  }
}

function TurnLeft()
{ if (NeedBallDown>0) { LastEvent=”TurnLeft”; return; }
  RotAng–;
  if (RotAng<0) RotAng=7;
  RefreshScreen();
}

function TurnRight()
{ if (NeedBallDown>0) { LastEvent=”TurnRight”; return; }
  RotAng++;
  if (RotAng>7) RotAng=0;
  RefreshScreen();
}

function Back()
{ if (NeedBallDown>0) { LastEvent=”Back”; return; }
  if (MoveCount>0)
  { IsOver=false;
    MoveCount–;
    var ii=History[MoveCount][0];
    var jj=History[MoveCount][1];
    var kk=–FldCount[ii][jj];
    Fld[ii][jj][kk]=0;
    window.document.OptionsForm.Moves.value=MoveCount;
    RefreshPic(ii, jj, kk);
  }
}

function Replay()
{ if (NeedBallDown>0) { LastEvent=”Replay”; return; }
  if (MoveCount<MaxMoveCount)
  { I_Sel=History[MoveCount][0];
    J_Sel=History[MoveCount][1];
    window.document.OptionsForm.Moves.value=MoveCount+1;
    MakeMove();     
    RefreshPic(I_Sel, J_Sel, FldCount[I_Sel][J_Sel]-1);
  }
}

function MakeMove()
{ var ccol, kk;
  ccol=((MoveCount+1+Start0)%2)*2-1;
  kk=FldCount[I_Sel][J_Sel]++;
  Fld[I_Sel][J_Sel][kk]=ccol;
  if (History[MoveCount][0]!=I_Sel)
  { History[MoveCount][0]=I_Sel;
    MaxMoveCount=MoveCount+1;
  }
  if (History[MoveCount][1]!=J_Sel)
  { History[MoveCount][1]=J_Sel;
    MaxMoveCount=MoveCount+1;
  }
  MoveCount++;
  if (MaxMoveCount<MoveCount)
    MaxMoveCount=MoveCount;
  IsOver=IsWinning(I_Sel, J_Sel, kk, ccol);
  if (IsOver)
  { if (ccol<0) alert(“Red has won !”);
    else alert(“Blue has won !”);
  }
  else
  { if (MoveCount==64)
    { IsOver=true;
      alert(“Draw !”);
    }
  }
}

function GetBestMove(theCol)
{ var ii, jj, kk, zz, vv, vvbest, nn, cc=theCol;
  var iiw,jjw,kkw,wwcount;
  var LLevel=Level[(MoveCount+1+Start0)%2];
  I_Sel=-1; J_Sel=-1;
  for (ii=0; ii<4; ii++)
  { for (jj=0; jj<4; jj++)
    { if ((kk=FldCount[ii][jj])<4)
      { Fld[ii][jj][kk]=cc;
        if (IsWinning(ii, jj, kk, cc))
        { Fld[ii][jj][kk]=0;
          Select(ii, jj);
          return;
        }
        Fld[ii][jj][kk]=0;
      }
    }
  }
  nn=0;
  for (ii=0; ii<4; ii++)
  { for (jj=0; jj<4; jj++)
    { Value[ii][jj]=0;
      if ((kk=FldCount[ii][jj])<4)
      { nn++;
        Fld[ii][jj][kk]=-cc;
        if (IsWinning(ii, jj, kk, -cc))
        { Fld[ii][jj][kk]=0;
          Select(ii, jj);
          return;
        }
        Fld[ii][jj][kk]=0;
      }
    }
  }
  if (LLevel>2)
  { for (ii=0; ii<4; ii++)
    { for (jj=0; jj<4; jj++)
      { if ((kk=FldCount[ii][jj])<4)
        { wwcount=0;
          Fld[ii][jj][kk]=cc;
          if (kk<3)
          { if ((wwcount=CanWin(ii,jj,kk+1,cc))==2)
            { Fld[ii][jj][kk]=0;
              Select(ii, jj);
              return;
            }
          }
          if (wwcount>=0)
          { for (iiw=0; iiw<4; iiw++)    
            { for (jjw=0; jjw<4; jjw++)
              { if ((kkw=FldCount[iiw][jjw])<4)
                { if (!((ii==iiw)&&(jj==jjw)))
                  { Fld[iiw][jjw][kkw]=cc;
                    if (IsWinning(iiw, jjw, kkw, cc))
                      wwcount++;
                    Fld[iiw][jjw][kkw]=0;
                    if (wwcount>1)
                    { Fld[ii][jj][kk]=0;
                      Select(ii, jj);
                      return;
                    }
                  }
                }
              }
            }
          }
          Fld[ii][jj][kk]=0;
        }
      }
    }
  }
  if (LLevel>3)
  { for (ii=0; ii<4; ii++)
    { for (jj=0; jj<4; jj++)
      { if ((kk=FldCount[ii][jj])<4)
        { vv=0;
          Fld[ii][jj][kk]=cc;
          if (kk<3)
          { Fld[ii][jj][kk+1]=-cc;
            if (IsWinning(ii, jj, kk+1, -cc))
              vv=-1;
            Fld[ii][jj][kk+1]=0;
          }
          if (vv==0)
          { Fld[ii][jj][kk]=-cc;
            if(kk<3)
            { Fld[ii][jj][kk+1]=cc;
              if (IsWinning(ii, jj, kk+1, cc))
                Value[ii][jj]=-200;
              Fld[ii][jj][kk+1]=0;
            }
            for (iiw=0; iiw<4; iiw++)    
            { for (jjw=0; jjw<4; jjw++)
              { if ((kkw=FldCount[iiw][jjw])<4)
                { if (!((ii==iiw)&&(jj==jjw)))
                  { if ((vv=CanWin(iiw,jjw,kkw,-cc))==2)
                    { Fld[ii][jj][kk]=0;
                      Select(ii, jj);
                      return;
                    }
                    if (vv==-1)
                    Value[ii][jj]=-100;
                  }
                }
              }
            }
            Fld[ii][jj][kk]=cc;
            if (kk<3)
            { Fld[ii][jj][kk+1]=-cc;
              for (iiw=0; iiw<4; iiw++)    
              { for (jjw=0; jjw<4; jjw++)
                { if ((kkw=FldCount[iiw][jjw])<4)
                  { if (!((ii==iiw)&&(jj==jjw)))
                    { if (CanWin(iiw,jjw,kkw,-cc)==2)
                        Value[ii][jj]=-5000;
                    }
                  }
                }
              }
              Fld[ii][jj][kk+1]=0;
            }
          }
          Fld[ii][jj][kk]=0;
        }
      }
    }
  }
  if (nn==0)
  { IsOver=true; return; }
  zz=0; 
  nn=0;
  for (ii=0; ii<4; ii++)
  { for (jj=0; jj<4; jj++)
    { if ((kk=FldCount[ii][jj])<4)
      { Fld[ii][jj][kk]=cc;
        if (kk<3)
        { Fld[ii][jj][kk+1]=-cc;
          if (IsWinning(ii, jj, kk+1, -cc))
          { vv=-8100;
            Fld[ii][jj][kk+1]=0;
          }
          else
          { Fld[ii][jj][kk+1]=0;
            vv=GetValue(ii, jj, kk, cc);
          }
        }
        else
          vv=GetValue(ii, jj, kk, cc);
        if (LLevel<2) vv%=200;
        if (LLevel<3) vv+=Math.floor(Math.random()*108);
        if (LLevel==3) vv+=Math.floor(Math.random()*27);
        Value[ii][jj]+=vv;
        if (zz==0) vvbest=Value[ii][jj];
        zz++;
        if (Value[ii][jj]==vvbest)
          nn++;
        if (Value[ii][jj]>vvbest)
        { nn=1;
          vvbest=Value[ii][jj];
        }
        Fld[ii][jj][kk]=0;
      }
    }
  }
  zz=Math.floor(Math.random()*nn);
  nn=-1;
  for (ii=0; ii<4; ii++)
  { for (jj=0; jj<4; jj++)
    { if ((kk=FldCount[ii][jj])<4)
      { if (vvbest==Value[ii][jj])
        { nn++;
          if (nn==zz)
          { Select(ii, jj);
            return;
          }
        }
      }
    }
  }
}

function CanWin(ii, jj, kk, cc)
{ var kkl, kkk=kk-1;
  var vv=0;
  do
  { kkk++;
    Fld[ii][jj][kkk]=-cc;
    if ((IsWinning(ii, jj, kkk, -cc)))
    { for (kkl=kk; kkl<=kkk; kkl++)
        Fld[ii][jj][kkl]=0;
      if (kkk==kk) return(-1);
      else return(vv);
    }
    Fld[ii][jj][kkk]=cc;
    if ((IsWinning(ii, jj, kkk, cc))&&(kkk<3))
    { if (kkk==kk) vv++;
      Fld[ii][jj][kkk]=-cc;
      Fld[ii][jj][kkk+1]=cc;
      if ((IsWinning(ii, jj, kkk+1, cc)))
      { for (kkl=kk; kkl<=kkk+1; kkl++)
          Fld[ii][jj][kkl]=0;
        return(2);
      }
      Fld[ii][jj][kkk+1]=0;
    }
    Fld[ii][jj][kkk]=-cc;
  }
  while (kkk<3);
  for (kkl=kk; kkl<=kkk; kkl++)
    Fld[ii][jj][kkl]=0;
  return(vv);
}

function GetValue(ii, jj, kk, ccol)
{ var ll, cc, ccount1, ccount2, vval=0;
  var dd1, dd2, ddv, ddd, ddr;
  if (MoveCount%2==0)
  { dd1=1;
    dd2=1;
    ddv=(3-kk)*2;
    ddd=4; ddr=4;
    if (kk==2)
    { ddd=8; ddr=8; }
  }
  else
  { dd1=1;
    dd2=1;
    ddv=(3-kk)*(3-kk)+1;
    ddd=4; ddr=4;
    if (kk==2)
    { ddd=8; ddr=8; }
  }
  var ss1=0;
  var ss2=0;
  var ww1count=3*dd1;
  var ww1=0;
  var ww2count=2*dd2;
  var ww2=0;
  ccount1=0;
  ccount2=0;
  for (ll=0; ll<4; ll++)
  { if ((cc=Fld[ll][jj][kk])==ccol) ccount1+=dd1;
    if (cc==-ccol) ccount2+=dd2;
  }
  if ((ccount1>dd1)&&(ccount2>0));
  else
  { vval+=(ccount1+1)*(ccount2+1)*ddv;
    ss1+=ccount1-dd1; ss2+=ccount2;
    if (ccount1>=ww1count) ww1++;
    if (ccount2>=ww2count) ww2++;
  }
  ccount1=0;
  ccount2=0;
  for (ll=0; ll<4; ll++)
  { if ((cc=Fld[ii][ll][kk])==ccol) ccount1+=dd1;
    if (cc==-ccol) ccount2+=dd2;
  }
  if ((ccount1>dd1)&&(ccount2>0));
  else
  { vval+=(ccount1+1)*(ccount2+1)*ddv;
    ss1+=ccount1-dd1; ss2+=ccount2;
    if (ccount1>=ww1count) ww1++;
    if (ccount2>=ww2count) ww2++;
  }
  ccount1=0;
  ccount2=0;
  for (ll=0; ll<=kk; ll++)
  { if ((cc=Fld[ii][jj][ll])==ccol) ccount1+=dd1;
    if (cc==-ccol) ccount2+=dd2;
  }
  if ((ccount1>dd1)&&(ccount2>0));
  else
  { vval+=(ccount1+1)*(ccount2+1)*ddv;
    ss1+=ccount1-dd1; ss2+=ccount2;
    if (ccount1>=ww1count) ww1++;
    if (ccount2>=ww2count) ww2++;
  }
  if (jj==kk)
  { ccount1=0;
    ccount2=0;
    for (ll=0; ll<4; ll++)
    { if ((cc=Fld[ii][ll][ll])==ccol) ccount1+=dd1;
      if (cc==-ccol) ccount2+=dd2;
    }
    if ((ccount1>dd1)&&(ccount2>0));
    else
    { vval+=(ccount1+1)*(ccount2+1)*ddd;
      ss1+=ccount1-dd1; ss2+=ccount2;
      if (ccount1>=ww1count) ww1++;
      if (ccount2>=ww2count) ww2++;
    }
  }
  if ((3-jj)==kk)
  { ccount1=0;
    ccount2=0;
    for (ll=0; ll<4; ll++)
    { if ((cc=Fld[ii][3-ll][ll])==ccol) ccount1+=dd1;
      if (cc==-ccol) ccount2+=dd2;
    }
    if ((ccount1>dd1)&&(ccount2>0));
    else
    { vval+=(ccount1+1)*(ccount2+1)*ddd;
      ss1+=ccount1-dd1; ss2+=ccount2;
      if (ccount1>=ww1count) ww1++;
      if (ccount2>=ww2count) ww2++;
    }
  }
  if (ii==kk)
  { ccount1=0;
    ccount2=0;
    for (ll=0; ll<4; ll++)
    { if ((cc=Fld[ll][jj][ll])==ccol) ccount1+=dd1;
      if (cc==-ccol) ccount2+=dd2;
    }
    if ((ccount1>dd1)&&(ccount2>0));
    else
    { vval+=(ccount1+1)*(ccount2+1)*ddd;
      ss1+=ccount1-dd1; ss2+=ccount2;
      if (ccount1>=ww1count) ww1++;
      if (ccount2>=ww2count) ww2++;
    }
  }
  if ((3-ii)==kk)
  { ccount1=0;
    ccount2=0;
    for (ll=0; ll<4; ll++)
    { if ((cc=Fld[3-ll][jj][ll])==ccol) ccount1+=dd1;
      if (cc==-ccol) ccount2+=dd2;
    }
    if ((ccount1>dd1)&&(ccount2>0));
    else
    { vval+=(ccount1+1)*(ccount2+1)*ddd;
      ss1+=ccount1-dd1; ss2+=ccount2;
      if (ccount1>=ww1count) ww1++;
      if (ccount2>=ww2count) ww2++;
    }
  }
  if (jj==ii)
  { ccount1=0;
    ccount2=0;
    for (ll=0; ll<4; ll++)
    { if ((cc=Fld[ll][ll][kk])==ccol) ccount1+=dd1;
      if (cc==-ccol) ccount2+=dd2;
    }
    if ((ccount1>dd1)&&(ccount2>0));
    else
    { vval+=(ccount1+1)*(ccount2+1)*ddd;
      ss1+=ccount1-dd1; ss2+=ccount2;
      if (ccount1>=ww1count) ww1++;
      if (ccount2>=ww2count) ww2++;
    }
  }                         
  if ((3-jj)==ii)
  { ccount1=0;
    ccount2=0;
    for (ll=0; ll<4; ll++)
    { if ((cc=Fld[ll][3-ll][kk])==ccol) ccount1+=dd1;
      if (cc==-ccol) ccount2+=dd2;
    }
    if ((ccount1>dd1)&&(ccount2>0));
    else
    { vval+=(ccount1+1)*(ccount2+1)*ddd;
      ss1+=ccount1-dd1; ss2+=ccount2;
      if (ccount1>=ww1count) ww1++;
      if (ccount2>=ww2count) ww2++;
    }
  }                       
  if ((ii==jj)&&(jj==kk))
  { ccount1=0;
    ccount2=0;
    for (ll=0; ll<4; ll++)
    { if ((cc=Fld[ll][ll][ll])==ccol) ccount1+=dd1;
      if (cc==-ccol) ccount2+=dd2;
    }
    if ((ccount1>dd1)&&(ccount2>0));
    else
    { vval+=(ccount1+1)*(ccount2+1)*ddr;
      ss1+=ccount1-dd1; ss2+=ccount2;
      if (ccount1>=ww1count) ww1++;
      if (ccount2>=ww2count) ww2++;
    }
  }
  if ((ii==kk)&&((3-jj)==kk))
  { ccount1=0;
    ccount2=0;
    for (ll=0; ll<4; ll++)
    { if ((cc=Fld[ll][3-ll][ll])==ccol) ccount1+=dd1;
      if (cc==-ccol) ccount2+=dd2;
    }
    if ((ccount1>dd1)&&(ccount2>0));
    else
    { vval+=(ccount1+1)*(ccount2+1)*ddr;
      ss1+=ccount1-dd1; ss2+=ccount2;
      if (ccount1>=ww1count) ww1++;
      if (ccount2>=ww2count) ww2++;
    }
  }
  if ((ii==jj)&&(jj==(3-kk)))
  { ccount1=0;
    ccount2=0;
    for (ll=0; ll<4; ll++)
    { if ((cc=Fld[ll][ll][3-ll])==ccol) ccount1+=dd1;
      if (cc==-ccol) ccount2+=dd2;
    }
    if ((ccount1>dd1)&&(ccount2>0));
    else
    { vval+=(ccount1+1)*(ccount2+1)*ddr;
      ss1+=ccount1-dd1; ss2+=ccount2;
      if (ccount1>=ww1count) ww1++;
      if (ccount2>=ww2count) ww2++;
    }
  }
  if (((3-ii)==kk)&&(jj==kk))
  { ccount1=0;
    ccount2=0;
    for (ll=0; ll<4; ll++)
    { if ((cc=Fld[3-ll][ll][ll])==ccol) ccount1+=dd1;
      if (cc==-ccol) ccount2+=dd2;
    }
    if ((ccount1>dd1)&&(ccount2>0));
    else
    { vval+=(ccount1+1)*(ccount2+1)*ddr;
      ss1+=ccount1-dd1; ss2+=ccount2;
      if (ccount1>=ww1count) ww1++;
      if (ccount2>=ww2count) ww2++;
    }
  }
  if (ww1>1) vval+=ww1*4000;
  if (ss1>3*dd1) vval+=(ss1-3*dd1)*20;
  if ((ww2>=1)&&(ss2>2*dd2)) vval+=(ss2-2*dd2)*(kk+1)*50;
  if (ww2>1) vval+=ww2*500;
  return(vval);
}

function IsWinning(ii, jj, kk, ccol)
{ var ll, ccount;
  ccount=0;
  for (ll=0; ll<4; ll++)
  { if (Fld[ll][jj][kk]==ccol) ccount++;
  }
  if (ccount==4) return(true);
  ccount=0;
  for (ll=0; ll<4; ll++)
  { if (Fld[ii][ll][kk]==ccol) ccount++;
  }
  if (ccount==4) return(true);
  ccount=0;
  for (ll=0; ll<=kk; ll++)
  { if (Fld[ii][jj][ll]==ccol) ccount++;
  }
  if (ccount==4) return(true);
  if (jj==kk)
  { ccount=0;
    for (ll=0; ll<4; ll++)
    { if (Fld[ii][ll][ll]==ccol) ccount++;
    }
    if (ccount==4) return(true);
  }
  if ((3-jj)==kk)
  { ccount=0;
    for (ll=0; ll<4; ll++)
    { if (Fld[ii][3-ll][ll]==ccol) ccount++;
    }
    if (ccount==4) return(true);
  }
  if (ii==kk)
  { ccount=0;
    for (ll=0; ll<4; ll++)
    { if (Fld[ll][jj][ll]==ccol) ccount++;
    }
    if (ccount==4) return(true);
  }
  if ((3-ii)==kk)
  { ccount=0;
    for (ll=0; ll<4; ll++)
    { if (Fld[3-ll][jj][ll]==ccol) ccount++;
    }
    if (ccount==4) return(true);
  }
  if (jj==ii)
  { ccount=0;
    for (ll=0; ll<4; ll++)
    { if (Fld[ll][ll][kk]==ccol) ccount++;
    }
    if (ccount==4) return(true);
  }
  if ((3-jj)==ii)
  { ccount=0;
    for (ll=0; ll<4; ll++)
    { if (Fld[ll][3-ll][kk]==ccol) ccount++;
    }
    if (ccount==4) return(true);
  }
  if ((ii==jj)&&(jj==kk))
  { ccount=0;
    for (ll=0; ll<4; ll++)
    { if (Fld[ll][ll][ll]==ccol) ccount++;
    }
    if (ccount==4) return(true);
  }
  if ((ii==kk)&&((3-jj)==kk))
  { ccount=0;
    for (ll=0; ll<4; ll++)
    { if (Fld[ll][3-ll][ll]==ccol) ccount++;
    }
    if (ccount==4) return(true);
  }
  if ((ii==jj)&&(jj==(3-kk)))
  { ccount=0;
    for (ll=0; ll<4; ll++)
    { if (Fld[ll][ll][3-ll]==ccol) ccount++;
    }
    if (ccount==4) return(true);
  }
  if (((3-ii)==kk)&&(jj==kk))
  { ccount=0;
    for (ll=0; ll<4; ll++)
    { if (Fld[3-ll][ll][ll]==ccol) ccount++;
    }
    if (ccount==4) return(true);
  }
  return(false);
}

function Select(ii, jj)
{ I_Sel=ii;
  J_Sel=jj;
  XMouseOver=ScreenFld[ii][jj][0];
  YMouseOver=ScreenFld[ii][jj][1];
  NeedBallDown=4;
}

function Clicked(xx, yy)
{ if (IsOver) return;
  if (NeedBallDown>0) return;
  MouseOut();
  MouseOver(xx, yy);
  if (XMouseOver>=0)
    NeedBallDown=4;
  window.document.OptionsForm.Moves.focus();
  window.document.OptionsForm.Moves.blur();

function MouseOver(xx, yy)
{ if (IsOver) return;
  if (XMouseOver>=0) return;
  if ((((MoveCount+Start0)%2==1)&&(IsPlayer[0]))||
      (((MoveCount+Start0)%2==0)&&(IsPlayer[1])))
  { if (NeedBallDown==0)
    { for (ii=0; ii<4; ii++)
      { for (jj=0; jj<4; jj++)
        { if ((ScreenFld[ii][jj][0]==xx)&&(ScreenFld[ii][jj][1]==yy))
          { if (Fld[ii][jj][3]==0)
            { if ((MoveCount+Start0)%2==1)
                window.document.images[13*yy+xx].src = Pic[1].src;
              else
                window.document.images[13*yy+xx].src = Pic[3].src;
              XMouseOver=xx;
              YMouseOver=yy;
              I_Sel=ii;
              J_Sel=jj;
            }
          }
        }
      }
    }
  }
}

function MouseOut()
{ if (IsOver) return;
  if (XMouseOver>=0)
  { if (NeedBallDown==0)
    { for (ii=0; ii<4; ii++)
      { for (jj=0; jj<4; jj++)
        { if ((ScreenFld[ii][jj][0]==XMouseOver)&&(ScreenFld[ii][jj][1]==YMouseOver))
            window.document.images[13*YMouseOver+XMouseOver].src = Pic[2+Fld[ii][jj][3]].src;
        }
      }
      XMouseOver=-1;
    }
  }

function RefreshPic(ii, jj, kk)
{ var xx=ScreenFld[ii][jj][0];
  var yy=ScreenFld[ii][jj][1];
  window.document.images[13*(yy+3-kk)+xx].src = Pic[2+Fld[ii][jj][kk]].src;
}

function RefreshScreen()
{ var ii, jj, kk, xx, yy;
  for (ii=0; ii<13; ii++)
  { for (jj=0; jj<13; jj++)
      window.document.images[13*ii+jj].src = Pic[0].src;
  }
  for (ii=0; ii<4; ii++)
  { for (jj=0; jj<4; jj++)
    { if (RotAng==0) { xx=3*ii+jj; yy=9-2*jj+ii; }
      if (RotAng==1) { xx=3*ii+3-jj; yy=9-2*jj+3-ii; }
      if (RotAng==2) { xx=3*(3-jj)+ii; yy=9-2*ii+(3-jj); }
      if (RotAng==3) { xx=3*(3-jj)+3-ii; yy=9-2*ii+3-(3-jj); }
      if (RotAng==4) { xx=3*(3-ii)+(3-jj); yy=9-2*(3-jj)+(3-ii); }
      if (RotAng==5) { xx=3*(3-ii)+3-(3-jj); yy=9-2*(3-jj)+3-(3-ii); }
      if (RotAng==6) { xx=3*jj+(3-ii); yy=9-2*(3-ii)+jj; }
      if (RotAng==7) { xx=3*jj+3-(3-ii); yy=9-2*(3-ii)+3-jj; }
      ScreenFld[ii][jj][0]=xx;
      ScreenFld[ii][jj][1]=yy-3;    
      for (kk=0; kk<4; kk++)
        window.document.images[13*(yy-kk)+xx].src = Pic[2+Fld[ii][jj][kk]].src;
    }
  }
  window.document.OptionsForm.Moves.value=MoveCount;
}

function Resize()
{ if(navigator.appName == “Netscape”) history.go(0);
}
//  End –>
</script>

</HEAD>

<BODY onResize=”javascript:Resize()”>

<DIV ALIGN=center>
<table noborder cellpadding=10 cellspacing=0 width=650 heigth=390>
<tr height=100%>
  <td width=60%>
    <table border cellpadding=10 cellspacing=0 bgcolor=#FFFFCC width=100%><tr><td>
      <table noborder cellpadding=0 cellspacing=0><tr><td>
      <script language=”JavaScript”>
      document.open(“text/plain”);
      for (j=0; j < 13; j++)
      { for (i=0; i < 13; i++)
          document.write(“<a href=\”javascript:Clicked(“+i+”,”+j+”)\” onMouseOver=\”MouseOver(“+i+”,”+j+”)\” onMouseOut=\”MouseOut()\”><IMG src=\”tt3d_0.gif\” border=0></a>”);
        document.writeln(“<BR>”);
      }
      document.close();
      </script>
      </td></tr></table>
    </td></tr></table>
  </td>
  <td width=40%><form name=”OptionsForm”>
      <table noborder cellpadding=0 cellspacing=0 width=100%>
      <tr><td> </td></tr>
      <tr><td>
        <table border cellpadding=2 cellspacing=0 width=100%>
        <tr><td><input type=radio name=”Red” checked value=”Red: Player” onClick=”javascript:SetOption(0,0)”> Red: Player</td></tr>
        <tr><td><input type=radio name=”Red” value=”Red: Computer” onClick=”javascript:SetOption(0,1)”> Red: Computer</td></tr>
        <tr><td> Level:
                <input type=radio name=”RedLevel” value=”1″ onClick=”javascript:SetLevel(0,1)”>1
                <input type=radio name=”RedLevel” checked value=”2″ onClick=”javascript:SetLevel(0,2)”>2
                <input type=radio name=”RedLevel” value=”3″ onClick=”javascript:SetLevel(0,3)”>3
                <input type=radio name=”RedLevel” value=”4″ onClick=”javascript:SetLevel(0,4)”>4
        </td></tr>
        </table>     
      </td></tr>
      <tr><td> </td></tr>
      <tr><td>
        <table border cellpadding=2 cellspacing=0 width=100%>
        <tr><td><input type=radio name=”Blue” value=”Blue: Player” onClick=”javascript:SetOption(1,0)”> Blue: Player</td></tr>
        <tr><td><input type=radio name=”Blue” checked value=”Blue: Computer” onClick=”javascript:SetOption(1,1)”> Blue: Computer</td></tr>
        <tr><td> Level:
                <input type=radio name=”BlueLevel” value=”1″ onClick=”javascript:SetLevel(1,1)”>1
                <input type=radio name=”BlueLevel” value=”2″ onClick=”javascript:SetLevel(1,2)”>2
                <input type=radio name=”BlueLevel” checked value=”3″ onClick=”javascript:SetLevel(1,3)”>3
                <input type=radio name=”BlueLevel” value=”4″ onClick=”javascript:SetLevel(1,4)”>4
        </td></tr>
        </table>
      </td></tr>
      <tr><td> </td></tr>
      <tr><td>
        <table border cellpadding=2 cellspacing=0 width=100%>
        <tr><td width=50%><input type=radio name=”Start” checked value=”Red” onClick=”javascript:SetOption(2,1)”> Red begins</td>
        <td><input type=radio name=”Start” value=”Blue” onClick=”javascript:SetOption(2,0)”> Blue begins</td></tr>
        </table>
      </td></tr>
      <tr><td> </td></tr>
      <tr><td>
        <table border cellpadding=2 cellspacing=0 width=100%><tr>
        <td width=30% align=center><input type=button value=”<-” width=60 style=”width:60″ onClick=”javascript:TurnLeft()”></td>
        <td width=40% align=center><input type=button value=”NEW” width=80 style=”width:80″ onClick=”javascript:Init()”></td>
        <td width=30% align=center><input type=button value=”->” width=60 style=”width:60″ onClick=”javascript:TurnRight()”></td>
        </tr></table>
      </td></tr>
      <tr><td> </td></tr>
      <tr><td>
        <table border cellpadding=2 cellspacing=0 width=100%><tr>
        <td width=40% align=center><input type=button value=”<<” width=80 style=”width:80″ onClick=”javascript:Back()”></td>
        <td width=20% align=center><input size=3 name=”Moves”></td>
        <td width=40% align=center><input type=button value=”>>” width=80 style=”width:80″ onClick=”javascript:Replay()”></td>
        </tr></table>
      </td></tr>
      </table>
  </form></td>
</tr>
</table>
</DIV>
<script language=”JavaScript”>
Init();
setInterval(“Timer()”,400);
</script>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: