return word;
}
private Boolean checkCrossword(Line line, int position, Word word,
int wordIndex) {
Line crossingLine = board.getOrthogonalLine(line, position + wordIndex);
if (!hasAdjacentTiles(line, crossingLine)) {
return null;
}
// find start
int startPosition = line.getPosition();
while (startPosition > 0
&& crossingLine.getSquares()[startPosition - 1].getTile() != null) {
startPosition--;
}
// find end
int endPosition = line.getPosition();
while (endPosition < (crossingLine.getSquares().length - 1)
&& crossingLine.getSquares()[endPosition + 1].getTile() != null) {
endPosition++;
}
Tile newTile = word.getTiles().get(wordIndex);
// construct crossword and count tiles already on the board
StringBuilder sb = new StringBuilder();
int score = 0;
for (int i = startPosition; i <= endPosition; i++) {
if (i == line.getPosition()) {
// skip the new tile
sb.append(newTile.getLetter().getSymbol());
continue;
}
Tile tile = crossingLine.getSquares()[i].getTile();
sb.append(tile.getLetter().getSymbol());
score += tile.getLetter().getValue();
}
// count the new tile, possibly with booster