-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordle.sh
executable file
·45 lines (40 loc) · 1.08 KB
/
wordle.sh
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
#!/bin/bash
dict=dicts.txt
function win {
clear
echo -e "${stack}\n"
echo "You won! Congraturations!"
exit 0
}
word=$(sed -n $(shuf -i 1-$(cat ${dict} | wc -l) -n 1)p ${dict})
[[ "${#word}" != 5 ]] && { echo "Unexpected error!"; exit 0; }
for tries in `seq 6`
do
while true
do
clear
[[ -n ${stack} ]] && echo -e "${stack}\n"
[[ -n ${err} ]] && echo "${err}"
echo -n "${tries}/6 >"; read answer
answer=${answer,,}
err=""
[[ "${#answer}" != 5 ]] && { err="String length must be 5!"; continue; }
cat ${dict} | grep "^${answer}$" || { err="Not in word list!"; continue; }
break
done
stack=$({ echo "${stack}"
for i in `seq 5`
do
search=$(echo -n "${answer}" | cut -c ${i})
correct=$(echo -n "${word}" | cut -c ${i})
{ echo -n "${word}" | grep "${search}" >/dev/null; } && {
[[ "${search}" = "${correct}" ]] && echo -n "\e[30;42m${search^^}\e[m" || echo -n "\e[30;43m${search^^}\e[m"
} || {
echo -n "\e[30;47m${search^^}\e[m"
}
done; })
clear
[[ "${answer}" = "${word}" ]] && win
done
echo -e "${stack}\n"
echo "You losed! Correct answer is \"${word}\""