コード例 #1
0
ファイル: boggler.py プロジェクト: Pjmcnally/old_projects
def main():
    """
    Main program:
    Find all words of length 3 or greater on a boggle
    board.

    Args:
        none (but expect two arguments on command line)

    Returns:
        Nothing (but prints found words in alphabetical
        order, without duplicates, one word per line)
    """
    dict_file, board_text = getargs()
    game_dict.read(dict_file)
    f.close()
    board = BoggleBoard(board_text)
    board_height, board_width = 4, 4
    for x in range(board_width):
        for y in range(board_height):
            find_words(board, x, y, board.get_char(x, y))
    results = board.results
    set_results = set(results)
    results = list(set_results)
    results.sort()
    final = [(item, score(item)) for item in results]
    if final:
        for elem in final:
            print(elem[0], elem[1]) # the word and its count
        sum_list = [elem[1] for elem in final]
        print('Total score: ', sum(sum_list))
    else:
        print('None')
コード例 #2
0
ファイル: boggler.py プロジェクト: rvarley/boggler
def main():
    """
    Main program:
    Find all words of length 3 or greater on a boggle
    board.

    Args:
        none (but expect two command line arguments - a string of 16 alph characters
        and a dictionary file)

    Returns:
        Nothing, but prints found words in alphabetical
        order, without duplicates, one word per line.  Each word is scored and the sum of all words is printed
    """

    dict_file, board_text = getargs()
    game_dict.read(dict_file)
    board = BoggleBoard(board_text)

    rows = 4
    cols = 4
    results = []
    for row in range(rows):
        for col in range(cols):
            find_words(board, row, col, board.get_char(row, col), results)

    set_ = set(results)
    fin_list = list(set_)
    fin_list.sort()
    final = score(fin_list)
    print("Total score:", final)
コード例 #3
0
ファイル: sat_boggler.py プロジェクト: rvarley/boggler
def main():
    """
    Main program: 
    Find all words of length 3 or greater on a boggle 
    board. 
    Args:
        none (but expect two arguments on command line)
    Returns: 
        Nothing (but prints found words in alphabetical
        order, without duplicates, one word per line)
    """
    dict_file, board_text = getargs()
    game_dict.read( dict_file )
    
    board = BoggleBoard(board_text)
    
    results = [ ] 
    #game_dict = game_dict.read( dict_file ) #KS: added this to initialize
    init_find_words = find_words(board, 0, 0, board.get_char(0,0), results)
コード例 #4
0
ファイル: boggler-1t.py プロジェクト: rvarley/boggler
def main():
    """
    Main program: 
    Find all words of length 3 or greater on a boggle 
    board. 
    Args:
        none (but expect two arguments on command line)
    Returns: 
        Nothing (but prints found words in alphabetical
        order, without duplicates, one word per line)
    """
    dict_file, board_text = getargs()
    game_dict.read( dict_file )
    
    board = BoggleBoard(board_text)
    results = [ ] 
    
    for row in range(4):
        for col in range(4):
             init_find_words = find_words(board, row, col, board.get_char(row,col), results)

    print(results)
コード例 #5
0
ファイル: boggler.py プロジェクト: Pjmcnally/old_projects
def main():
    """Main program: Find all words of length 3 or greater on a boggle 
    board. 
    
    Parameters
    ---------
    Input:
    None
    pulls two arguments from the command line:
        "board" is the characters of board, in left-to-right reading order
        dict.txt is a file containing a list of words in alphabetical order
    
    Output:
    None 
        but prints found words in alphabetical order, without duplicates, 
        one word per line)"""

    
    global word_dict
    dict_file, board_text = getargs() # pulls args from command line
    word_dict = game_dict.read(dict_file)
    board = BoggleBoard(board_text)


    # Creates range to hit all possible x values on board.
    for x in range(board.board_height): 
        # Creates range to hit all possible y values on board.
        for y in range(board.board_width): 
            # runs recursive search beginning from each tile on the board.
            results.update(find_words(board, x, y, board.get_char(x,y)))
    final_list = score_list(results)
    total_score = 0
    for x, y in sorted(final_list): # Prints each word with associated score.
        print("{} {}".format(x,y))
        total_score += y
    print("Total score:", total_score)