diff --git a/src/Console/Console.html b/src/Console/Console.html index 23876d4..77df2ba 100644 --- a/src/Console/Console.html +++ b/src/Console/Console.html @@ -11,7 +11,6 @@

Console - test

-
@@ -25,6 +24,7 @@ + diff --git a/src/Console/main.js b/src/Console/main.js index 6646e7b..d1c0bd0 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -1,5 +1,5 @@ -// import { Card5 } from "../Model/Card5"; -// import('../Model/Card5'); +//import { Card5 } from "../Model/Card5"; +//import('../Model/Card5'); //import {Card} from '../Model/Card'; console.log("~#Test#~"); @@ -110,4 +110,30 @@ for (let i=0; i<26;i++){ console.log(e.getAttributes()); }); } -deck.checkSet(customCard); \ No newline at end of file +deck.checkSet(customCard); + +// CREATE HYPERSET + +function checkList(list) { + // Vérifier si tous les éléments sont identiques + if (list.every(element => element === list[0])) { + return 1; + } + + if ([...new Set(list)].length === list.length) { + return 0; + } + + // Si tous les éléments ne sont ni identiques ni différents + return 2; +} + +// Exemple d'utilisation +const list1 = [1, 2, 3, 4]; +console.log(checkList(list1)); // Retourne 0 + +const list2 = [1, 1, 1, 1]; +console.log(checkList(list2)); // Retourne 1 + +const list3 = [1, 2, 3, 1]; +console.log(checkList(list3)); // Retourne 2 \ No newline at end of file diff --git a/src/Model/Const.js b/src/Model/Const.js index fa16eef..3625570 100644 --- a/src/Model/Const.js +++ b/src/Model/Const.js @@ -1,7 +1,7 @@ const tabColor = ['red','purple','green','blue','orange']; const tabNumber = [1,2,3,4,5]; const tabShape = ['diamond','oval','squiggle','star','triangle']; -const tabFilling = ['empty','stripped','full','pointed','squared']; +const tabFilling = ['empty','stripped','fullO','pointed','squared']; const tabOutline = ['full','dot','rect','spade','sharp']; const ATTRIBUTES=[tabColor,tabNumber,tabShape,tabFilling,tabOutline]; @@ -19,4 +19,4 @@ const OUTLINE_SPEC = ```{ "rect" : ["stroke-dasharray" : 70], "spade" : ["stroke-dasharray" : "10 15", "stroke-width" : 70], "sharp" : [] -}```; \ No newline at end of file +}```; diff --git a/src/algo.js b/src/algo.js index 8f0ab21..b739892 100644 --- a/src/algo.js +++ b/src/algo.js @@ -1,4 +1,4 @@ -import('./Model/Card.js') +//import('./Model/Card.js') function isSet(cards) @@ -131,4 +131,116 @@ function setsCounter(deck, numberForSet){ console.error('The number of cards in a Set is not existing', numberForSet) } +function createElements(attributsCartes, listeAttributs) { + let l = [] + let verif; + listeAttributs.forEach(element => { + verif = false; + attributsCartes.forEach(attribCartes => { + if (element == attribCartes) { + verif = true; + } + }) + if (verif == false) { + l.push(element); + } + }); + return l +} + +function trouveElements(attributsCartes) { + + let x; + + tabColor.forEach(element => { + if (element == attributsCartes[0]) { + x = createElements(attributsCartes, tabColor); + } + }); + + tabNumber.forEach(element => { + if (element == attributsCartes[0]) { + x = createElements(attributsCartes, tabNumber); + } + }); + + tabShape.forEach(element => { + if (element == attributsCartes[0]) { + x = createElements(attributsCartes, tabShape); + } + }); + + tabFilling.forEach(element => { + if (element == attributsCartes[0]) { + x = createElements(attributsCartes, tabFilling); + } + }); + + tabOutline.forEach(element => { + if (element == attributsCartes[0]) { + x = createElements(attributsCartes, tabOutline); + } + }); + + return x; +} +function createCard(cards) { + + let attributesMatrix = []; + let carteFinale = []; + let listeInter = []; + + cards.forEach(element => { + attributesMatrix.push(element.getAttributes()); + }); + + for (let i = 0; i < attributesMatrix[0].length; i++) { + listeInter = []; + attributesMatrix.forEach(element => { + listeInter.push(element[i]); + }); + + //S'ils sont tous égaux + if (listeInter.every(element => element === listeInter[0])) { + l = [] + l.push(listeInter[0]) + carteFinale.push(l); + } + else { + //S'ils sont tous différents + if ([...new Set(listeInter)].length === listeInter.length) { + carteFinale.push(trouveElements(listeInter)); + } + //Sinon + else { + carteFinale.push([]); + } + } + } + + console.log(carteFinale); + return carteFinale; +} + +function isHyperset(cardsLeft, cardsRight) { + left = createCard(cardsLeft) + right = createCard(cardsRight) + let verif; + + for (let i = 0; i < left.length; i++) { + + verif = false; + left[i].forEach(elementG => { + right[i].forEach(elementD => { + if (elementD == elementG) { + verif=true + } + }) + }) + if (verif == false) { + return false; + } + } + return true; +} \ No newline at end of file diff --git a/test/testsIsHyperset.js b/test/testsIsHyperset.js new file mode 100644 index 0000000..9c4d9ca --- /dev/null +++ b/test/testsIsHyperset.js @@ -0,0 +1,61 @@ +let card1 = new Card4WithoutOutline('red', 3, 'wave', 'full'); +let card2 = new Card4WithoutOutline('red', 3, 'oval', 'empty'); +let card3 = new Card4WithoutOutline('blue', 2, 'oval', 'full'); +let card4 = new Card4WithoutOutline('green', 1, 'wave', 'pointed'); +let card5 = new Card4WithoutOutline('green', 1, 'wave', 'full'); + +deckA = []; +deckB = []; +deckC = []; + +deckA.push(card1, card2); +deckB.push(card3, card4); +deckC.push(card3, card5); + +console.assert(isHyperset(deckA, deckB) == true); +console.assert(isHyperset(deckA, deckC) == false); + +let BcardG1 = new Card5('red', 4, 'oval', 'empty', 'fullO'); +let BcardG2 = new Card5('red', 3, 'oval', 'full', 'fullO'); +let BcardG3 = new Card5('red', 2, 'oval', 'squared', 'fullO'); +let BcardG4 = new Card5('red', 1, 'oval', 'pointed', 'fullO'); + +let BcardD1 = new Card5('green', 3, 'oval', 'pointed', 'cloudy'); +let BcardD2 = new Card5('blue', 2, 'oval', 'squared', 'sharpy'); +let BcardD3 = new Card5('purple', 4, 'oval', 'full', 'hyphen'); +let BcardD4 = new Card5('orange', 1, 'oval', 'empty', 'dotted'); +let BcardD5 = new Card5('purple', 4, 'oval', 'stripped', 'hyphen'); + +BdeckA = []; +BdeckB = []; +BdeckC = []; +BdeckD = []; +BdeckE = []; + + +BdeckA.push(BcardG1, BcardG2, BcardG3); +BdeckB.push(BcardD1, BcardD2, BcardD3); +BdeckC.push(BcardD1, BcardD2, BcardD5); +BdeckD.push(BcardG1, BcardG2, BcardG3, BcardG4); +BdeckE.push(BcardD1, BcardD2, BcardD3, BcardD4); + +console.assert(isHyperset(BdeckA, BdeckB) == true); +console.assert(isHyperset(BdeckA, BdeckC) == false); +console.assert(isHyperset(BdeckD, BdeckE) == true); + + +let Ccard1 = new Card4WithoutShape('blue', 3, 'empty', 'cloudy'); +let Ccard2 = new Card4WithoutShape('red', 3, 'empty', 'cloudy'); +let Ccard3 = new Card4WithoutShape('green', 3, 'empty', 'cloudy'); +let Ccard4 = new Card4WithoutShape('purple', 3, 'empty', 'sharpy'); +let Ccard5 = new Card4WithoutShape('purple', 3, 'empty', 'sharpy'); +let Ccard6 = new Card4WithoutShape('purple', 3, 'empty', 'sharpy'); + +CdeckA = []; +CdeckB = []; + +CdeckA.push(Ccard1, Ccard2, Ccard3); +CdeckB.push(Ccard4, Ccard5, Ccard6); + +console.assert(isHyperset(CdeckA, CdeckB) == false); +