Added word lists, generate random target words, only accept guesses that are valid words
This commit is contained in:
parent
ccdc7c1131
commit
a7ebe3dc50
5 changed files with 198190 additions and 1 deletions
|
@ -14,6 +14,10 @@ config/name="godot-wordle"
|
||||||
run/main_scene="res://src/Main.tscn"
|
run/main_scene="res://src/Main.tscn"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
Global="*res://src/Global.gd"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
window/size/width=640
|
window/size/width=640
|
||||||
|
|
59
src/Global.gd
Normal file
59
src/Global.gd
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
|
const MIN_LENGTH := 5
|
||||||
|
const MAX_LENGTH := 5
|
||||||
|
const GENERABLE_WORDS_FILENAME = "res://words/popular-filtered.txt"
|
||||||
|
const ALL_WORDS_FILENAME := "res://words/enable1.txt"
|
||||||
|
|
||||||
|
|
||||||
|
var generable_words: Dictionary
|
||||||
|
var all_words: Dictionary
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
randomize()
|
||||||
|
generable_words = parse_words(GENERABLE_WORDS_FILENAME, MIN_LENGTH, MAX_LENGTH)
|
||||||
|
all_words = parse_words(ALL_WORDS_FILENAME, MIN_LENGTH, MAX_LENGTH)
|
||||||
|
|
||||||
|
|
||||||
|
func parse_words(filename: String, min_len: int, max_len: int) -> Dictionary:
|
||||||
|
var dict := {}
|
||||||
|
for i in range(min_len, max_len + 1):
|
||||||
|
dict[i] = []
|
||||||
|
|
||||||
|
var file := File.new()
|
||||||
|
var error := file.open(filename, File.READ)
|
||||||
|
assert(not error)
|
||||||
|
while not file.eof_reached():
|
||||||
|
var line := file.get_line()
|
||||||
|
var length = line.length()
|
||||||
|
if length < min_len || length > max_len:
|
||||||
|
continue
|
||||||
|
dict[length].append(line.to_upper())
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
for key in dict.keys():
|
||||||
|
print(key, ": ", dict[key].size())
|
||||||
|
|
||||||
|
|
||||||
|
return dict
|
||||||
|
|
||||||
|
|
||||||
|
func generate_word(length: int, random_seed = null) -> String:
|
||||||
|
if typeof(random_seed) == TYPE_INT:
|
||||||
|
seed(random_seed)
|
||||||
|
|
||||||
|
var words_list := generable_words[length] as Array
|
||||||
|
|
||||||
|
return words_list[randi() % words_list.size()]
|
||||||
|
|
||||||
|
|
||||||
|
func is_valid_word(word: String) -> bool:
|
||||||
|
var length := word.length()
|
||||||
|
if length < MIN_LENGTH or length > MAX_LENGTH:
|
||||||
|
return false
|
||||||
|
|
||||||
|
var words_list := all_words[length] as Array
|
||||||
|
|
||||||
|
return word.to_upper() in words_list
|
|
@ -27,7 +27,7 @@ func _ready() -> void:
|
||||||
$C/V/LetterGrid.add_child(letter)
|
$C/V/LetterGrid.add_child(letter)
|
||||||
letters.append(letter_array)
|
letters.append(letter_array)
|
||||||
|
|
||||||
target_word = "godot".to_upper()
|
target_word = Global.generate_word(letter_count)
|
||||||
current_guess = 0
|
current_guess = 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +48,9 @@ func guess_entered(guess: String) -> void:
|
||||||
if guess.length() != letter_count:
|
if guess.length() != letter_count:
|
||||||
show_error("Word must be five characters.")
|
show_error("Word must be five characters.")
|
||||||
return
|
return
|
||||||
|
if not Global.is_valid_word(guess):
|
||||||
|
show_error("Not a recognized word.")
|
||||||
|
return
|
||||||
|
|
||||||
var letters_remaining = []
|
var letters_remaining = []
|
||||||
for letter in target_word:
|
for letter in target_word:
|
||||||
|
|
172823
words/enable1.txt
Normal file
172823
words/enable1.txt
Normal file
File diff suppressed because it is too large
Load diff
25300
words/popular-filtered.txt
Normal file
25300
words/popular-filtered.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue