MoveList Board::allWordsFormedBy(const Move &move) const { MoveList ret; if (move.tiles().length() > 1) ret.push_back(move); if (move.action == Move::Place) { if (m_empty) { ret.push_back(move); } else { LetterString word; if (move.horizontal) { int i = 0; for (const auto& it : move.tiles()) { if (m_letters[move.startrow][i + move.startcol] == QUACKLE_NULL_MARK) { word.clear(); word += it; int startRow = 0; for (int j = move.startrow - 1; j >= 0; --j) { if (m_letters[j][i + move.startcol] == QUACKLE_NULL_MARK) { startRow = j + 1; break; } else { word = m_letters[j][i + move.startcol] + word; } } for (int j = move.startrow + 1; j < m_height; ++j) { if (m_letters[j][i + move.startcol] == QUACKLE_NULL_MARK) j = m_height; else word += m_letters[j][i + move.startcol]; } if (word.length() > 1) { ret.push_back(Move::createPlaceMove(startRow, (i + move.startcol), /* vertical */ false, word)); } } i++; } } else { int i = 0; for (const auto& it : move.tiles()) { if (m_letters[i + move.startrow][move.startcol] == QUACKLE_NULL_MARK) { word.clear(); word += it; int startColumn = 0; for (int j = move.startcol - 1; j >= 0; --j) { if (m_letters[i + move.startrow][j] == QUACKLE_NULL_MARK) { startColumn = j + 1; break; } else { word = m_letters[i + move.startrow][j] + word; } } for (int j = move.startcol + 1; j < m_width; ++j) { if (m_letters[i + move.startrow][j] == QUACKLE_NULL_MARK) j = m_width; else word += m_letters[i + move.startrow][j]; } if (word.length() > 1) { ret.push_back(Move::createPlaceMove((i + move.startrow), startColumn, /* horizontal */ true, word)); } i++; } } } } } for (auto& it : ret) { it.setTiles(sanitizedTilesOfMove(it)); it.setPrettyTiles(prettyTilesOfMove(it)); it.score = score(it); } return ret; }
void Board::updateBritishness() { Generator generator; LetterString word; for (int row = 0; row < m_height; row++) { for (int col = 0; col < m_width; col++) { bool isBritish = false; if (m_letters[row][col] != QUACKLE_NULL_MARK) { word.clear(); word += QUACKLE_ALPHABET_PARAMETERS->clearBlankness(m_letters[row][col]); for (int j = row - 1; j >= 0; --j) { if (m_letters[j][col] == QUACKLE_NULL_MARK) break; else word = QUACKLE_ALPHABET_PARAMETERS->clearBlankness(m_letters[j][col]) + word; } for (int j = row + 1; j < m_height; ++j) { if (m_letters[j][col] == QUACKLE_NULL_MARK) break; else word += QUACKLE_ALPHABET_PARAMETERS->clearBlankness(m_letters[j][col]); } if (word.length() > 1) { WordWithInfo wordWithInfo; wordWithInfo.wordLetterString = word; generator.storeWordInfo(&wordWithInfo); if (wordWithInfo.british) isBritish = true; } word.clear(); word += QUACKLE_ALPHABET_PARAMETERS->clearBlankness(m_letters[row][col]); for (int j = col - 1; j >= 0; --j) { if (m_letters[row][j] == QUACKLE_NULL_MARK) break; else word = QUACKLE_ALPHABET_PARAMETERS->clearBlankness(m_letters[row][j]) + word; } for (int j = col + 1; j < m_width; ++j) { if (m_letters[row][j] == QUACKLE_NULL_MARK) break; else word += QUACKLE_ALPHABET_PARAMETERS->clearBlankness(m_letters[row][j]); } if (word.length() > 1) { WordWithInfo wordWithInfo; wordWithInfo.wordLetterString = word; generator.storeWordInfo(&wordWithInfo); if (wordWithInfo.british) isBritish = true; } } m_isBritish[row][col] = isBritish; } } }