-
Notifications
You must be signed in to change notification settings - Fork 0
/
spellcast-solver.py
134 lines (111 loc) · 4.62 KB
/
spellcast-solver.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
# Spellcast Solver
# vsulli
# 14 January 2024
# Program to automatically find the
# word with the most amount of points
# when it's your turn and use pyautogui
# to select those squares
# import necessary packages
import re
import time
import cv2
import mss
import pyautogui, sys
import numpy as np
from PIL import Image, ImageGrab
import extcolors
import pytesseract
# my files to import
from board import *
import config
from dictionary import *
from imageprocessing import *
from trie import *
from collections import defaultdict
from collections import OrderedDict
# from pytesseract import Output
# from imutils import contours
def read_in_dict(filename, word_list):
# reads in dictionary of valid words and returns list
with open(filename, "r") as f:
lines = [line.strip() for line in f]
return lines
def main():
user_input = 0
# read in the valid words to a list
word_list = []
word_list = read_in_dict("collins.txt", word_list ) #TODO reset to actual dict
trie = create_trie(word_list)
# read in first board
format_board_image()
# read letters and store in dict
read_image(config.game_board)
while user_input != 5:
# new gameplay loop
user_input = input("Please make a selection:\n" +
"1) Get Current Board\n" +
"2) Correct Board\n" +
"3) Find Best Word\n" +
"4) Print Current Board\n" +
"5) Update Dictionary\n" +
"6) Quit\n")
match user_input:
case "1":
# process image
format_board_image()
# read letters and store in dict
read_image(config.game_board)
case "2":
# correct letters, gems, DL, 2X status
correct_board(config.game_board)
case "3":
board_list = convert_game_board(config.game_board)
# gets top 5 words
top_5 = search_algo(board_list, word_list, trie, config.game_board)
word_selected = input("Enter the word you would like to play: \n")
# uses pyautogui to select word on monitor
navigate_board(word_selected, letter_positions, valid_words)
# add to user's total points
config.user_points += valid_words[word_selected][1]
print("------------------------------------------")
print("You added: " + str(valid_words[word_selected][1]) + " points.")
print("Total points: " + str(config.user_points))
print("------------------------------------------")
case "4":
print("INDEX LETTER 2X DL GEM TL \n" +
"------------------------------------------")
for i in range(1, 26):
if config.game_board.get(i)[1] | config.game_board.get(i)[2] | config.game_board.get(i)[3]:
print(i, config.game_board.get(i))
else:
print(i, config.game_board.get(i)[0])
print("------------------------------------------\n")
board_list = convert_game_board(config.game_board)
for row in board_list:
print(" ".join(row))
print("------------------------------------------\n")
case "5":
user_input2 = -1
while user_input2 != "1" or user_input2 != "2":
# TODO
user_input2 = input("Would you like to add(1) or remove words(2) from the dictionary?\n")
match user_input2:
# add new words to dictionary
case "1":
word = input("Type the word to remove from the dictionary: ")
addWord(word)
break
# remove words from dictionary
case "2":
word = input("Type the word to remove from the dictionary: ")
removeWord(word)
break
case _:
print("Invalid input.")
# TODO add option to change default coordinates of letters
case "6":
return
# default invalid input
case _:
print("Invalid input. Please select from the options above.")
main()