drawi

<?php 
// read the necessary board data from board.txt
//$Board = rtrim(file_get_contents($BoardURL));
include "Snoopy.class.php";


// Parse the board.htm file to learn the score, number of moves, move bank, etc for each player, for later display under the game board.

$snoopy = new Snoopy;
$snoopy->fetchtext($BoardHTMURL);
$Board = rtrim($snoopy->results);

$BoardLines = explode("\n", $Board); // split the file into lines
//echo count($BoardLines);
foreach ($BoardLines as $BoardLine) {
$InputRow = explode(",", $BoardLine);  // split into "argument"  and "value"
switch ($InputRow[0]) {
// first check for the non-team specific items
case '"Seconds elapsed:"':
    $BoardInfo['SecondsElapsed'] = $InputRow[1]; break;
case '"Game start:"':
    $BoardInfo['GameStart'] = $InputRow[1]; break;
case '"Seconds between moves:"':
    // this is the frequency with which moves are awarded (adjusted by bonus if appropriate)
    $BoardInfo['MoveSeconds'] = $InputRow[1]; break;
case '"Dropped cap:"':
    $BoardInfo['MoveBankCap'] = $InputRow[1]; break;
case '"Seconds until next move:"':
    $BoardInfo['SecondsToMove'] = $InputRow[1]; break;
    
default:    
    // now look for Score, Moves, Bonus for the various teams
    // this requires splitting the "argument" into "team" and "subargument"    
    $ArgDivide = explode(" ", str_replace("\"", "", $InputRow[0]));
    switch ($ArgDivide[1]) {
    case 'Moves:':
        $BoardInfo['Moves'][$ArgDivide[0]] = $InputRow[1];
    case 'Bonus:':
        $BoardInfo['Bonus'][$ArgDivide[0]] = $InputRow[1];
    } // switch on $ArgDivide
    
} // switch
} // while reading file
//print_r($BoardInfo); echo "<br>printed BoardInfo<br>";
//echo "show " . $BoardInfo['SecondsElapsed'] . " elapsed<br>\n";

// Now calculate the "Next Move At" time for each player (irrespective of move bank cap)
$GameSeconds = strtotime(substr($BoardInfo['GameStart'],1,-1)) + $BoardInfo['SecondsElapsed'];
//echo "GameSeconds = " . $GameSeconds . "<br>\n";
//echo "MoveSeconds = " . $BoardInfo['MoveSeconds'] . "<br>\n";

    foreach ($BoardInfo['Moves'] as $key => $val) {
    // $key is team name, $val is # of moves
    //   echo "$key = $val<br>\n";
        if ($BoardInfo['Bonus'][$key] > 0) {
            $BoardInfo['NextMove'][$key] = date("M j, H:i",$GameSeconds + (1-($BoardInfo['Moves'][$key] -floor($BoardInfo['Moves'][$key])))*($BoardInfo['MoveSeconds'] / $BoardInfo['Bonus'][$key]));
        } else { $BoardInfo['NextMove'][$key] = 0; }
    } //foreach team with Moves




// Now move on to the Board.txt file to learn the current location of flags and buffers

$snoopy2 = new Snoopy;
$snoopy2->fetchtext($BoardURL);
$Board = rtrim($snoopy2->results);

$Score = array();
$BoardLines = explode("\n", $Board); // split the file into lines
//echo count($BoardLines);
foreach ($BoardLines as $OneLine) {
    $Fields = explode("|", $OneLine); // split the line into individual fields
    if (($Fields[0] < 30) && ($Fields[1] < 30)) {
        $ThisTime = strtotime($Fields[4]); // the time this cell was established
            // check if the square is mature or not
            //use date("Z") to account for timezone different to UTC
        $CellTeam[$Fields[0]][$Fields[1]] = $Fields[3];
        if ($ThisTime + $TimeBetweenCaptures < time(U)-date("Z")) {
            // mature
            $CellMature[$Fields[0]][$Fields[1]] = "Old";
        } else {
            // immature
            $CellMature[$Fields[0]][$Fields[1]] = "New";
        }
        //CellTeam is used to determine color
        //CellValue is the flag value
        $CellValue[$Fields[0]][$Fields[1]] = $Fields[8];
        //Use CellOffset to validate banked move
        $CellOffset[$Fields[0]][$Fields[1]] = substr($Fields[6],-3,3).substr($Fields[7],-3,3);

        if ($Fields[3] != "!") {$Score[$Fields[3]]++;} // skip score of computer generated walls
    }
}

if (count($Score) > 0) {
    arsort($Score, SORT_NUMERIC);

    $j=1;
    foreach ($Score as $key => $val) {
    //   echo "$key = $val<br>\n";
       $Rank["$key"] = min($j,19);
       $j++;
    }
    reset($Score);
}

$MoveList = explode($MoveDelimiter, $MoveData);
for ($j=0; $j<count($MoveList)-1; $j++) {
    $MovePieces = explode("|", $MoveList[$j]);
    $Square = FindSquare($MovePieces[0], $MovePieces[3], $MovePieces[7]);
    $LatLon  = explode("x",$Square);
    $CellPlayer[$LatLon[0] % 30][$LatLon[1] % 30] = substr($MovePieces[0],0,1); // first initial
    //CellPlayer indicates the player who banked this move
    $MoveOffset = $MovePieces[4].$MovePieces[8];
    // Get GameBoard offset either from CellOffset or from default
    if ($CellOffset[$LatLon[0] % 30][$LatLon[1] % 30]) {
        $ThisCellOffset = $CellOffset[$LatLon[0] % 30][$LatLon[1] % 30];
    } else {
        $ThisCellOffset = $DefaultOffsets;
    }
    if ($MoveOffset != $ThisCellOffset) {
        $CellPlayer[$LatLon[0] % 30][$LatLon[1] % 30] .= "X";
    }
}

//Now draw the actual board
?>
<table>
<tr><td>
<STYLE type=text/css>
<!-- 
.mys    { FONT-SIZE: 8pt }
.mys TD { FONT-SIZE: 8pt }
.mys TH { FONT-SIZE: 8pt }

.lg2 {position: absolute; top: 15; left: 20; z-index: 2}
.cp2 {position: absolute; top: 520; left:  5; font-family: Arial; font-size: 10px; z-index: 2}
.bd2 {position: absolute; top: 20; left: 20; z-index: 1}
.mw2 {position: absolute;                     font-family: Arial; font-size: 11px; z-index: 3}
.cl2 {position: absolute; top: 610; left: 20; font-family: Arial;                  z-index: 3}
-->
</STYLE>
<!-- used to have A{text-decoration:none} in Style section -->

<table><tr><td>
<DIV id=board class=bd>
<FONT FACE=arial>
<TABLE class=mys cellSpacing=1 cellPadding=0 align=center bgColor=black border=0 frame=void>
  <TBODY>
  <TR align=middle>
    <TD width=18 height=14 bgcolor=black></TD>
    <TD width=18 bgColor=lightgrey>29</TD>
    <TD width=18 bgColor=lightgrey>28</TD>
    <TD width=18 bgColor=lightgrey>27</TD>
    <TD width=18 bgColor=lightgrey>26</TD>
    <TD width=18 bgColor=lightgrey>25</TD>
    <TD width=18 bgColor=lightgrey>24</TD>
    <TD width=18 bgColor=lightgrey>23</TD>
    <TD width=18 bgColor=lightgrey>22</TD>
    <TD width=18 bgColor=lightgrey>21</TD>
    <TD width=18 bgColor=lightgrey>20</TD>
    <TD width=18 bgColor=lightgrey>19</TD>
    <TD width=18 bgColor=lightgrey>18</TD>
    <TD width=18 bgColor=lightgrey>17</TD>
    <TD width=18 bgColor=lightgrey>16</TD>
    <TD width=18 bgColor=lightgrey>15</TD>
    <TD width=18 bgColor=lightgrey>14</TD>
    <TD width=18 bgColor=lightgrey>13</TD>
    <TD width=18 bgColor=lightgrey>12</TD>
    <TD width=18 bgColor=lightgrey>11</TD>
    <TD width=18 bgColor=lightgrey>10</TD>
    <TD width=18 bgColor=lightgrey><font color=lightgrey>0</font>9</TD>
    <TD width=18 bgColor=lightgrey><font color=lightgrey>0</font>8</TD>
    <TD width=18 bgColor=lightgrey><font color=lightgrey>0</font>7</TD>
    <TD width=18 bgColor=lightgrey><font color=lightgrey>0</font>6</TD>
    <TD width=18 bgColor=lightgrey><font color=lightgrey>0</font>5</TD>
    <TD width=18 bgColor=lightgrey><font color=lightgrey>0</font>4</TD>
    <TD width=18 bgColor=lightgrey><font color=lightgrey>0</font>3</TD>
    <TD width=18 bgColor=lightgrey><font color=lightgrey>0</font>2</TD>
    <TD width=18 bgColor=lightgrey><font color=lightgrey>0</font>1</TD>
    <TD width=18 bgColor=lightgrey><font color=lightgrey>0</font>0</TD>
    <TD width=18 bgcolor=black></TD>
  </TR>
  
<?php
    for ($i=29; $i>=0; $i--) {
        echo "<TR align=middle>\n";
        echo "    <TD height=14 bgColor=lightgrey>$i</TD>\n";
        for ($j=29; $j>=0; $j--) {
            //echo "    <TD bgcolor=".$CellColor[$Rank[$CellTeam[$i][$j]].$CellMature[$i][$j]].">";
            echo "    <TD ";
            if (strlen($CellTeam[$i][$j]) > 0) {
                // use some color here - based on team rank and square maturity
                if ($CellMature[$i][$j] == "New") { echo "  background=\"stipple.gif\" "; }
                echo "bgcolor=".$CellColor[$Rank[$CellTeam[$i][$j]].'New'].">";
            } else { 
                // make it white
                echo "bgcolor=white>"; 
            }

            // what to display in cell
            if ($CellValue[$i][$j]>0 || $CellPlayer[$i][$j]) {
                echo ($CellValue[$i][$j]>0 ? $CellValue[$i][$j] : "").$CellPlayer[$i][$j];
            } else {
                echo "&nbsp;&nbsp;";
            }
            echo "</TD>";
        }
        echo "    <TD bgColor=lightgrey>$i</TD>\n";
        echo "</TR>\n";
    }
?>  
  <TR align=middle>
    <TD height=14 bgcolor=black></TD>
    <TD bgColor=lightgrey>29</TD>
    <TD bgColor=lightgrey>28</TD>
    <TD bgColor=lightgrey>27</TD>
    <TD bgColor=lightgrey>26</TD>
    <TD bgColor=lightgrey>25</TD>
    <TD bgColor=lightgrey>24</TD>
    <TD bgColor=lightgrey>23</TD>
    <TD bgColor=lightgrey>22</TD>
    <TD bgColor=lightgrey>21</TD>
    <TD bgColor=lightgrey>20</TD>
    <TD bgColor=lightgrey>19</TD>
    <TD bgColor=lightgrey>18</TD>
    <TD bgColor=lightgrey>17</TD>
    <TD bgColor=lightgrey>16</TD>
    <TD bgColor=lightgrey>15</TD>
    <TD bgColor=lightgrey>14</TD>
    <TD bgColor=lightgrey>13</TD>
    <TD bgColor=lightgrey>12</TD>
    <TD bgColor=lightgrey>11</TD>
    <TD bgColor=lightgrey>10</TD>
    <TD bgColor=lightgrey>9</TD>
    <TD bgColor=lightgrey>8</TD>
    <TD bgColor=lightgrey>7</TD>
    <TD bgColor=lightgrey>6</TD>
    <TD bgColor=lightgrey>5</TD>
    <TD bgColor=lightgrey>4</TD>
    <TD bgColor=lightgrey>3</TD>
    <TD bgColor=lightgrey>2</TD>
    <TD bgColor=lightgrey>1</TD>
    <TD bgColor=lightgrey>0</TD>
    <TD bgColor=black></TD>
  </TR>
  </TBODY>
</TABLE>
</FONT>
</td></tr>
<P>&nbsp;
<tr><td>
<P>&nbsp;
<?php
if (count($Score) > 0) {
?>
<font face=arial>
<TABLE class=mys cellSpacing=1 cellPadding=1 align=center bgColor=black border=0 frame=void>
  <TBODY>
  <TR align=middle>
  <TD          height=14 bgcolor=white><font face=arial>&nbsp;Player&nbsp;</font></TD>
<?php
    $i=1;
    foreach ($Score as $key => $val) {
        //echo "<TD width=18 height=14 bgcolor=".$CellColor[min($i,8).'Old'].">$key</TD>\n";
        echo "<TD width=18 height=14 bgcolor=".$CellColor[min($i,19).'New'].">$key</TD>\n";
        $i++;
    }
    reset($Score);
?>  
  </TR>
  <TR>
  <TD  height=14 bgcolor=white><font face=arial>&nbsp;Score&nbsp;</font></TD>
<?php
    foreach ($Score as $key => $val) {
    //   echo "$key = $val<br>\n";
        echo "<TD bgcolor=white align=center>".$val."</TD>\n";
    }
    reset($Score);
?>  
  </TR>
  <TR>
  <TD          height=14 bgcolor=white><font face=arial>&nbsp;Moves&nbsp;</font></TD>
<?php
    foreach ($Score as $key => $val) {
        echo "<TD bgcolor=white align=center>" . sprintf("%3.1f",floor(10*$BoardInfo['Moves'][$key])/10) . "</TD>\n";
        //echo "<TD bgcolor=white align=center>".sprintf("%3.1f",floor(10*$BoardInfo["EMoves"])/10)."</TD>\n";
    }
    reset($Score);
?>  
  </TR>
  <TR>
  <TD          height=14 bgcolor=white><font face=arial>&nbsp;Bonus&nbsp;</font></TD>
<?php
    foreach ($Score as $key => $val) {
        echo "<TD bgcolor=white align=center>" . sprintf("%3.2f",$BoardInfo['Bonus'][$key]) . "</TD>\n";
        //echo "<TD bgcolor=white align=center>".sprintf("%3.2f",$BoardInfo["EBonus"])."</TD>\n";
    }
    reset($Score);
?>  
  </TR>
  <TR>
  <TD          height=14 bgcolor=white><font face=arial>&nbsp;Next Move At (UTC)&nbsp;</font></TD>
<?php
    foreach ($Score as $key => $val) {
        echo "<TD bgcolor=white align=center>" . $BoardInfo['NextMove'][$key] . "</TD>\n";
        //echo "<TD bgcolor=white align=center>&nbsp;".$NextMove["E"]."&nbsp;</TD>\n";
    }
    reset($Score);
?>  
  </TR>
  </TBODY>
</TABLE>
</font>
<?php
} // if there are teams to show - otherwise, just skip this entire table
?>  
</DIV>
</td></tr></table>
</td><td><p>

&nbsp;<a href="movedb.php?T=<?php echo $DefTeam;?>&P=<?php echo $DefPlayer;?>">Refresh</a><br>
<p>&nbsp;<p>
&nbsp;<a href="javascript: document.MWForm.scoreboard.click();">MW Scoreboard</a><br> 
<p>&nbsp;<p>
&nbsp;<a href="javascript: document.MWForm.db_search.click();">MW Recent Moves</a><br>
<p>&nbsp;<p>
&nbsp;<a href="currentevents.php?G=<?php echo $GameDataFields[0]; ?>">Current Events</a><br>
<p>&nbsp;<p>

<div align="left">
  <table border="0" cellpadding="4" cellspacing="4" style="border-collapse: collapse" bordercolor="#111111" id="AutoNumber1" bgcolor="#6699cc">
    <tr>
      <td>
      <p align="left"><font color="#FFFFFF" face="Verdana" size="2">
        An "X" after a player's initial indicates the move is stale (i.e. fractional coords don't match game board)
        <br>For example, because a neutral that was visited has since been captured.
          </font></td>
    </tr>
  </table>
</div>
</td></tr></table>