cup() { tput cup $(($row * 2)) $(($col * 4 - 2)) } stats() { vars=($(echo $(cat vars) | openssl aes-256-cbc -d -a -pbkdf2 -pass pass:wordle)) games="$((${vars[0]} + ${vars[1]} + ${vars[2]} + ${vars[3]} + ${vars[4]} + ${vars[5]}))" if [ $(($games + ${vars[6]})) -eq 0 ] then percent=0 else percent=$(echo "scale=2; $(echo "$games/($games+${vars[6]})*10000" | bc -l)/100" | bc -l) fi games=$(($games + ${vars[6]})) echo "
Win Percentage: $percent%
Games Played: $games
1 Guess: ${vars[0]}
2 Guesses: ${vars[1]}
3 Guesses: ${vars[2]}
4 Guesses: ${vars[3]}
5 Guesses: ${vars[4]}
6 Guesses: ${vars[5]}
Losses: ${vars[6]}
" > stats.html } cd ~ if [ ! -f "dtar_functions" ] then cd "$(dirname "$0")" if [ ! -f "dtar_functions" ] then curl "https://raw.githubusercontent.com/dtar-github/bash/refs/heads/main/dtar_functions" > dtar_functions chmod +x dtar_functions fi fi source "dtar_functions" cd "$(dirname "$0")" clear mkdir -p "Wordle_Data" cd "Wordle_Data" if [ -f "session" ] then if [ "$(cat session)" != "0" ] then echo "Previous Session Was Terminated :(" echo "Press enter to continue" read clear fi else echo "0" > session fi if [ ! -f "words.txt" ] then echo "Use ONLY lowercase letters" echo "Press '=' to delete, NOT the [Delete] button" echo "DO NOT press enter while typing words" echo read -p "Press enter to continue" clear echo "Curling Data..." echo curl https://gist.githubusercontent.com/dracos/dd0668f281e685bad51479e5acaadb93/raw/6bfa15d263d6d5b63840a8e5b64e04b382fdb079/valid-wordle-words.txt -o words.txt fi if [ ! -f "words.txt" ] then echo echo "Could Not Curl Data" echo;echo printf "\e[33mPlease Connect to the Internet to Curl Data\e[0m" echo;echo exit fi if [ ! -f "vars" ] then echo "0 0 0 0 0 0 0" | openssl aes-256-cbc -a -salt -pbkdf2 -pass pass:wordle > vars fi stats clear echo "Loading Words..." wins=0 losses=0 words=() array=(a b c d e f g h i j k l m n o p q r s t u v w x y z) while IFS= read -r line do words+=("$line") done < words.txt while true do stty echo clear input=() guess=${words[$(($RANDOM % ${#words[@]}))]} echo "1" > session word="" row=1 col=1 win=0 echo " Bash Wordle" echo "╔═══╦═══╦═══╦═══╦═══╗" echo "║ ║ ║ ║ ║ ║" echo "╠═══╬═══╬═══╬═══╬═══╣" echo "║ ║ ║ ║ ║ ║" echo "╠═══╬═══╬═══╬═══╬═══╣" echo "║ ║ ║ ║ ║ ║" echo "╠═══╬═══╬═══╬═══╬═══╣" echo "║ ║ ║ ║ ║ ║" echo "╠═══╬═══╬═══╬═══╬═══╣" echo "║ ║ ║ ║ ║ ║" echo "╠═══╬═══╬═══╬═══╬═══╣" echo "║ ║ ║ ║ ║ ║" echo "╚═══╩═══╩═══╩═══╩═══╝" while [ $win -eq 0 ] do statrow=$row cup read -n1 letter tput cup 14 0 case $letter in "=") cup echo " " if [ $col -gt 1 ] then ((col--)) word=${word:0:$((${#word} - 1))} cup echo " " fi ;; *) letter=$(echo "$letter" | awk '{print tolower($0)}') cup printf $letter word+=$letter ((col++)) if printf "%s\0" "${words[@]}" | grep -Fxqz -- "$word" then if [ $col -gt 5 ] then alpha=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) for ((col=1;col<6;col++)) do letter="${guess:$(($col - 1)):1}" index=($(index $letter)) ((alpha[${index[0]}]++)) done green="" for ((col=1;col<6;col++)) do letter="${word:$(($col - 1)):1}" if [ "${guess:$(($col - 1)):1}" == $letter ] then cup printf "\e[32m$letter\e[0m" green+=$letter index=($(index $letter)) ((alpha[${index[0]}]--)) else green+=" " fi done for ((col=1;col<6;col++)) do yellow=0 letter="${word:$(($col - 1)):1}" index=($(index $letter)) if [[ $guess =~ "$letter" ]] && [ "${guess:$(($col - 1)):1}" != $letter ] && [ ${alpha[${index[0]}]} -gt 0 ] then cup printf "\e[33m$letter\e[0m" ((alpha[${index[0]}]--)) fi done col=1 ((row++)) if [[ $green == $word ]] then ((wins++)) tput cup 14 0 echo "You Win " echo " " echo "Wins: $wins" echo "Losses: $losses" vars[$(($statrow - 1))]=$((${vars[$(($statrow - 1))]} + 1)) echo "${vars[@]}" | openssl aes-256-cbc -a -salt -pbkdf2 -pass pass:wordle > vars stats stty -echo echo "0" > session read win=1 else if [ $row -gt 6 ] then ((losses++)) tput cup 14 0 echo "You Lose " echo "Word: $guess" echo echo "Wins: $wins" echo "Losses: $losses" vars[6]=$((${vars[6]} + 1)) echo "${vars[@]}" | openssl aes-256-cbc -a -salt -pbkdf2 -pass pass:wordle > vars stats stty -echo echo "0" > session read win=2 fi fi word="" fi else if [ $col -eq 6 ] then tput cup 14 0 echo "'$word' is not in word list" fi fi esac if [ $col -gt 5 ] then for ((col=1;col<6;col++)) do cup echo " " done col=1 word="" fi done menu "Wordle" "Play_Again" "Exit" if [ $output -eq 2 ] then echo exit fi done