-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorsetraining
executable file
·63 lines (55 loc) · 1.46 KB
/
morsetraining
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
counter=1
answer=""
points=0
dictionary=""
time=0.05
percernt=0
function usage() # Help usage --help
{
echo "Usage: $ $(basename $0) <parameters>"
echo
echo " PARAMETERS"
echo " -d dictionary_file (each line one word)"
echo " -t length of dot (default $time seconds)"
echo " --help (this help)"
echo
echo " EXAMPLES"
echo " $ $(basename $0) -d words1.txt"
}
while [ ! -z $1 ]; do
case $1 in
"-d") shift; dictionary=$1;;
"-t") shift; time=$1;;
"-h" | "--help") usage; exit 0;;
*) usage; exit 1;;
esac
shift
done
if [ "$dictionary" = "" ]; then echo "ERROR: No dictionary selected"; usage; exit 1; fi
echo "Train morse code game with dictionary file $dictionary"
echo "Answer «end» to finish"
echo
echo "Let's go. What are you listening to..."
while true; do
max=$(wc -l $dictionary | cut -f1 -d" ") # Number of lines in dictionary
n=`echo $(rand -M $max -s $(date +%s)) + 1 | bc` # From 0 to (M-1)
w=$(cat $dictionary | sed -n "$n p")
morsebeep -t $time -m $w
read -p "$counter) " answer
percent=`echo $points \* 100 / $counter | bc`
if [ "${answer,,}" = "${w,,}" ]; then
points=`echo $points + 1 | bc`
percent=`echo $points \* 100 / $counter | bc`
echo "Right. Points $points $percent%"
else
if [ "${answer,,}" = "end" ]; then
echo
echo "Total score $points"
exit 0
else
echo "ERROR. The answer is $w $percent%"
fi
fi
counter=`echo $counter + 1 | bc`
done