From 0574b4b19fc6592453a0323e2f927925d98ed76c Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 4 Apr 2020 14:18:37 +0200 Subject: Working win-check for every row --- qml/pages/FirstPage.qml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 8df939f..d19d1dd 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -26,6 +26,7 @@ ApplicationWindow { Column { property int bits: 4 + property var correct: new Array(bits) property var matrix: new Array(Math.pow(bits + 1, 2)) id: root @@ -37,14 +38,26 @@ ApplicationWindow { title: "Binary Fun" } + function nearest(number) { + if (number % (bits + 1) === 0) { + return number + } else { + return number - (number % (bits + 1)) + } + } + function check(index) { root.matrix[index] ^= 1; - console.log(root.matrix); - console.log(Number(root.matrix.slice(5, 9).join("")).toString()); - console.log(parseInt((root.matrix[9] >>> 0).toString(2))); + var near = nearest(index); + + if (Number(root.matrix.slice(near, near + bits).join("")).toString() === (root.matrix[near + bits] >>> 0).toString(2)) { + correct[near / (bits + 1) - 1] = 1; + } else { + correct[near / (bits + 1) - 1] = 0; + } - if (Number(root.matrix.slice(5, 9).join("")).toString() === (root.matrix[9] >>> 0).toString(2)) { - console.log("YAY"); + if (correct.filter(function(i) { return i === 1 }).length === bits) { + console.log("WON!!"); } } -- cgit v1.2.3