]> gitweb.factorcode.org Git - factor.git/commitdiff
quiz: Add country/flag quiz
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 28 Jan 2022 04:16:38 +0000 (22:16 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 28 Jan 2022 04:16:38 +0000 (22:16 -0600)
extra/quiz/quiz.factor

index add93fe99dc8c4e7d856bb5adc29e1985240eb0d..a0357f469052eaccccb757c26d5d33916de69f16 100644 (file)
@@ -3,7 +3,8 @@
 USING: accessors arrays assocs combinators combinators.smart
 continuations formatting io kernel math math.functions
 math.parser prettyprint quotations random sequences
-sequences.extras splitting strings unicode ;
+sequences.extras splitting strings unicode unicode.flags
+unicode.flags.images ;
 IN: quiz
 
 GENERIC: generate-question* ( question -- quot )
@@ -63,6 +64,8 @@ TUPLE: sqrt-question < number-response random-choices ;
 TUPLE: sq-question < number-response random-choices ;
 TUPLE: stack-shuffler < string-response n-shufflers ;
 TUPLE: state-capital-question < string-response ;
+TUPLE: country-from-flag < string-response n ;
+TUPLE: flag-from-countries < string-response n ;
 
 M: multiplication generate-question*
     [ count>> random ] [ n>> ] bi '[ _ random 2 + ] replicate
@@ -91,6 +94,12 @@ CONSTANT: state-capitals H{
 M: state-capital-question generate-question* drop state-capitals keys random '[ _ state-capital ] ;
 M: state-capital-question parse-response drop trim-blanks >title ;
 
+M: country-from-flag generate-question* drop valid-flags random '[ _ flag>unicode ] ;
+M: country-from-flag parse-response drop trim-blanks >title ;
+
+M: flag-from-countries generate-question* drop valid-flag-names random '[ _ unicode>flag ] ;
+M: flag-from-countries parse-response drop trim-blanks >title ;
+
 CONSTANT: stack-shufflers { dup 2dup drop 2drop swap over rot -rot roll -roll 2dup pick dupd }
 
 M: stack-shuffler generate-question*
@@ -181,6 +190,16 @@ M: sequence run-multiple-choice-quiz ( seq n -- questions )
         T{ stack-shuffler { n-shufflers 4 } }
     } 5 run-multiple-choice-quiz score-quiz ;
 
+: run-country-from-flag-quiz ( -- )
+    {
+        T{ country-from-flag { n 4 } }
+    } 5 run-multiple-choice-quiz score-quiz ;
+
+: run-flag-from-countries-quiz ( -- )
+    {
+        T{ flag-from-countries { n 4 } }
+    } 5 run-multiple-choice-quiz score-quiz ;
+
 : run-main-quiz ( -- )
     {
         T{ multiplication { count 10 } { n 10 } }