<!-- Move Generator for Quarter of 19x19 Go Board  07/05/2000-03/17/2011 -->
<!-- -------------------------------------------------------- 09/10/2009 -->
<!-- www.davar.net/GO/MOVQUART.JS                                        -->
<!-- Copyright (C) 2000-2011 by Vladimir Veytsel                         -->
<!--
//       0 0 0   0   0   0   0   0   0   0   1   1
//       0 1 2   3   4   5   6   7   8   9   0   1

// 00   =9 | +---+---+---o---+---+---+---+---+---o
//         | |   |   |   |   |   |   |   |   |   |
// 01   +8 | +---+---+---+---+---+---+---+---+---+
//         | |   |   |   |   |   |   |   |   |   |
// 02   +7 | +---+---+---+---+---+---+---+---+---+
//         | |   |   |   |   |   |   |   |   |   |
// 03   +6 | +---+---+---+---+---+---+---+---+---+
//         | |   |   |   |   |   |   |   |   |   |
// 04   +5 | +---+---+---+---+---+---+---+---+---+
//         | |   |   |   |   |   |   |   |   |   |
// 05   +4 | +---+---+---+---+---+---+---+---+---+
//         | |   |   |   |   |   |   |   |   |   |
// 06   +3 | +---+---+---o---+---+---+---+---+---o
//         | |   |   |   |   |   |   |   |   |   |
// 07   +2 | +---+---+---+---+---+---+---+---+---+
//         | |   |   |   |   |   |   |   |   |   |
// 08   +1 | +---+---+---+---+---+---+---+---+---+
//         | |   |   |   |   |   |   |   |   |   |
// 09   +0 | +---+---+---+---+---+---+---+---+---+
// 10      +--------------------------------------
// 11       +0  +1  +2  +3  +4  +5  +6  +7  +8  =9

// i - Row    index (0- 11)
// j - Column index (0- 11)
// k - Array  index (0-143)  k=12*i+j
//     I.e., common sense notation [i,j] translates into linear [12*i+j]
//     that is directly supported by JavaScript (12 - size of the square)
//     Same notation is used also when "i" or/and "j" are constants
//     in order to make script readable in terms of Row/Column indexes.

// Problem=<problem>        // Name of <problem>.JS file with Move array
// Move = new Array(nn)     // Move array (see corresponding <problem>.JS)

// Last_Move=nn             // Last move up to which solution is generated
// Last_Move=0              // Generates problem only (no solution moves)

// Board  = new Array(144)  // Board corner array 12x12 (see BRDQUART.JS)
   Record = new Array( 70)  // Problem solution record 14x5 array

// Closing move is the very last move in the Move array that finalizes solution
   Closing_Move=Number(String(Move[Move.length-1]).substr(0,3))
   Solution_Comm=""  // Comment will be displayed only with Closing move

   // Generate hyperlinks to move numbers
   for (m=0;m<Move.length;m++)
       {Move_Numb=String(Move[m]).substr(0,3)
        if (!(isNaN(Move_Numb)))  // Check for digital move number
           {if (Move_Numb.substr(0,1)==" ")     // Remove leading spaces that
               Move_Numb=Move_Numb.substr(1,2)  // caused script to crash on
            if (Move_Numb.substr(0,1)==" ")     // skipping to forward moves
               Move_Numb=Move_Numb.substr(1,1)  // 09/10/2009  LBI, NJ
            if (Move_Numb<15)     // Fill next element of left Record column
               {Record[5*(Move_Numb-1)+0]="<TR><TD WIDTH=20 ALIGN=Right><A HREF='PRBQUART.HTM?"+Problem+","+Move_Numb+"' onMouseOver=\"window.status='Show solution up to the move"+Move_Numb+"'; return true\" onMouseOut=\"window.status=''; return true\"><FONT COLOR=Teal>"+Move_Numb+"</FONT></A></TD>"
                Record[5*(Move_Numb-1)+1]="<TD></TD>"
               }
            if ((Move_Numb>14)&&  // Fill next element of right Record column
                (Move_Numb<29))   // Move record is kept only up 28-th move
               {Record[5*(Move_Numb-15)+2]="<TD> </TD>"
                Record[5*(Move_Numb-15)+3]="<TD WIDTH=20 ALIGN=Right><A HREF='PRBQUART.HTM?"+Problem+","+Move_Numb+"' onMouseOver=\"window.status='Show solution up to the move "+Move_Numb+"'; return true\" onMouseOut=\"window.status=''; return true\"><FONT COLOR=Teal>"+Move_Numb+"</FONT></A></TD>"
                Record[5*(Move_Numb-15)+4]="<TD></TD></TR>"
               }
           }
       }

   Capture=false  // Autogenerates "Capture" move comment where appropriate
      Stop=false  // Stops move generation when Closing_Move is reached
         m=0      // Index within the Move array (linear)

   // Generate problem moves
   while (!(Stop))

         {m=m+1  // Moves start with "1" (Move[0] is a problem name)
          Move_Numb=String(Move[m]).substr(0,3)
          Hor_Coord=String(Move[m]).substr(4,2)
          Ver_Coord=String(Move[m]).substr(6,2)
          Move_Comm=String(Move[m]).substr(9)

          if (Move_Comm.substr(0,1)=="@")
             {Move_Comm=Move_Comm.substr(1)
              Move_Comm="<A HREF='../GLOSSARY.HTM#"+Move_Comm+"'>"+Move_Comm+"</A>"
             }
          if (Move_Comm.substr(0,1)=="%")
             {Move_Comm=Move_Comm.substr(1)
              Move_Comm="<A HREF='../GLOSSARY.HTM#"+Move_Comm+"'><I>"+Move_Comm+"</I></A>"
             }

          i=Number(9-Ver_Coord.substr(1))  // Row index in Board array
          j=Number(Hor_Coord.substr(1))+2  // Col index in Board array

          // Navigation bar
          if (Last_Move==0)
             {Navigation=                "<FONT COLOR=Gray>Problem</FONT> "+
              "<FONT COLOR=Green>|</FONT> <FONT COLOR=Gray>Prev</FONT> "+
              "<FONT COLOR=Green>|</FONT> <A HREF='PRBQUART.HTM?"+Problem+",1' onMouseOver=\"window.status='Show next move (one move forward)'; return true\" onMouseOut=\"window.status=''; return true\"><B>Next</B></A> "+
              "<FONT COLOR=Green>|</FONT> <A HREF='PRBQUART.HTM?"+Problem+","+Closing_Move+"' onMouseOver=\"window.status='Show entire problem solution sequence'; return true\" onMouseOut=\"window.status=''; return true\">Solution</A>"
             }
          if (Move_Numb==Math.min(Last_Move,Closing_Move))
             {if ((Move_Numb>0)&&
                  (Move_Numb<Closing_Move))
                 {Navigation=                "<A HREF='PRBQUART.HTM?"+Problem+",0' onMouseOver=\"window.status='Show initial problem setting'; return true\" onMouseOut=\"window.status='"+Move[0]+"'; return true\">Problem</A> "+
                  "<FONT COLOR=Green>|</FONT> <A HREF='PRBQUART.HTM?"+Problem+","+String(Number(Move_Numb)-1)+"' onMouseOver=\"window.status='Show previous move (one move back)'; return true\" onMouseOut=\"window.status=''; return true\">Prev</A> "+
                  "<FONT COLOR=Green>|</FONT> <A HREF='PRBQUART.HTM?"+Problem+","+String(Number(Move_Numb)+1)+"' onMouseOver=\"window.status='Show next move (one move forward)'; return true\" onMouseOut=\"window.status=''; return true\"><B>Next</B></A> "+
                  "<FONT COLOR=Green>|</FONT> <A HREF='PRBQUART.HTM?"+Problem+","+Closing_Move+"' onMouseOver=\"window.status='Show entire problem solution sequence'; return true\" onMouseOut=\"window.status=''; return true\">Solution</A>"
                 }
              if (Move_Numb==Closing_Move)
                 {Navigation=                "<A HREF='PRBQUART.HTM?"+Problem+",0' onMouseOver=\"window.status='Show initial problem setting'; return true\" onMouseOut=\"window.status=''; return true\">Problem</A> "+
                  "<FONT COLOR=Green>|</FONT> <A HREF='PRBQUART.HTM?"+Problem+","+String(Number(Move_Numb)-1)+"' onMouseOver=\"window.status='Show previous move (one move back)'; return true\" onMouseOut=\"window.status=''; return true\">Prev</A> "+
                  "<FONT COLOR=Green>|</FONT> <FONT COLOR=Gray>Next</FONT> "+
                  "<FONT COLOR=Green>|</FONT> <FONT COLOR=Gray>Solution</FONT>"
                 }
             }

          // Problem initial position
          if (Move_Numb==" +B")  // Place Black stone on the board
             Board[12*i+j]="<TD><IMG SRC='../BS.JPG' WIDTH=33 HEIGHT=33></TD>"
          if (Move_Numb==" +W")  // Place White stone on the board
             Board[12*i+j]="<TD><IMG SRC='../WS.JPG' WIDTH=33 HEIGHT=33></TD>"

          if ((Last_Move==0)&&  // Generate problem only (no solution moves)
              (Move_Numb==1))
             Stop=true

          // Problem solution moves
          if (Last_Move>0)
             {if ((Move_Numb==" -B")||  // Remove stone from the board
                  (Move_Numb==" -W"))
                 {Capture=true
                  Point="EC"
                  if (i==9) Point="EB"
                  if (j==2) Point="EL"
                  if ((i==9)&&(j==2)) Point="EBL"
                  if (((i==0)||(i==6))&&((j==5)||(j==11))) Point="HS"
                  Board[12*i+j]="<TD><IMG SRC='../"+Point+".JPG' WIDTH=33 HEIGHT=33></TD>"
                 }

              // Place next move stone on the board
              if (!(isNaN(Move_Numb)))
                 {if ((Capture)&&
                      (Move_Comm==""))
                     {Capture=false
                      Move_Comm="Capture"
                     }
                  Move_Numb=Number(Move_Numb)  // To make it comparable to the Last_Move
                  if (Move_Numb<15)            // Fill next element of left Record column
                     {if (Move_Numb==Last_Move)
                         {Record[5*(Move_Numb-1)+0]="<TR><TD ALIGN=Right><FONT COLOR=Red><U>"+Move_Numb+"</U></FONT></TD>"
                          Record[5*(Move_Numb-1)+1]="<TD>&nbsp;<FONT COLOR=Red>"+Hor_Coord+Ver_Coord+"&nbsp; "+Move_Comm+"</FONT></TD>"
                         }
                      else
                         {Record[5*(Move_Numb-1)+0]="<TR><TD ALIGN=Right><A HREF='PRBQUART.HTM?"+Problem+","+Move_Numb+"' onMouseOver=\"window.status='Show solution up to the move "+Move_Numb+"'; return true\" onMouseOut=\"window.status=''; return true\">"+Move_Numb+"</A></TD>"
                          Record[5*(Move_Numb-1)+1]="<TD>&nbsp;"+Hor_Coord+Ver_Coord+"&nbsp; "+Move_Comm+"</TD>"
                         }
                     }
                  if ((Move_Numb>14)&&  // Fill next element of right Record column
                      (Move_Numb<29))   // Move record is kept only up 28-th move
                     {Record[5*(Move_Numb-15)+2]="<TD> </TD>"
                      if (Move_Numb==Last_Move)
                         {Record[5*(Move_Numb-15)+3]="<TD ALIGN=Right><FONT COLOR=Red><U>"+Move_Numb+"</U></FONT></TD>"
                          Record[5*(Move_Numb-15)+4]="<TD>&nbsp;<FONT COLOR=Red>"+Hor_Coord+Ver_Coord+"&nbsp; "+Move_Comm+"</FONT></TD></TR>"
                         }
                      else
                         {Record[5*(Move_Numb-15)+3]="<TD ALIGN=Right><A HREF='PRBQUART.HTM?"+Problem+","+Move_Numb+"' onMouseOver=\"window.status='Show solution up to the move "+Move_Numb+"'; return true\" onMouseOut=\"window.status=''; return true\">"+Move_Numb+"</A></TD>"
                          Record[5*(Move_Numb-15)+4]="<TD>&nbsp;"+Hor_Coord+Ver_Coord+"&nbsp; "+Move_Comm+"</TD></TR>"
                         }
                     }
                  if (Move_Numb==Math.min(Last_Move,Closing_Move))
                     {Stop=true            // Stop at the Last_Move or Closing_Move
                      if (Move_Numb%2==0)
                         Board[12*i+j]="<TD BACKGROUND='../WS.JPG' WIDTH=33 HEIGHT=33 ALIGN=Center><FONT COLOR=Black><B><BLINK>"+Move_Numb+"</BLINK></B></FONT></TD>"
                      else
                         Board[12*i+j]="<TD BACKGROUND='../BS.JPG' WIDTH=33 HEIGHT=33 ALIGN=Center><FONT COLOR=White><B><BLINK>"+Move_Numb+"</BLINK></B></FONT></TD>"
                     }
                  else
                     if (Move_Numb%2==0)
                        Board[12*i+j]="<TD BACKGROUND='../WS.JPG' WIDTH=33 HEIGHT=33 ALIGN=Center><FONT COLOR=Black>"+Move_Numb+"</FONT></TD>"
                     else
                        Board[12*i+j]="<TD BACKGROUND='../BS.JPG' WIDTH=33 HEIGHT=33 ALIGN=Center><FONT COLOR=White>"+Move_Numb+"</FONT></TD>"
                 }
              if ((Move_Numb==Closing_Move)&&
                  (Comment  !=""))
                 Solution_Comm="<TR><TD COLSPAN=3><FONT COLOR=Navy>"+Comment+"</FONT></TD></TR>"
             }
         }
//-->

