! Copyright (C) 2022 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays ascii assocs assocs.extras colors
-combinators hashtables io io.styles kernel math random ranges
-sequences sequences.extras sets sorting strings
-wordlet.word-list ;
+USING: accessors arrays ascii assocs assocs.extras base91 colors
+combinators hashtables io io.encodings.binary
+io.encodings.string io.encodings.utf8 io.files io.styles kernel
+literals math random ranges sequences sequences.extras sets
+sorting splitting strings ;
IN: wordlet
+<PRIVATE
+
+CONSTANT: word-list $[
+ "vocab:wordlet/word-list.txt" binary file-contents
+ base91> utf8 decode "\n" split fast-set
+]
+
+PRIVATE>
+
TUPLE: wordlet-game secret-word chances guesses ;
: <wordlet-game> ( secret-word chances -- wordlet-game )
guess>chars
] with map concat members
[ background of ] assoc-map
- [ first ] collect-value-by
+ [ drop ] collect-value-by
[ [ color>n ] zip-with sort-values reverse first first ] assoc-map
CHAR: a CHAR: z [a..b] [ 1string COLOR: white ] { } map>assoc [ or ] assoc-merge ;
"guess: " write
readln >lower dup length 5 =
[ " needs to have 5 letters" append print read-guess ] unless
- dup word-hash-set in?
+ dup word-list in?
[ " not in the word list" append print read-guess ] unless ;
: check-winner? ( game -- ? )
"wordlet Started" print
word-list random 6 <wordlet-game> play-wordlet ;
-MAIN: play-random-wordlet-game
\ No newline at end of file
+MAIN: play-random-wordlet-game