Пример #1
0
 @Override
 public String toString() {
   String info = word + ", score[" + wordScore + "] tiles to play on[";
   for (Tile t : tiles) {
     info += t.getLocation();
   }
   info += "]";
   return info;
 }
Пример #2
0
 /**
  * @param r
  * @param word
  * @return
  */
 private ScrabbleMove getScrabbleMove(final Regex r, final String word) {
   final ScrabbleMove move = new ScrabbleMove();
   final ArrayList<Integer> wordBonuses = new ArrayList<Integer>();
   final char[] chars = word.toCharArray();
   final int wordLength = word.length();
   int playoffX = r.start.x, playoffY = r.start.y;
   for (int i = 0; i < chars.length; i++) {
     if (String.valueOf(chars[i]).equalsIgnoreCase(r.playOff)) {
       // *
       // * Needs a lot of work as somtimes returns wrong position resulting in unplayable word
       // being place.
       // * Only happens in words where the playoff letter appears more than once.
       // *
       playoffY = r.vert ? playoffY - i : playoffY;
       playoffX = r.vert ? playoffX : playoffX - i;
       if (!r.vert && playoffX + wordLength > board.width()
           || r.vert && playoffY + wordLength >= board.height()) {
         continue;
       }
       break;
     }
   }
   move.word = word;
   for (int i = 0; i < wordLength; i++) {
     final int x = playoffX + (r.vert ? 0 : i), y = playoffY + (r.vert ? i : 0);
     final Tile tile = board.getTileAt(x, y);
     move.tiles.add(tile);
     if (tile.getLetterValue() > 0) {
       move.wordScore += tile.getLetterValue();
       continue;
     } else {
       move.wordScore += getLetterValue(chars[i]) * tile.getLetterBonus();
       wordBonuses.add(tile.getWordBonus());
     }
   }
   for (int bonus : wordBonuses) {
     move.wordScore = move.wordScore * bonus;
   }
   return move;
 }