-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainroutine.py
139 lines (100 loc) · 3.34 KB
/
mainroutine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python
import sys
import rospy
import numpy as np
import math
#import baxter_interface
import time
from board import Board
from dictionary import Dictionary
from bag import generate_rack, get_full_bag
import cv2
import speech
import dictionary
import direction
import board
import solution
import board_vision
import rack_vision
import ScrabbleGUI
#import testeroni
from Classification import CNN_Model
DICTIONARY_FILENAME = "dictionary"
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)
if __name__ == "__main__":
try:
main()
except rospy.ROSInterruptException:
pass