]> Skullheadx's Git Forge - word-hunt.git/commitdiff
very slow puzzle generator, data sifting, pruned out non letters
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Mon, 21 Nov 2022 22:45:36 +0000 (17:45 -0500)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Mon, 21 Nov 2022 22:45:36 +0000 (17:45 -0500)
Main/__pycache__/game.cpython-310.pyc
Main/data.py [new file with mode: 0644]
Main/game.py
Main/main.py
Main/prune.py
Main/pruned_words.json
Main/puzzle_generator.py
Main/setup.py

index fc0e4e0d83b010c1b93d1e6b65be3402f45887c1..2ff0263b2079f3038a55bce19f53589e2c2f5212 100644 (file)
Binary files a/Main/__pycache__/game.cpython-310.pyc and b/Main/__pycache__/game.cpython-310.pyc differ
diff --git a/Main/data.py b/Main/data.py
new file mode 100644 (file)
index 0000000..4181144
--- /dev/null
@@ -0,0 +1,79 @@
+from string import ascii_lowercase
+import json
+import random
+
+with open("pruned_words.json", 'r') as f:
+    word_list = json.load(f)
+alphabet = ascii_lowercase
+vowels = "aeiouy"  # y for special case like rhythm
+
+print("Strange Data about english words")
+
+letter_frequency = {letter: 0 for letter in alphabet}
+for word in word_list:
+    for letter in word:
+        letter_frequency[letter] += 1
+
+
+# print(letter_frequency)
+
+def get_value(a):
+    return letter_frequency[a]
+
+
+print(f"The most common letter is {max(letter_frequency, key=get_value)}.")
+print(f"The least common letter is {min(letter_frequency, key=get_value)}.")
+
+
+def get_second(a):
+    return a[1]
+
+
+total_letters = sum(letter_frequency.values())
+print(f"The total # of letters is {total_letters}.")
+
+letters = []
+weights = []
+for i in letter_frequency:
+    letters.append((round(letter_frequency[i] / total_letters * 100, 2), i))
+    weights.append(letter_frequency[i] / total_letters * 100)
+
+# print(letters)
+# print(weights)
+letters.sort(reverse=True)
+print("Percentage Composition")
+print(*letters)
+
+print("Choosing 16 letters using these weights")
+print(random.choices(alphabet, weights=weights, k=16))
+
+
+def non_vowel_substr(w):
+    vowel_indexes = []
+    for i, l in enumerate(w):
+        if l in vowels:
+            vowel_indexes.append(i)
+    longest_substr = 0
+    prev = -1
+    for val in vowel_indexes:
+        c = val - prev
+        if c > longest_substr:
+            longest_substr = c
+            # print(w[prev:val])
+        prev = val
+    c = len(w) - prev
+    if c > longest_substr:
+        longest_substr = c
+        # print(w[prev:len(w)])
+
+    return longest_substr - 1
+
+
+longest = 0
+longest_value = ""
+for word in word_list:
+    l = non_vowel_substr(word)
+    if l >= longest:
+        longest_value = word
+        longest = l
+print(f'The longest substring that has no vowels is in "{longest_value}" and has length {longest}.')
index 712ab32581b660ffedd840b8e62ec95848d0aabc..f6bf5e0b959126776bd728baeaf4ad1c407e3372 100644 (file)
@@ -9,7 +9,7 @@ class Game:
     def __init__(self, imported_file_name=None):
         if imported_file_name is None:
             length, width = 4,4
-            self.letters = [random.choice(alphabet) for i in range(length  * width)]
+            self.letters = [random.choice(alphabet) for i in range(length * width)]
         else:
             with open(imported_file_name,"r") as f:
                 file_contents = f.read().split("\n")
index 3c0238c96c03a7f3a8b1cd2bc547b0887d254fe0..beee3c603060af13944e4d993db02f355066952c 100644 (file)
@@ -4,7 +4,7 @@ from setup import *
 from game import Game
 
 
-scene = Game("puzzles/templates/puzzle.txt")
+scene = Game()
 
 is_running = True
 delta = 1000/fps
index d4ea849bc15ccd742e1489b0eb71de328bdbc822..2bce199a1d7dda3cfb37306020f42865682e2890 100644 (file)
@@ -9,7 +9,7 @@ print(min(word_list, key=len))
 pruned_word_list = dict()
 
 for word in word_list:
-    if len(word) >= 3:
+    if len(word) >= 3 and "-" not in word:
         pruned_word_list[word] = 1
 
 
index b1b8540d717a5578324a4a5d4063af459d42b505..759d00392fda0e619fdbbaab682c82ea81201b21 100644 (file)
     "jealousness": 1,
     "jeames": 1,
     "jean": 1,
-    "jean-christophe": 1,
     "jeanette": 1,
     "jeany": 1,
     "jeanie": 1,
     "jeannette": 1,
     "jeannie": 1,
     "jeanpaulia": 1,
-    "jean-pierre": 1,
     "jeans": 1,
     "jear": 1,
     "jebat": 1,
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a78249e0bfe09fa1fb59359bcf9597ca2785ac0e 100644 (file)
@@ -0,0 +1,66 @@
+from random import choice
+from queue import Queue
+from string import ascii_lowercase
+import json
+
+length, width = 4, 4
+with open("pruned_words.json", 'r') as f:
+    word_list = json.load(f)
+alphabet = ascii_lowercase
+weights = [8.464812190575197, 1.8290213382006486, 4.377463842181293, 3.238497204031964, 10.77374340292079,
+           1.1220794892410257, 2.3639146242995768, 2.64283880414943, 8.95783107183879, 0.15584834882323761,
+           0.7667338050095298, 5.577710795267362, 3.009862381185312, 7.195528282969081, 7.200021981915867,
+           3.2521214123037474, 0.16781246449047607, 7.0440305216612025, 7.162211941733039, 6.607483411238427,
+           3.7628002442053465, 0.945823450296398, 0.6405381447778209, 0.29978982655180736, 2.0193881642839093,
+           0.4220928558487209]
+
+class Tile:
+
+    def __init__(self, x, y, letter):
+        self.letter = letter
+        self.neighbors = set()
+        for i in range(-1, 2):
+            for j in range(-1, 2):
+                if not (i == 0 and j == 0):
+                    tx, ty = x + i, y + j
+                    if (0 <= tx < width) and (0 <= ty < length):
+                        self.neighbors.add((tx, ty))
+
+
+def find_words(b):
+    words = set()
+    q = Queue()
+    for i in b:
+        q.put((b[i].letter, i, set()))
+
+    while not q.empty():
+        word, current, seen = q.get()
+        if current in seen:
+            continue
+        else:
+            seen.add(current)
+
+        if len(word) >= length * width:
+            break
+
+        if word in word_list:
+            words.add(word)
+
+        for i in b[current].neighbors:
+            q.put((word + b[i].letter, i, seen.copy()))
+    return words
+
+
+board = {(i, j): Tile(i, j, choice(alphabet)) for i in range(width) for j in range(length)}
+
+for i, val in enumerate(board.values()):
+    print(val.letter, end=" ")
+    if (i + 1) % 4 == 0:
+        print()
+
+print(find_words(board))
+# c l t a
+# h x d o
+# r a m u
+# t f k g
+# {'haku', 'aku', 'trah', 'toma', 'fam', 'gud', 'frt', 'amdt', 'kadu', 'aft', 'rad', 'adam', 'tao', 'arf', 'fax', 'art', 'max', 'rat', 'adat', 'oda', 'dao', 'tod', 'tax', 'taku', 'mat', 'kudo', 'rha', 'omar', 'dar', 'douma', 'haft', 'moat', 'fram', 'dum', 'odum', 'rah', 'doug', 'moa', 'chat', 'xat', 'udo', 'dart', 'fado', 'kaf', 'mota', 'mud', 'dug', 'trad', 'odax', 'tom', 'cham', 'amu', 'xcl', 'udom', 'kam', 'raku', 'tar', 'toad', 'hld', 'tou', 'rada', 'mot', 'arx', 'trf', 'mad', 'mudar', 'mart', 'toa', 'mxd', 'maku', 'duo', 'cha', 'mado', 'toda', 'doum', 'mfr', 'tra', 'haf', 'oat', 'chart', 'dat', 'rax', 'dom', 'doat', 'adar', 'gum', 'dak', 'dato', 'ada', 'chad', 'adm', 'duka', 'marx', 'fart', 'chaft', 'mug', 'hat', 'ham', 'dumka', 'tad', 'ram', 'kat', 'tfr', 'kart', 'tram', 'oud', 'hcl', 'dam', 'ado', 'daft', 'dot', 'mah', 'duma', 'moud', 'raft', 'mar', 'dah', 'atom', 'far', 'mou', 'tam', 'hart', 'tahr', 'frat', 'hak', 'adatom', 'fra', 'char', 'toug', 'had', 'oad', 'fad', 'fat', 'doa', 'mod'}
index 5b5364e744b25e957cad93d0d53bd278821cfd33..0a2c2f7a0311ce6a77c61270381485ce48b7e8c8 100644 (file)
@@ -8,12 +8,10 @@ import random
 with open("pruned_words.json", 'r') as f:
     word_list = json.load(f)
 
-
-
 pygame.init()
 SCREEN_WIDTH, SCREEN_HEIGHT = 720, 720
 dimensions = pygame.Vector2(SCREEN_WIDTH, SCREEN_HEIGHT)
-center = pygame.Vector2(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)
+center = pygame.Vector2(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
 screen = pygame.display.set_mode(dimensions, pygame.RESIZABLE)
 
 pygame.display.set_caption("Word Hunt")
@@ -21,13 +19,20 @@ clock = pygame.time.Clock()
 fps = 60
 
 alphabet = string.ascii_lowercase
+weights = [8.464812190575197, 1.8290213382006486, 4.377463842181293, 3.238497204031964, 10.77374340292079,
+           1.1220794892410257, 2.3639146242995768, 2.64283880414943, 8.95783107183879, 0.15584834882323761,
+           0.7667338050095298, 5.577710795267362, 3.009862381185312, 7.195528282969081, 7.200021981915867,
+           3.2521214123037474, 0.16781246449047607, 7.0440305216612025, 7.162211941733039, 6.607483411238427,
+           3.7628002442053465, 0.945823450296398, 0.6405381447778209, 0.29978982655180736, 2.0193881642839093,
+           0.4220928558487209]
+
 
 class Colour:
-    WHITE = (255,255,255)
-    GRAY = (255/2,255/2,255/2)
-    LIGHT_GRAY = (255*2/3,255*2/3,255*2/3)
-    BLACK = (0,0,0)
+    WHITE = (255, 255, 255)
+    GRAY = (255 / 2, 255 / 2, 255 / 2)
+    LIGHT_GRAY = (255 * 2 / 3, 255 * 2 / 3, 255 * 2 / 3)
+    BLACK = (0, 0, 0)
     RED = (255, 0, 0)
-    GREEN = (0,255,0)
-    BLUE = (0,0,255)
-    YELLOW = (255/2, 255/2,0)
+    GREEN = (0, 255, 0)
+    BLUE = (0, 0, 255)
+    YELLOW = (255 / 2, 255 / 2, 0)