[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [gcompris/gsoc_pulkit_digital_electricity] src/activities/digital_electricity: digital_electricity: 
From:       Rudra Nil Basu <null () kde ! org>
Date:       2017-08-14 20:57:15
Message-ID: E1dhMQF-0005qI-PB () code ! kde ! org
[Download RAW message or body]

Git commit dfbce1eb7dcd7c58c2efa32e7dfa2fd08141e5c9 by Rudra Nil Basu.
Committed on 14/08/2017 at 13:33.
Pushed by rudranilbasu into branch 'gsoc_pulkit_digital_electricity'.

digital_electricity: Update answer checking

The answer checking has been changed from random test cases to all the
possible test cases.

For few levels, the answer checking is simply to check if the bulb is
glowing or not, for those, we are checking the value of:

determiningComponents[0].inputTerminals.itemAt(0).value

If it is 1, then the answer is correct, else false

For the others, primarily we are storing the values of the initial state
of the switches (to restore it back later) in:

var switch1InitialState = switch1.imgSrc
...

We then traverse through all the possible scenarios, for each of the
cases we are checking if the actual answer (stored in "operationResult")
is the same as the answer provided (denoted by whether the light is
glowing or not, determined by the value of
digitalLight.inputTerminals.itemAt(0).value)

If they do not match, we display that the answer is incorrect and reset
the values of the switces, as it was stored in switchxInitialState. If it
passes all the test cases, we display that the answer is correct and
move on to the next level

Also updated few intromessage for few levels, fixing grammatical errors

Signed-off-by: Rudra Nil Basu <rudra.nil.basu.1996@gmail.com>

M  +6    -4    src/activities/digital_electricity/Dataset.qml
M  +79   -102  src/activities/digital_electricity/digital_electricity.js

https://commits.kde.org/gcompris/dfbce1eb7dcd7c58c2efa32e7dfa2fd08141e5c9

diff --git a/src/activities/digital_electricity/Dataset.qml \
b/src/activities/digital_electricity/Dataset.qml index 18543420..4167b406 100644
--- a/src/activities/digital_electricity/Dataset.qml
+++ b/src/activities/digital_electricity/Dataset.qml
@@ -103,7 +103,7 @@ QtObject {
             playAreaComponentPositionX: [0.4],
             playAreaComponentPositionY: [0.3],
             introMessage: [
-                qsTr("The Digital light will glow when it's terminal is connected \
with an input of 1"), +                qsTr("The Digital light will glow when its \
                terminal is connected with an input of 1"),
                 qsTr("Turn the Digital light on using the inputs provided")
             ]
         },
@@ -129,8 +129,8 @@ QtObject {
             playAreaComponentPositionX: [0.4, 0.6],
             playAreaComponentPositionY: [0.3, 0.3],
             introMessage: [
-                qsTr("The OR Gate produces an output of 1  when at least one of the \
                input terminal is of value 1"),
-                qsTr("Turn the Digital light on using an AND gate and the inputs \
provided") +                qsTr("The OR Gate produces an output of 1 when at least \
one of the input terminal is of value 1"), +                qsTr("Turn the Digital \
light on using an OR gate and the inputs provided")  ]
         },
         // level 4
@@ -141,7 +141,9 @@ QtObject {
             wires: [ [0, 0, 2, 0], [2, 0, 3, 0], [3, 0, 4, 0]],
             playAreaComponentPositionX: [0.2, 0.3, 0.4, 0.6, 0.8],
             playAreaComponentPositionY: [0.1, 0.4, 0.3, 0.3, 0.4],
-            introMessage: []
+            introMessage: [
+                qsTr("NOTE: You can draw multiple wires from the output terminal of \
a component.") +            ]
         },
         // level 5
         {
diff --git a/src/activities/digital_electricity/digital_electricity.js \
b/src/activities/digital_electricity/digital_electricity.js index 6f5e734c..dc2eade0 \
                100644
--- a/src/activities/digital_electricity/digital_electricity.js
+++ b/src/activities/digital_electricity/digital_electricity.js
@@ -250,7 +250,7 @@ function isTutorialMode() {
 
 function checkAnswer() {
     // for levels with single light
-    if (currentLevel != 6 && currentLevel != 8) {
+    if (currentLevel != 6 && currentLevel != 8 && currentLevel != 10) {
         if (determiningComponents[0].inputTerminals.itemAt(0).value == 1)
             items.bonus.good('tux')
         else
@@ -260,46 +260,29 @@ function checkAnswer() {
         var switch1 = determiningComponents[0]
         var switch2 = determiningComponents[1]
 
-        switch1.imgSrc = "switchOn.svg"
-        switch2.imgSrc = "switchOff.svg"
-        updateComponent(switch1.index)
-        updateComponent(switch2.index)
+        var switch1InitialState = switch1.imgSrc
+        var switch2InitialState = switch2.imgSrc
 
-        if (digitalLight.inputTerminals.itemAt(0).value != 1) {
-            items.bonus.bad('tux')
-            return 0
-        }
-
-        switch1.imgSrc = "switchOff.svg"
-        switch2.imgSrc = "switchOn.svg"
-        updateComponent(switch1.index)
-        updateComponent(switch2.index)
-
-        if (digitalLight.inputTerminals.itemAt(0).value != 1) {
-            items.bonus.bad('tux')
-            return 0
-        }
+        for (var A = 0; A <= 1; A++) {
+            for (var B = 0; B <= 1; B++) {
+                switch1.imgSrc = A == 1 ? "switchOn.svg" : "switchOff.svg"
+                switch2.imgSrc = B == 1 ? "switchOn.svg" : "switchOff.svg"
 
-        switch1.imgSrc = "switchOn.svg"
-        switch2.imgSrc = "switchOn.svg"
-        updateComponent(switch1.index)
-        updateComponent(switch2.index)
+                updateComponent(switch1.index)
+                updateComponent(switch2.index)
 
-        if (digitalLight.inputTerminals.itemAt(0).value != 0) {
-            items.bonus.bad('tux')
-            return 0
-        }
+                var operationResult = A ^ B
 
-        switch1.imgSrc = "switchOff.svg"
-        switch2.imgSrc = "switchOff.svg"
-        updateComponent(switch1.index)
-        updateComponent(switch2.index)
-
-        if (digitalLight.inputTerminals.itemAt(0).value != 0) {
-            items.bonus.bad('tux')
-            return 0
+                if (operationResult != digitalLight.inputTerminals.itemAt(0).value) \
{ +                    switch1.imgSrc = switch1InitialState
+                    switch2.imgSrc = switch2InitialState
+                    updateComponent(switch1.index)
+                    updateComponent(switch2.index)
+                    items.bonus.bad('tux')
+                    return
+                }
+            }
         }
-
         items.bonus.good('tux')
     } else if (currentLevel == 8) {
         var switch1 = determiningComponents[0]
@@ -308,76 +291,70 @@ function checkAnswer() {
 
         var digitalLight = determiningComponents[3]
 
-        // A = 1, B = 0, C = 0
-        switch1.imgSrc = "switchOn.svg"
-        switch2.imgSrc = "switchOff.svg"
-        switch3.imgSrc = "switchOff.svg"
-
-        updateComponent(switch1.index)
-        updateComponent(switch2.index)
-        updateComponent(switch3.index)
-
-        if (digitalLight.inputTerminals.itemAt(0).value != 1) {
-            items.bonus.bad('tux')
-            return 0
-        }
-
-        // A = 0, B = 0, C = 0
-        switch1.imgSrc = "switchOff.svg"
-        switch2.imgSrc = "switchOff.svg"
-        switch3.imgSrc = "switchOff.svg"
-
-        updateComponent(switch1.index)
-        updateComponent(switch2.index)
-        updateComponent(switch3.index)
-
-        if (digitalLight.inputTerminals.itemAt(0).value != 0) {
-            items.bonus.bad('tux')
-            return 0
+        var switch1InitialState = switch1.imgSrc
+        var switch2InitialState = switch2.imgSrc
+        var switch3InitialState = switch3.imgSrc
+
+        for (var A = 0; A <= 1; A++) {
+            for (var B = 0; B <= 1; B++) {
+                for (var C = 0; C <= 1; C++) {
+                    switch1.imgSrc = A == 1 ? "switchOn.svg" : "switchOff.svg"
+                    switch2.imgSrc = B == 1 ? "switchOn.svg" : "switchOff.svg"
+                    switch3.imgSrc = C == 1 ? "switchOn.svg" : "switchOff.svg"
+
+                    updateComponent(switch1.index)
+                    updateComponent(switch2.index)
+                    updateComponent(switch3.index)
+
+                    var operationResult = A | (B & C)
+
+                    if (operationResult != \
digitalLight.inputTerminals.itemAt(0).value) { +                        \
switch1.imgSrc = switch1InitialState +                        switch2.imgSrc = \
switch2InitialState +                        switch3.imgSrc = switch3InitialState
+                        updateComponent(switch1.index)
+                        updateComponent(switch2.index)
+                        return
+                    }
+                }
+            }
         }
+        items.bonus.good('tux')
+    } else if (currentLevel == 10) {
+        var switch1 = determiningComponents[0]
+        var switch2 = determiningComponents[1]
+        var switch3 = determiningComponents[2]
 
-        // A = 0, B = 1, C = 0
-        switch1.imgSrc = "switchOff.svg"
-        switch2.imgSrc = "switchOn.svg"
-        switch3.imgSrc = "switchOff.svg"
-
-        updateComponent(switch1.index)
-        updateComponent(switch2.index)
-        updateComponent(switch3.index)
-
-        if (digitalLight.inputTerminals.itemAt(0).value != 0) {
-            items.bonus.bad('tux')
-            return 0
-        }
-
-        // A = 0, B = 0, C = 1
-        switch1.imgSrc = "switchOff.svg"
-        switch2.imgSrc = "switchOff.svg"
-        switch3.imgSrc = "switchOn.svg"
-
-        updateComponent(switch1.index)
-        updateComponent(switch2.index)
-        updateComponent(switch3.index)
-
-        if (digitalLight.inputTerminals.itemAt(0).value != 0) {
-            items.bonus.bad('tux')
-            return 0
-        }
-
-        // A = 0, B = 1, C = 1
-        switch1.imgSrc = "switchOff.svg"
-        switch2.imgSrc = "switchOn.svg"
-        switch3.imgSrc = "switchOn.svg"
-
-        updateComponent(switch1.index)
-        updateComponent(switch2.index)
-        updateComponent(switch3.index)
+        var digitalLight = determiningComponents[3]
 
-        if (digitalLight.inputTerminals.itemAt(0).value != 1) {
-            items.bonus.bad('tux')
-            return 0
+        var switch1InitialState = switch1.imgSrc
+        var switch2InitialState = switch2.imgSrc
+        var switch3InitialState = switch3.imgSrc
+
+        for (var A = 0; A <= 1; A++) {
+            for (var B = 0; B <= 1; B++) {
+                for (var C = 0; C <= 1; C++) {
+                    switch1.imgSrc = A == 1 ? "switchOn.svg" : "switchOff.svg"
+                    switch2.imgSrc = B == 1 ? "switchOn.svg" : "switchOff.svg"
+                    switch3.imgSrc = C == 1 ? "switchOn.svg" : "switchOff.svg"
+
+                    updateComponent(switch1.index)
+                    updateComponent(switch2.index)
+                    updateComponent(switch3.index)
+
+                    var operationResult = A ^ (B ^ C)
+
+                    if (operationResult != \
digitalLight.inputTerminals.itemAt(0).value) { +                        \
switch1.imgSrc = switch1InitialState +                        switch2.imgSrc = \
switch2InitialState +                        switch3.imgSrc = switch3InitialState
+                        updateComponent(switch1.index)
+                        updateComponent(switch2.index)
+                        return
+                    }
+                }
+            }
         }
-
         items.bonus.good('tux')
     }
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic