Le site arthur.bebou.netlib.re - retour accueil
git clone git://bebou.netlib.re/arthur.bebou
Log | Files | Refs |
oly (2179B)
1 #! /bin/sh 2 3 data=all.tsv 4 tmpd=$(mktemp -d);trap "rm -rf $tmpd" EXIT QUIT 5 red="\033[91m";green="\033[92m";blue="\033[94m" 6 gold="\x1b[93m";silver="\x1b[38;5;251m";bronze="\x1b[38;5;172m" 7 norm="\033[0m"; 8 9 colormedals() { 10 sed -E "s/Gold/$gold&\x1b[0m/" | 11 sed -E "s/Silver/$silver&\x1b[0m/" | 12 sed -E "s/Bronze/$bronze&\x1b[0m/" 13 } 14 15 rh() { 16 tail -n+2 17 } 18 19 pretty() { 20 cut -f4,5,6,7,8,9,10 | 21 column -ts' ' | 22 sed 's/ Summer Olympics//' 23 } 24 25 createquestion() { 26 id=$(< $data rh | cut -f1 | sort -u | shuf | head -n1) 27 grep -w "$id" $data > $tmpd/event 28 < $tmpd/event cut -f5 | uniq > $tmpd/answer 29 30 < $data rh | cut -f5 | grep -wv "$answer" | sort -u | shuf | head -n3 > $tmpd/other 31 cat $tmpd/other $tmpd/answer | shuf > $tmpd/options 32 33 < $tmpd/event cut -f7,9 | tr ' ' ' ' | uniq > $tmpd/ui-1 34 < $tmpd/event cut -f4 | grep -Eo "[0-9]{4}" | uniq > $tmpd/ui-2 35 < $data rh | grep -w "$(cat $tmpd/answer)" | 36 cut -f4 | grep -Eo "[0-9]{4}" | sort -nu > $tmpd/ui-3 37 < $tmpd/event grep -qw team \ 38 && echo "Team event" > $tmpd/ui-4 \ 39 || < $tmpd/event cut -f8 > $tmpd/ui-4 40 } 41 42 dispquestion() { 43 echo "------------------" 44 echo "current score : $score" 45 echo "lifes : $lifes" 46 echo "---" 47 48 find $tmpd -name "ui-*" | sort | head -n "$1" | 49 xargs paste | 50 column -ts' ' -o'|' | sed 's/|/ | /' | 51 colormedals 52 53 cat $tmpd/options | sed -E '1 i -hint-' | fzy > $tmpd/guess 54 } 55 56 score=0;maxscore=5;lifes=5 57 echo "-hint-" > $tmpd/guess 58 59 while [ "$lifes" -gt 0 ];do 60 clear 61 nbhints=0 62 createquestion 63 while [ "$(cat $tmpd/guess)" = "-hint-" ];do 64 [ "$nbhints" -lt 4 ] && nbhints=$(($nbhints+1)) 65 dispquestion "$nbhints" 66 done 67 if [ "$(cat $tmpd/guess)" = "$(cat $tmpd/answer)" ];then 68 echo "${green}correct$norm, answer was $(cat $tmpd/answer)" 69 score=$(( $score + $maxscore - $nbhints )) 70 else 71 echo "${red}wrong$norm, correct answer was : $(cat $tmpd/answer)" 72 lifes=$(( $lifes - 1 )) 73 fi 74 cat $tmpd/event | pretty | colormedals 75 read -p "enter to continue..." var 76 echo "-hint-" > $tmpd/guess 77 nbhints=0 78 rm -rf $tmpd/ui-* 79 done 80 81 echo "---------------" 82 echo "${blue}final score : $score$norm" 83 echo "$(date) $(whoami) $score" >> /var/www/arthur.bebou.netlib.re/jo-stats/highscores