src/lib/wordfind.js
function (puzzle, options, word) {
            var locations = [], height = options.height, width = options.width, wordLength = word.length, maxOverlap = 0; // we'll start looking at overlap = 0
            // loop through all of the possible orientations at this position
            for (var k = 0, len = options.orientations.length; k < len; k++) {
                var orientation = options.orientations[k], check = checkOrientations[orientation], next = orientations[orientation], skipTo = skipOrientations[orientation], x = 0, y = 0;
                // loop through every position on the board
                while (y < height) {
                    // see if this orientation is even possible at this location
                    if (check(x, y, height, width, wordLength)) {
                        // determine if the word fits at the current position
                        var overlap = calcOverlap(word, puzzle, x, y, next);
                        // if the overlap was bigger than previous overlaps that we've seen
                        if (overlap >= maxOverlap || (!options.preferOverlap && overlap > -1)) {
                            maxOverlap = overlap;
                            locations.push({ x: x, y: y, orientation: orientation, overlap: overlap });
                        }
                        x++;
                        if (x >= width) {
                            x = 0;
                            y++;
                        }
                    }
                    else {
                        // if current cell is invalid, then skip to the next cell where
                        // this orientation is possible. this greatly reduces the number
                        // of checks that we have to do overall
                        var nextPossible = skipTo(x, y, wordLength);
                        x = nextPossible.x;
                        y = nextPossible.y;
                    }
                }
            }
            // finally prune down all of the possible locations we found by
            // only using the ones with the maximum overlap that we calculated
            return options.preferOverlap ?
                pruneLocations(locations, maxOverlap) :
                locations;
        }
function (puzzle, options, word) {
            var locations = [], height = options.height, width = options.width, wordLength = word.length, maxOverlap = 0; // we'll start looking at overlap = 0
            // loop through all of the possible orientations at this position
            for (var k = 0, len = options.orientations.length; k < len; k++) {
                var orientation = options.orientations[k], check = checkOrientations[orientation], next = orientations[orientation], skipTo = skipOrientations[orientation], x = 0, y = 0;
                // loop through every position on the board
                while (y < height) {
                    // see if this orientation is even possible at this location
                    if (check(x, y, height, width, wordLength)) {
                        // determine if the word fits at the current position
                        var overlap = calcOverlap(word, puzzle, x, y, next);
                        // if the overlap was bigger than previous overlaps that we've seen
                        if (overlap >= maxOverlap || (!options.preferOverlap && overlap > -1)) {
                            maxOverlap = overlap;
                            locations.push({ x: x, y: y, orientation: orientation, overlap: overlap });
                        }
                        x++;
                        if (x >= width) {
                            x = 0;
                            y++;
                        }
                    }
                    else {
                        // if current cell is invalid, then skip to the next cell where
                        // this orientation is possible. this greatly reduces the number
                        // of checks that we have to do overall
                        var nextPossible = skipTo(x, y, wordLength);
                        x = nextPossible.x;
                        y = nextPossible.y;
                    }
                }
            }
            // finally prune down all of the possible locations we found by
            // only using the ones with the maximum overlap that we calculated
            return options.preferOverlap ?
                pruneLocations(locations, maxOverlap) :
                locations;
        }
function ( puzzle , options , word ) { var locations = [ ] , height = options . height , width = options . width , wordLength = word . length , maxOverlap = 0 ; // we'll start looking at overlap = 0 // loop through all of the possible orientations at this position for ( var k = 0 , len = options . orientations . length ; k < len ; k ++ ) { var orientation = options . orientations [ k ] , check = checkOrientations [ orientation ] , next = orientations [ orientation ] , skipTo = skipOrientations [ orientation ] , x = 0 , y = 0 ; // loop through every position on the board while ( y < height ) { // see if this orientation is even possible at this location if ( check ( x , y , height , width , wordLength ) ) { // determine if the word fits at the current position var overlap = calcOverlap ( word , puzzle , x , y , next ) ; // if the overlap was bigger than previous overlaps that we've seen if ( overlap >= maxOverlap || ( ! options . preferOverlap && overlap > - 1 ) ) { maxOverlap = overlap ; locations . push ( { x : x , y : y , orientation : orientation , overlap : overlap } ) ; } x ++ ; if ( x >= width ) { x = 0 ; y ++ ; } } else { // if current cell is invalid, then skip to the next cell where // this orientation is possible. this greatly reduces the number // of checks that we have to do overall var nextPossible = skipTo ( x , y , wordLength ) ; x = nextPossible . x ; y = nextPossible . y ; } } } // finally prune down all of the possible locations we found by // only using the ones with the maximum overlap that we calculated return options . preferOverlap ? pruneLocations ( locations , maxOverlap ) : locations ; }
Iterates through the puzzle and determines all of the locations where
the word will fit. Options determines if overlap should be maximized or
not.

Returns a list of location objects which contain an x,y cooridinate
indicating the start of the word, the orientation of the word, and the
number of letters that overlapped with existing letter.

@param {[[String]]} puzzle: The current state of the puzzle
@param {[Options]} options: The options to use when filling the puzzle
@param {String} word: The word to fit into the puzzle.
Iterates through the puzzle and determines all of the locations where the word will fit . Options determines if overlap should be maximized or not .