Esempio n. 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
Esempio n. 2
0
def interactive_play(board, word_list, hand, board_filename):
  genny = gen_blocks(board, word_list, hand)
  while True:
    # Grab and show four plays.
    top_blocks = tuple(islice(genny, 4))
    if not top_blocks:
      print('No moves available.')
      return

    chunk, plays = zip(*top_blocks)
    print_blocks(chunk, num_cols=4)
    # Ask for which play the user wants.
    print('Choose a move (1-%d) or leave blank for more choices' % len(chunk))
    resp = input_().strip()
    try:
      idx = int(resp) - 1
      assert 0 <= idx < len(chunk)
    except:
      continue
    # User made a valid choice, so write the boardfile and exit.
    choice = plays[idx]
    new_boardfile = '\n'.join(board_rows(board, choice, colors=False))
    with open(board_filename, 'w') as fh:
      print(new_boardfile, file=fh)
    return
  # TODO: handle this case better. It's unlikely, but it shouldn't error out.
  assert False, 'You looked at all the moves and chose none of them!'
Esempio n. 3
0
 def GET(self):
   web.header('Content-type', 'test/ascii')
   return '\n'.join(board_rows(board_holder[0], colors=False))