Esempio n. 1
0
 def POST(self):
   data = web.input(board={})
   try:
     board_holder[0] = make_board(data['board'].file)
   except ValueError as e:
     print 'Failed to make the board:'
     print e
   return render('', board_holder[0], None)
Esempio n. 2
0
def main():
  op = OptionParser(usage='%prog boardfile')
  opts, args = op.parse_args()
  if len(args) != 1:
    op.error('Must provide boardfile argument')
  word_list = read_dictionary(os.path.dirname(__file__))
  # Keep reading the boardfile, asking for a hand, then suggesting plays.
  while True:
    board = make_board(open(args[0]))
    try:
      hand = ask_for_hand()
      interactive_play(board, word_list, hand, args[0])
    except KeyboardInterrupt:
      print()
      break
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
          mergers.append('mtl')
        if r>0 and c+1<BOARD_SIZE and is_tile(r-1,c+1):
          mergers.append('mtr')
        if r+1<BOARD_SIZE and c>0 and is_tile(r+1,c-1):
          mergers.append('mbl')
        if r+1<BOARD_SIZE and c+1<BOARD_SIZE and is_tile(r+1,c+1):
          mergers.append('mbr')
      tclass = ' '.join(css_classes + mergers)
      tiles.append(tile_render(letter, tclass, r, c, value, clickable))
  return board_render(tiles)

words = read_dictionary(PATH)
render = web.template.frender(os.path.join(PATH,'static/template.html'),
                              globals={'board_as_html':board_as_html})
# Hacky mutable global storage for the current board.
board_holder = [make_board()]


class WWF(object):
  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()