Пример #1
0
def main():
    """
    Main program: 
    Find all words of length 3 or greater on a boggle board. Converts list to
    a set, then back to list, which is then sorted. This eliminates duplicates
    and orders the contents of list results alphabetically
    
    Arguments:
        none (but expect two arguments on command line)
        
    Returns:
        nothing
        
    Effects:
        prints found words in alphabetical order, without duplicates,
        one word per line, then prints the total score
    """
    prefix = ""
    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):
            find_words(board, row, col, prefix, results)
    final_score = 0
    results = sorted(list(set(results)))
    for word in results:
        final_score += score(word)
        print (word, score(word))
    print ("Total score:", final_score)
Пример #2
0
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)
    global results
    results = [] 
    l = [0,1,2,3]
    for r in l:
        for c in l:
            find_words(board, r, c)
    comeout = duplicate(results)
    total = 0
    for word in comeout:
        numb = score(word)
        total += numb
        print(word + " " + str(numb))
    print("Total score: " + str(total))
Пример #3
0
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):
            find_words(board,row,col,'',results)
    
    single_results = duplicates(results)   # get non-duplicate list 
            
    total_score = 0
    for word in single_results:   # print found words with point values
        print(word, score(word))
        total_score += score(word)

    print('Total score: ', total_score)
Пример #4
0
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')
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
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()
	dict_file = "dict.txt"
	try:
		dict_f = open(dict_file,'r')
	except:
		print("dictionary file error")
		input()
		exit(1)
		
	game_dict.read( dict_f )
		
	while True:
		board_text = input("Please enter the board text(16 charaters): ")
		if not len(board_text) == 16:
			print("Please make sure there are 16 charaters!")
			input()
			continue
		
		board = BoggleBoard(board_text)
		results = [ ] 
		i=0	#as a counter to calculate the row and col
		for letter in board_text:	#search one letter by one letter
			find_words(board,(i//4),(i%4),letter, results)	#call the function
			i+=1
		results=sorted(results)	#sort the results
		sco=0	#as a sum of the score
		for elem in results:
			#if score(elem) >= 1:
			print(elem,score(elem))	#Print each word and its score
			sco+=score(elem)	#calculate the sum score
		print("Total score: ",sco)	#print the total score
		if input("Enter 'e' to exit, anything else to continue: ") == 'e':
			break
Пример #8
0
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)
Пример #9
0
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)
Пример #10
0
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 = [ ] 
    total_score = 0
    for i in range(0,4):
        for j in range(0,4):
            find_words(board,i,j,'',results)
    results = deadu(results)
    for word in results:
        print(word + ' ' + str(score(word)))
        total_score += score(word)
    print("Total Score " + str(total_score))
Пример #11
0
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)