Skip to content

Instantly share code, notes, and snippets.

@paniclater
Created August 13, 2012 19:51
Show Gist options
  • Select an option

  • Save paniclater/3343604 to your computer and use it in GitHub Desktop.

Select an option

Save paniclater/3343604 to your computer and use it in GitHub Desktop.
Fill Board function for PHP Word Search app
function fillBoard() {
//fill board with list by calling addWord for each word
//or return false if failed
global $word;
$direction = array("N", "S", "E", "W");
$itWorked = TRUE;
$counter = 0;
$keepGoing = TRUE;
while ($keepGoing) {
$dir = rand(0,3);
$result = addWord($word[$counter], $direction[$dir]);
if ($result == FALSE) {
// print "failed to place $word[$counter]";
$keepGoing = FALSE;
$itWorked = FALSE;
} //end if no result check
$counter++;
if ($counter >= count($word)) {
$keepGoing = FALSE;
} // end if
} // end while
return $itWorked;
} // end fill board
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment