def main():
    """ Load configurations for the game """

    # create and load dictionary of points
    if not os.path.isfile(WORDSDICT):
        print "Generating dictionary..."
        create_dict()

    try:
        wordPoints = load_dict()

    except:
        print("Could not load the dictionary.")
        sys.exit()
    ''' get the list '''
    letters = raw_input("Type the letters: ")
    if len(letters) > 15:
        return "Hand should be at most 15 letters."
    handCombination = generate_combination(letters)
    """ show sorterd, with point """
    valid = []
    for comb in handCombination:
        if comb in wordPoints.keys():
            valid.append([comb, wordPoints[comb]])

    print "Possible words are:"
    for w in sorted(valid, reverse=True):
        print w[0] + " - Points: " + str(w[1])
Exemplo n.º 2
0
def main():

    """ Load configurations for the game """

    # create and load dictionary of points
    if not os.path.isfile(WORDSDICT):
        print "Generating dictionary..."
        create_dict()

    try:
        wordPoints = load_dict()

    except:
        print ("Could not load the dictionary.")
        sys.exit()

    """ get the list """
    letters = raw_input("Type the letters: ")
    if len(letters) > 15:
        return "Hand should be at most 15 letters."
    handCombination = generate_combination(letters)

    """ show sorterd, with point """
    valid = []
    for comb in handCombination:
        if comb in wordPoints.keys():
            valid.append([comb, wordPoints[comb]])

    print "Possible words are:"
    for w in sorted(valid, reverse=True):
        print w[0] + " - Points: " + str(w[1])
Exemplo n.º 3
0
def main():

    greetings()

    """ Load configurations for the game """

    # create and load dictionary of points
    if not os.path.isfile(WORDSDICT):
        create_dict()

    try:
        wordPoints = load_dict()
    except:
        return "Could not load the dictionary."

    try:
        lettersGame = create_list_letters()
    except:
        return "Could not create list of letters."

    """ set game variables """
    piecesLeft = len(lettersGame)
    numberOfPiecesHand = 5
    lettersDict = LETTERS

    lettersPC = ""
    pointsPC = 0
    wordsPC = []

    lettersHuman = ""
    pointsHuman = 0
    wordsHuman = []

    """ Game Loop """
    while piecesLeft >= 2 * numberOfPiecesHand:

        # computer's turn
        print("\n--> Computer's Turn:")
        points, word, lettersPC, lettersDict = computerTurn(
            wordPoints, lettersGame, numberOfPiecesHand, lettersDict, lettersPC
        )

        pointsPC += points
        wordsPC.append(word)
        printStatus(word, str(points), str(pointsPC))

        # human's turn
        print("\n--> Your Turn:")
        points, word, lettersHuman, lettersDict = humanTurn(
            wordPoints, lettersGame, numberOfPiecesHand, lettersDict, lettersHuman
        )

        pointsHuman += points
        wordsHuman.append(word)
        printStatus(word, str(points), str(pointsHuman))

        break

    """ Game Finalization """
    goodbye(str(pointsHuman), str(pointsPC), wordsHuman, wordsPC)
Exemplo n.º 4
0
def main():

    greetings()
    """ Load configurations for the game """

    # create and load dictionary of points
    if not os.path.isfile(WORDSDICT):
        create_dict()

    try:
        wordPoints = load_dict()
    except:
        return "Could not load the dictionary."

    try:
        lettersGame = create_list_letters()
    except:
        return "Could not create list of letters."
    """ set game variables """
    piecesLeft = len(lettersGame)
    numberOfPiecesHand = 5
    lettersDict = LETTERS

    lettersPC = ""
    pointsPC = 0
    wordsPC = []

    lettersHuman = ""
    pointsHuman = 0
    wordsHuman = []
    """ Game Loop """
    while piecesLeft >= 2 * numberOfPiecesHand:

        # computer's turn
        print("\n--> Computer's Turn:")
        points, word, lettersPC, lettersDict =  computerTurn(wordPoints, lettersGame, \
                            numberOfPiecesHand, lettersDict, lettersPC)

        pointsPC += points
        wordsPC.append(word)
        printStatus(word, str(points), str(pointsPC))

        # human's turn
        print("\n--> Your Turn:")
        points, word, lettersHuman, lettersDict =  humanTurn(wordPoints, lettersGame, \
                            numberOfPiecesHand, lettersDict, lettersHuman)

        pointsHuman += points
        wordsHuman.append(word)
        printStatus(word, str(points), str(pointsHuman))

        break
    """ Game Finalization """
    goodbye(str(pointsHuman), str(pointsPC), wordsHuman, wordsPC)