From 41e48013cdfa014ade5a864d7358cb17ad086efc Mon Sep 17 00:00:00 2001 From: Raphael LACOTE Date: Thu, 23 Feb 2023 15:23:30 +0100 Subject: [PATCH] MAJ Algo --- src/algo.js | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/algo.js b/src/algo.js index 8f0ab21..9ee8cf8 100644 --- a/src/algo.js +++ b/src/algo.js @@ -131,4 +131,77 @@ function setsCounter(deck, numberForSet){ console.error('The number of cards in a Set is not existing', numberForSet) } +function createElements(attributs1, attributs2) { + if (attributs1 in tabColor) { + tabColor.forEach(element => { + if (element != attributs1) { + if (element != attributs2) { + return element; + } + } + }); + } + if (attributs1 in tabNumber) { + tabNumber.forEach(element => { + if (element != attributs1) { + if (element != attributs2) { + return element; + } + } + }); + } + if (attributs1 in tabShape) { + tabShape.forEach(element => { + if (element != attributs1) { + if (element != attributs2) { + return element; + } + } + }); + } + if (attributs1 in tabFilling) { + tabFilling.forEach(element => { + if (element != attributs1) { + if (element != attributs2) { + return element; + } + } + }); + } + if (attributs1 in tabOutline) { + tabOutline.forEach(element => { + if (element != attributs1) { + if (element != attributs2) { + return element; + } + } + }); + } +} + +function createCard(cards) { + + let attributesMatrix = []; + let carteFinale = []; + + cards.forEach(element => { + attributesMatrix.push(element.getAttributes()); + }); + + for (let i = 0; i < attributesMatrix[0].length; i++) { + if (attributesMatrix[0][i] == attributesMatrix[1][i]) { + carteFinale.push(attributesMatrix[0][i]); + } + else { + carteFinale.push(createElements(attributesMatrix[0][i], attributesMatrix[1][i])) + } + } + + return carteFinale; + +} + +function isHyperset(cardsLeft, cardsRight) { + return createCard(cardsLeft).join() == createCard(cardsRight).join(); +}