<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<LINK rel="stylesheet" type="text/css" media="screen" href="/~ray/styles/stylesheet.css">
<link rel="icon" type="image/png" href="/~ray/img/orb2.png">
<link rel="SHORTCUT ICON" type="image/png" href="/~ray/img/orb2.png">
<title>Boggle solver</title>
<style><!--

div.container {
  border: 1px dashed #333;
  background-color: #fff;
  padding-top: 0.5em;
}

div.spacer {
  clear: both;
  font-size: 1px;
}

div.float {
  float: left;
  width: 70px;
  padding: 10px;
}

div.float p {
   text-align: left;
}

div.items p:not(:target) {border: none}
div.items p:target {border: 1px; border-color: black; border-style:dotted;background-color:#bbf}


--></style>
</head>
<body>
<div id="hdr">
	<div id="hdrNav">
	        <a href="/">madrabbit</a>
	&raquo; <a href="/~ray/">ray</a>
	&raquo; <a href="/~ray/">boggle solver</a>
	</div>
</div>
<div id="body">
<?php
if ($_POST["board"] != "") {
  $board = $_POST["board"];
	# $board = "WITALQuRDNAEIUNINPESCETRAP";
	$board = strtolower($board);
	$realboard = "";
	print '<center><table cellpadding=0 cellspacing=0 border=1><tr><td><table border=0 bgcolor="#a2d6de"><tr><td align=center colspan=5>Boggle board</td></tr>';
	for ($i=0, $cube=0; $i<strlen($board) && $cube<25; $i++) {
		if ($board{$i} == ' ')
			continue;
		if ($cube % 5 == 0)
			print "\n<tr>";
		print "<td";
		if ($cube % 5 != 4) print ' width=20';
		print '>'. strtoupper($board{$i});
		$realboard=$realboard . $board{$i};
		if ($board{$i} == 'q') {
			print 'u';
			if ($board{$i+1} == 'u')
				$i++;
		}
		print '</td>';
		if ($cube % 5 == 4)
			print "</tr>";
		$cube++;
	}
	print "</td></tr></table></table></center><br>\n";
	
	$cmd = "/home/ray/bin/bog_linear 2>/dev/null /home/ray/bin/simplewordsofficial.linearized ";
	$cmd = $cmd . $realboard;
	$pipe = popen($cmd, "r");

	$wordcount=0;
	$rowcount=0;
	$previous_word=" ";
	while ($word = fgets($pipe, 1024)) {
		if ($wordcount==0)
			print '<div class="container"><div class="spacer">&nbsp;</div>';

		if ( ($word{0} != $previous_word{0}) && ($wordcount != 0) && ($rowcount != 0)) {
			while (12-($rowcount++))
				print '<br> ';
			$rowcount=0;
			print '</div>';
		}
		
		if ($rowcount % 12 == 0)
			print "\n" . '<div class="float">';

		print chop($word) . "<br> ";

		if ($rowcount % 12 == 11) {
			print '</div>';
			$rowcount=-1;
		}
		
		$wordcount++;
		$rowcount++;
		$previous_word=$word;
    	}

    	if ($wordcount % 12 != 11)
    		print '</div>';
    	print '<div class="spacer">&nbsp;</div></div>';

    	pclose($pipe);
} else {
?>
<form method="POST" name="testform">
<p>Enter the board cubes in the box below. Enter the 'Qu' cube as 'Q'. A sample board is filled in, to give you an idea.</p>
Board: <input type="text" length=29 size=31 name="board" value="WITAL QRDNA EIUNI NPESC ETRAP"> <input type="submit">
</form>
<?
}
?>
</div>
<div id="copyright">
Copyright &copy; 2003 - 2007, <a href="mailto:ray-website@madrabbit.org">Ray Lee</a>.<br>
</div>
</body>
</html>