Ejemplo n.º 1
0
    def main2(self):
        print 'old board at the beginningof 2'
        print self.old_board

        if self.solution:
            print "Winner: %s" % self.solution

            # Play the winning solution.
            self.board.create_board()
            print("I suggest you play the word:"+self.solution.word)

            #speech.speak(solution)
        else:
            pass
            # Should put letters back in bag.
            
        print board

        print 'old board at the beginningof 2 - 1'
        print self.old_board
        
        # Wait for "Enter", signifying the player has completed his/her turn.
        #self.wait = raw_input("Press enter when finished with move")

        # Get word that was just played on the board by fetching the new board state.
        self.update_board = Board()

        print 'old board at the beginningof 2 - 2'
        print self.old_board

        board1 = board_vision.get_board(self.classify,self.cam1)
        board2 = board_vision.get_board(self.classify,self.cam1)
        board3 = board_vision.get_board(self.classify,self.cam1)

        print 'old board at the beginningof 2 - 3'
        print self.old_board
        correctboard = [None] *15*15
        for i in range(len(board1)):
            if board1[i]==board2[i] or board1[i]==board3[i]:
                correctboard[i] = board1[i]
            elif board2[i]==board3[i]:
                correctboard[i] = board2[i]

        self.update_board.set_cells(correctboard)

        print 'old board at the beginningof 2 - 4'
        print self.old_board


        self.gui.full_board_update(copy.deepcopy(self.update_board.cells))

        print 'old board at the end gof 2'
        print self.old_board
Ejemplo n.º 2
0
def main():

    sadasdasdas
    gui = ScrabbleGUI.UserInterface()

    # Load the dictionary.
    dictionary = Dictionary.load(DICTIONARY_FILENAME)
    board = Board()

    # Keep track of the winning solution at each round.
    winners = []

    # List of letters we can still pick from.
    bag = get_full_bag()

    # Rack starts out empty. Keep track of current and last rack state.
    rack = ""
    old_rack = ""
    count = 0

    # Keep track of current and last board state,
    update_board = None
    old_board = Board()

    # Baxter's score
    my_score = 0

    #Create classifier
    classify = CNN_Model()

    # Create video feeds
    # cam = cv2.VideoCapture(1)
    # print cam.isOpened()



    # Keep playing until we're out of tiles or solutions.
    while count < 8:
        count+=1
        # Fill up our rack.
        print "Bag: %s" % "".join(bag)
        old_rack = rack

        # Updates rack with current rack from video feed.
        # cam1 = cv2.VideoCapture(1)
        # print cam1.isOpened()
        cam1 = 1

        rack = rack_vision.get_rack(classify,cam1)
        # cam1.release()
        cv2.destroyAllWindows()

        # Get a list of possible solutions. These aren't all necessarily legal.
        solutions = board.generate_solutions(rack, dictionary)

        solution = board.find_best_solution(solutions, dictionary)

        print solution.direction

        #gui.addword(solution.word,solution.row,solution.col,solution.,suggestion = True)

        if solution:
            print "Winner: %s" % solution

            # Play the winning solution.
            board.create_board()
            print("I suggest you play the word:"+solution.word)
            #speech.speak(solution)
        else:
            pass
            # Should put letters back in bag.
            
        print board
        
        # Wait for "Enter" press, signifying the player has completed his/her turn.
        wait = raw_input("Press enter when finished with move")

        # Get word that was just played on the board by fetching the new board state.
        update_board = Board()
        update_board.set_cells(board_vision.get_board(classify,cam1))
        
        move,letter_placed_on_board = board.get_played_word(update_board,old_board)

        print ("The word:"+ move +"was just played.")

        if (move == solution.word):
            print("Player listened to Baxter")
        else:
            print("defied Baxter")

        print "Baxter's Score: %d" % my_score

        generate_rack(rack,old_rack,bag)

        for char in letter_placed_on_board:
            rack = rack.replace(char,"")

        old_board = update_board
        print ("count:"+str(count))


    print "Baxter's Score: %d" % my_score
    print "Baxter's Words:"
    for rack, winner in winners:
        print "    %s: %s" % (rack, winner)