Пример #1
0
def gen_blocks(board, word_list, hand):
  # Generates an almost-infinite sequences of (block, play) pairs.
  for score, words, play in top_moves(board, word_list, hand, 999,
                                      prune_words=False):
    header = ('%d %s' % (score, ', '.join(words))).center(15)
    block = [header] + board_rows(board, play)
    yield block, play
Пример #2
0
  def GET(self):
    args = web.input(html='',hand='',reset=False, play='')
    moves = None

    if args.play:
      play = ast.literal_eval(args.play)
      board = board_holder[0]
      for (r,c),x in play:
        board[r][c] = x.upper()

    if args.reset:
      board_holder[0] = make_board()

    if args.hand:
      moves = top_moves(board_holder[0],words,args.hand.upper())

    return render(args.hand, board_holder[0], moves)
Пример #3
0
def main():
  op = OptionParser(usage='%prog [-n 8] boardfile hand')
  op.add_option('-n', '--num-plays', type=int, default=8,
                help='Number of possible plays to display')
  op.add_option('-c', '--num-cols', type=int, default=4,
                help='Number of columns of plays to display')
  opts, args = op.parse_args()
  if len(args) != 2:
    op.error('Must provide boardfile and hand as arguments')
  board = make_board(open(args[0]))
  hand = args[1].upper()
  if (len(hand) < 1 or len(hand) > 7 or
      not all(x.isalpha() or x == '.' for x in hand)):
    op.error('Invalid hand: must be 1 to 7 letters or blanks (.)')
  word_list = read_dictionary(os.path.dirname(__file__))
  blocks = []
  for score, words, play in top_moves(board, word_list, hand, opts.num_plays):
    header = ('%d %s' % (score, ', '.join(words))).center(15)
    # TODO: add padding when len(header) > 15
    blocks.append([header] + board_rows(board, play))
  print_blocks(blocks, num_cols=opts.num_cols)