From e87dec89fcb5bd4395ac7acdc6f7b62a260278cb Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Tue, 28 Feb 2023 14:55:27 +0100 Subject: [PATCH 01/11] edit to work only with card, define funArrayOfAttributes --- src/Console/main.js | 32 ++++++++++++++++---------------- src/Model/Card.js | 12 +++++++++++- src/Model/Const.js | 12 ++++++------ src/Model/Deck.js | 5 ++--- src/Model/Factory.js | 15 +++++++++++++++ 5 files changed, 50 insertions(+), 26 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index 6646e7b..d3c5845 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -94,20 +94,20 @@ console.groupEnd(); // CHECK SET -console.log("~~CHECKING ALL SET~~") +// console.log("~~CHECKING ALL SET~~") -for (let i=0; i<26;i++){ - console.log(`-----${i}emme itérations-----`) - console.log("Card to remove: ") - console.log(deck.outputCards[0].getAttributes(),deck.outputCards[1].getAttributes(),deck.outputCards[2].getAttributes()) - customCard=[deck.outputCards[0],deck.outputCards[1],deck.outputCards[2]]; - deck.checkSet(customCard); - console.log(`remaining cards : ${deck.remainingCards.length}`) - console.log(`All cards : ${deck.allCards.length}`) - console.log(`size output ${deck.outputCards.length}`); - console.group('Output cards'); - deck.outputCards.forEach(e => { - console.log(e.getAttributes()); - }); -} -deck.checkSet(customCard); \ No newline at end of file +// for (let i=0; i<26;i++){ +// console.log(`-----${i}emme itérations-----`) +// console.log("Card to remove: ") +// console.log(deck.outputCards[0].getAttributes(),deck.outputCards[1].getAttributes(),deck.outputCards[2].getAttributes()) +// customCard=[deck.outputCards[0],deck.outputCards[1],deck.outputCards[2]]; +// deck.checkSet(customCard); +// console.log(`remaining cards : ${deck.remainingCards.length}`) +// console.log(`All cards : ${deck.allCards.length}`) +// console.log(`size output ${deck.outputCards.length}`); +// console.group('Output cards'); +// deck.outputCards.forEach(e => { +// console.log(e.getAttributes()); +// }); +// } +// deck.checkSet(customCard); \ No newline at end of file diff --git a/src/Model/Card.js b/src/Model/Card.js index 45c5972..2c0ab73 100644 --- a/src/Model/Card.js +++ b/src/Model/Card.js @@ -1,5 +1,15 @@ class Card{ - constructor(){} + constructor(attributes){ + this.attributes=attributes; + } + createAttributes(arrayOfAttributes){ + + } + + + + + /** * * @returns all attributes of a card diff --git a/src/Model/Const.js b/src/Model/Const.js index 201e43e..33ff496 100644 --- a/src/Model/Const.js +++ b/src/Model/Const.js @@ -1,6 +1,6 @@ -const tabColor = ['red','purple','green','blue','orange']; -const tabNumber = [1,2,3,4,5]; -const tabShape = ['diamond','oval','wave','star','triangle']; -const tabFilling = ['empty','stripped','full','pointed','squared']; -const tabOutline = ['full','dotted ','hyphen','cloudy','sharpy']; -const ATTRIBUTES=[tabColor,tabNumber,tabShape,tabFilling,tabOutline] \ No newline at end of file +const TAB_COLOR = ['red','purple','green','blue','orange']; +const TAB_NUMBER = [1,2,3,4,5]; +const TAB_SHAPE = ['diamond','oval','wave','star','triangle']; +const TAB_FILLING = ['empty','stripped','full','pointed','squared']; +const TAB_OUTLINE = ['full','dotted','hyphen','cloudy','sharpy']; +const ATTRIBUTES=[TAB_COLOR,TAB_NUMBER,TAB_SHAPE,TAB_FILLING,TAB_OUTLINE] \ No newline at end of file diff --git a/src/Model/Deck.js b/src/Model/Deck.js index c4c7b41..8b0c280 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -45,7 +45,6 @@ class Deck{ const random = Math.floor(Math.random() * this.remainingCards.length); return random; } - /** * * @param attributes : index of the attributes used @@ -53,8 +52,8 @@ class Deck{ * @author Bastien Jacquelin */ createCards(attributes){ - let factory = new Factory(attributes) - return factory.product + let factory = new Factory(attributes); + return factory.product; } /** diff --git a/src/Model/Factory.js b/src/Model/Factory.js index 2ab720c..39d54bc 100644 --- a/src/Model/Factory.js +++ b/src/Model/Factory.js @@ -2,7 +2,21 @@ class Factory{ constructor(arrayOfAttributes){ let length=arrayOfAttributes.length this.product=this.concreteCardCreation(arrayOfAttributes,length); + console.log("arrayOfAttributes",this.funArrayOfAttributes(arrayOfAttributes)); } + funArrayOfAttributes(arrayOfAttributes){ + let attr=[]; + let l=arrayOfAttributes.length; + arrayOfAttributes.forEach(e => { + for (let i=0;i Date: Tue, 28 Feb 2023 15:51:09 +0100 Subject: [PATCH 02/11] get dictionnary of attributes, key and value --- src/Model/Const.js | 3 ++- src/Model/Factory.js | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Model/Const.js b/src/Model/Const.js index 33ff496..4337dcf 100644 --- a/src/Model/Const.js +++ b/src/Model/Const.js @@ -3,4 +3,5 @@ const TAB_NUMBER = [1,2,3,4,5]; const TAB_SHAPE = ['diamond','oval','wave','star','triangle']; const TAB_FILLING = ['empty','stripped','full','pointed','squared']; const TAB_OUTLINE = ['full','dotted','hyphen','cloudy','sharpy']; -const ATTRIBUTES=[TAB_COLOR,TAB_NUMBER,TAB_SHAPE,TAB_FILLING,TAB_OUTLINE] \ No newline at end of file +const ATTRIBUTES=[TAB_COLOR,TAB_NUMBER,TAB_SHAPE,TAB_FILLING,TAB_OUTLINE]; +const IDX_ATTRIBUTES=["color","number","shape","filling","outline"]; \ No newline at end of file diff --git a/src/Model/Factory.js b/src/Model/Factory.js index 39d54bc..c012249 100644 --- a/src/Model/Factory.js +++ b/src/Model/Factory.js @@ -3,17 +3,41 @@ class Factory{ let length=arrayOfAttributes.length this.product=this.concreteCardCreation(arrayOfAttributes,length); console.log("arrayOfAttributes",this.funArrayOfAttributes(arrayOfAttributes)); + console.log("attributesDictionnary",this.attributesDictionnary(arrayOfAttributes,this.funArrayOfAttributes(arrayOfAttributes))) } - funArrayOfAttributes(arrayOfAttributes){ + /** + * + * @param {*} arrayOfIdxAttributes index of attributes in ATTRIBUTES + * @returns array of all attributes + */ + funArrayOfAttributes(arrayOfIdxAttributes){ let attr=[]; - let l=arrayOfAttributes.length; - arrayOfAttributes.forEach(e => { - for (let i=0;i { + for (let i=0;i Date: Tue, 28 Feb 2023 16:22:37 +0100 Subject: [PATCH 03/11] need to edit concreteCardCreation, creation of cards with right attributes --- src/Model/Factory.js | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/src/Model/Factory.js b/src/Model/Factory.js index c012249..1ff8c0e 100644 --- a/src/Model/Factory.js +++ b/src/Model/Factory.js @@ -1,7 +1,7 @@ class Factory{ constructor(arrayOfAttributes){ let length=arrayOfAttributes.length - this.product=this.concreteCardCreation(arrayOfAttributes,length); + this.product=this.concreteCardCreation(arrayOfAttributes); console.log("arrayOfAttributes",this.funArrayOfAttributes(arrayOfAttributes)); console.log("attributesDictionnary",this.attributesDictionnary(arrayOfAttributes,this.funArrayOfAttributes(arrayOfAttributes))) } @@ -38,9 +38,6 @@ class Factory{ } return dico; } - - - /** * @brief check if i in arrayOfAttributes * @param {*} i value @@ -55,34 +52,14 @@ class Factory{ } } return finded - } - /** - * @brief create a matrix with the attributes of the cards : if attributes not defined : value 0 - * @param {*} arrayOfAttributes - * @param {*} length - * @returns matrix of attributes - */ - attributesRequiredFun(arrayOfAttributes){ - let attributesRequiredTmp=[]; - let nullArray=[0,0,0,0,0]; - for(let i=0;i<5;i++){ - if(!this.inArray(i,arrayOfAttributes)){ - attributesRequiredTmp.push(nullArray); - } - else{ - attributesRequiredTmp.push(ATTRIBUTES[i]); - } - } - console.log('attributesRequiredFun',attributesRequiredTmp); - return attributesRequiredTmp; - } + } /** * @biref create the right cards : 3,4,5 attributes * @param {*} arrayOfAttributes * @param {*} length * @returns array of all cards */ - concreteCardCreation(arrayOfAttributes, length){ + concreteCardCreation(attributesDico){ let tabOfAllCards=[]; let attributes=this.attributesRequiredFun(arrayOfAttributes); let nbAttributes=length From 4951e2b8e10eae548fbbeb2ac175b4490b90348d Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Thu, 2 Mar 2023 11:09:26 +0100 Subject: [PATCH 04/11] card class only, can take multiple attributes, deck and card creation to do --- src/Console/main.js | 40 +++++++++++------------------ src/Model/Card.js | 33 +++++++++++++++--------- src/Model/Card4WithoutColor.js | 27 -------------------- src/Model/Card4WithoutFilling.js | 27 -------------------- src/Model/Card4WithoutNumber.js | 27 -------------------- src/Model/Card4WithoutOutline.js | 27 -------------------- src/Model/Card4WithoutShape.js | 27 -------------------- src/Model/Card5.js | 43 -------------------------------- 8 files changed, 36 insertions(+), 215 deletions(-) delete mode 100644 src/Model/Card4WithoutColor.js delete mode 100644 src/Model/Card4WithoutFilling.js delete mode 100644 src/Model/Card4WithoutNumber.js delete mode 100644 src/Model/Card4WithoutOutline.js delete mode 100644 src/Model/Card4WithoutShape.js delete mode 100644 src/Model/Card5.js diff --git a/src/Console/main.js b/src/Console/main.js index d3c5845..8e34e15 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -3,36 +3,26 @@ //import {Card} from '../Model/Card'; console.log("~#Test#~"); -let card4 = new Card4WithoutOutline('red','2','losange','full'); -console.group('Carte 4 attributes'); -console.log(`carte de 4 elements : ${card4.color}`); -console.groupEnd(); -let card5 = new Card5('blue','2','losange','full','pointillet'); -console.group('Carte 5 attributes'); -console.log(`carte de 5 elements : ${card5.color}`); -console.log(`carte de 5 elements : ${card5.outline}`); -console.log(`carte de 5 éléments instance de 5: ${card5 instanceof Card5}`); -console.log(`carte de 5 éléments accès par méthode idx 0: ${card5.getAttributes()[0]}`); -console.log(`carte de 5 éléments accès par méthode idx 4: ${card5.getAttributes()[4]}`); -console.groupEnd(); -console.group('Error'); -try { - let errCard = new Card5('blue','','losange','full','pointillet'); -}catch(errCard){ - if(errCard instanceof EmptyParamaterException){ - console.log('Error in constructor'); - } - else{ - console.error(errCard); - } -} +console.group('Card');//DONE +console.log('Passed') +/* +let card1=new Card({'color':'red','filling':'full'}); +let card2=new Card({'color':'red','filling':'full'}); +let card3=new Card({'color':'red','outline':'full'}); +let card4=new Card({'color':'red','filling':'empty'}); +console.log(card1.attributes);// ATTRIBUTES +console.log(card1.getAttributes());// ATTRIBUTES +console.log(card1.equals(card2));// TRUE +console.log(card1.equals(card3));//FALSE +console.log(card1.equals(card4));//FALSE +*/ console.groupEnd(); // CREATE DECK - console.group('Deck'); +/* console.log("~~BEGINNING~~"); let deck = new Deck([0,1,2,3],3); console.log(`All cards : ${deck.allCards.length}`); @@ -80,8 +70,8 @@ deck.setMade.forEach(e => {//tab of tab of cards of set made }) }); // console.log(deck.setMade) +*/ console.groupEnd(); - //let deck5 = new Deck([0,1,2,3,4]); //console.log(`All cards with 5 attributes size ${deck5.allCards.length}`); // deck5.allCards.forEach(e => { diff --git a/src/Model/Card.js b/src/Model/Card.js index 2c0ab73..9420f3f 100644 --- a/src/Model/Card.js +++ b/src/Model/Card.js @@ -1,25 +1,34 @@ class Card{ + /** + * + * @param {*} attributes : dictionnary of attributes : key : name of the attributes and value : value of the attributes + */ constructor(attributes){ this.attributes=attributes; } - createAttributes(arrayOfAttributes){ - - } - - - - - /** * * @returns all attributes of a card */ - getAttributes(){} + getAttributes(){ + let att=[]; + Object.entries(this.attributes).forEach(function([key, value]) { + att.push(value); + }); + return att; + } /** * * @param {*} card card to be compared with the current obj * @returns boolean */ - equals(card){} - -}//export {Card} \ No newline at end of file + equals(card){ + let bool=true; + Object.entries(this.attributes).forEach(function([key, value]) { + if(card.attributes[key]!=value){ + bool=false; + } + }); + return bool; + } +} \ No newline at end of file diff --git a/src/Model/Card4WithoutColor.js b/src/Model/Card4WithoutColor.js deleted file mode 100644 index cbad689..0000000 --- a/src/Model/Card4WithoutColor.js +++ /dev/null @@ -1,27 +0,0 @@ -class Card4WithoutColor extends Card{ - constructor(number, shape, filling, outline){ - super(); - if(number==''){ - throw new EmptyParamaterException('Number'); - } - if(shape==''){ - throw new EmptyParamaterException('Shape'); - } - if(filling==''){ - throw new EmptyParamaterException('Filling'); - } - if(outline==''){ - throw new EmptyParamaterException('Outline'); - } - this.number=number; - this.shape=shape; - this.filling=filling; - this.outline=outline; - } - getAttributes(){ - return [this.number,this.shape,this.filling,this.outline]; - } - equals(card){ - return this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ; - } -} \ No newline at end of file diff --git a/src/Model/Card4WithoutFilling.js b/src/Model/Card4WithoutFilling.js deleted file mode 100644 index b895c07..0000000 --- a/src/Model/Card4WithoutFilling.js +++ /dev/null @@ -1,27 +0,0 @@ -class Card4WithoutFilling extends Card{ - constructor(color,number, shape, outline){ - super(); - if(number==''){ - throw new EmptyParamaterException('Number'); - } - if(shape==''){ - throw new EmptyParamaterException('Shape'); - } - if(color==''){ - throw new EmptyParamaterException('Color'); - } - if(outline==''){ - throw new EmptyParamaterException('Outline'); - } - this.number=number; - this.shape=shape; - this.color=color; - this.outline=outline; - } - getAttributes(){ - return [this.number,this.shape,this.color,this.outline]; - } - equals(card){ - return this.number===card.number && this.shape===card.shape && this.color===card.color && this.outline===card.outline ; - } -} \ No newline at end of file diff --git a/src/Model/Card4WithoutNumber.js b/src/Model/Card4WithoutNumber.js deleted file mode 100644 index 95abc61..0000000 --- a/src/Model/Card4WithoutNumber.js +++ /dev/null @@ -1,27 +0,0 @@ -class Card4WithoutNumber extends Card{ - constructor(color, shape, filling, outline){ - super(); - if(color==''){ - throw new EmptyParamaterException('Color'); - } - if(shape==''){ - throw new EmptyParamaterException('Shape'); - } - if(filling==''){ - throw new EmptyParamaterException('Filling'); - } - if(outline==''){ - throw new EmptyParamaterException('Outline'); - } - this.color=color; - this.shape=shape; - this.filling=filling; - this.outline=outline; - } - getAttributes(){ - return [this.color,this.shape,this.filling,this.outline]; - } - equals(card){ - return this.color===card.color && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ; - } -} \ No newline at end of file diff --git a/src/Model/Card4WithoutOutline.js b/src/Model/Card4WithoutOutline.js deleted file mode 100644 index b1db83c..0000000 --- a/src/Model/Card4WithoutOutline.js +++ /dev/null @@ -1,27 +0,0 @@ -class Card4WithoutOutline extends Card{ - constructor(color, number, shape, filling){ - super(); - if(color==''){ - throw new EmptyParamaterException('Color'); - } - if(number==''){ - throw new EmptyParamaterException('Number'); - } - if(shape==''){ - throw new EmptyParamaterException('Shape'); - } - if(filling==''){ - throw new EmptyParamaterException('Filling'); - } - this.color=color; - this.number=number; - this.shape=shape; - this.filling=filling; - } - getAttributes(){ - return [this.color,this.number,this.shape,this.filling]; - } - equals(card){ - return this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.color===card.color; - } -} \ No newline at end of file diff --git a/src/Model/Card4WithoutShape.js b/src/Model/Card4WithoutShape.js deleted file mode 100644 index bf0d36c..0000000 --- a/src/Model/Card4WithoutShape.js +++ /dev/null @@ -1,27 +0,0 @@ -class Card4WithoutShape extends Card{ - constructor(color,number, filling, outline){ - super(); - if(color==''){ - throw new EmptyParamaterException('Color'); - } - if(number==''){ - throw new EmptyParamaterException('Number'); - } - if(filling==''){ - throw new EmptyParamaterException('Filling'); - } - if(outline==''){ - throw new EmptyParamaterException('Outline'); - } - this.color=color; - this.number=number; - this.filling=filling; - this.outline=outline; - } - getAttributes(){ - return [this.number,this.color,this.filling,this.outline]; - } - equals(card){ - return this.number===card.number && this.color===card.color && this.filling===card.filling && this.outline===card.outline ; - } -} \ No newline at end of file diff --git a/src/Model/Card5.js b/src/Model/Card5.js deleted file mode 100644 index a22e47a..0000000 --- a/src/Model/Card5.js +++ /dev/null @@ -1,43 +0,0 @@ -// import('.Card'); - -class Card5 extends Card { - constructor(color, number, shape, filling, outline){ - super(); - if(color==''){ - throw new EmptyParamaterException('Color'); - } - if(number==''){ - throw new EmptyParamaterException('Number'); - } - if(shape==''){ - throw new EmptyParamaterException('Shape'); - } - if(filling==''){ - throw new EmptyParamaterException('Filling'); - } - if(outline==''){ - throw new EmptyParamaterException('Outline'); - } - this.color=color; - this.number=number; - this.shape=shape; - this.filling=filling; - this.outline=outline; - } - /** - * @returns array of all attributes : - idx 1 : color - idx 2 : number - idx 3 : shape - idx 4 : filling - idx 5 : outline - * @author Bastien Jacquelin - */ - getAttributes(){ - return [this.color,this.number,this.shape,this.filling,this.outline]; - } - equals(card){ - return this.color===card.color && this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ; - } -} -// export {Card5}; \ No newline at end of file From 822b1edeba81f44a5fce90744dc73dd975ffbd74 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Thu, 2 Mar 2023 12:26:18 +0100 Subject: [PATCH 05/11] Factory : creation of all cards done : cards of 3,4,5 attributes working, need to check to deck --- src/Console/Console.html | 6 --- src/Console/main.js | 6 +++ src/Model/Card.js | 4 +- src/Model/Const.js | 2 +- src/Model/Factory.js | 90 ++++++++++++++++++++++++++++++++++++---- 5 files changed, 90 insertions(+), 18 deletions(-) diff --git a/src/Console/Console.html b/src/Console/Console.html index 23876d4..68b4247 100644 --- a/src/Console/Console.html +++ b/src/Console/Console.html @@ -16,12 +16,6 @@ - - - - - - diff --git a/src/Console/main.js b/src/Console/main.js index 8e34e15..40cfa0e 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -20,6 +20,12 @@ console.log(card1.equals(card4));//FALSE console.groupEnd(); +console.group('Factory'); +let fact3=new Factory([0,1,2]); +let fact4=new Factory([0,1,2,3]); +let fact5=new Factory([0,1,2,3,4]); +console.groupEnd(); + // CREATE DECK console.group('Deck'); /* diff --git a/src/Model/Card.js b/src/Model/Card.js index 9420f3f..864bac6 100644 --- a/src/Model/Card.js +++ b/src/Model/Card.js @@ -10,7 +10,7 @@ class Card{ * * @returns all attributes of a card */ - getAttributes(){ + getAttributes(){//working✅ let att=[]; Object.entries(this.attributes).forEach(function([key, value]) { att.push(value); @@ -22,7 +22,7 @@ class Card{ * @param {*} card card to be compared with the current obj * @returns boolean */ - equals(card){ + equals(card){//working✅ let bool=true; Object.entries(this.attributes).forEach(function([key, value]) { if(card.attributes[key]!=value){ diff --git a/src/Model/Const.js b/src/Model/Const.js index 4337dcf..3fae447 100644 --- a/src/Model/Const.js +++ b/src/Model/Const.js @@ -2,6 +2,6 @@ const TAB_COLOR = ['red','purple','green','blue','orange']; const TAB_NUMBER = [1,2,3,4,5]; const TAB_SHAPE = ['diamond','oval','wave','star','triangle']; const TAB_FILLING = ['empty','stripped','full','pointed','squared']; -const TAB_OUTLINE = ['full','dotted','hyphen','cloudy','sharpy']; +const TAB_OUTLINE = ['continuous','dotted','hyphen','cloudy','sharpy']; const ATTRIBUTES=[TAB_COLOR,TAB_NUMBER,TAB_SHAPE,TAB_FILLING,TAB_OUTLINE]; const IDX_ATTRIBUTES=["color","number","shape","filling","outline"]; \ No newline at end of file diff --git a/src/Model/Factory.js b/src/Model/Factory.js index 1ff8c0e..3519386 100644 --- a/src/Model/Factory.js +++ b/src/Model/Factory.js @@ -1,16 +1,19 @@ class Factory{ constructor(arrayOfAttributes){ - let length=arrayOfAttributes.length - this.product=this.concreteCardCreation(arrayOfAttributes); + this.dicoAttributes=this.attributesDictionnary(arrayOfAttributes,this.funArrayOfAttributes(arrayOfAttributes)); console.log("arrayOfAttributes",this.funArrayOfAttributes(arrayOfAttributes)); - console.log("attributesDictionnary",this.attributesDictionnary(arrayOfAttributes,this.funArrayOfAttributes(arrayOfAttributes))) + console.log("attributesDictionnary",this.dicoAttributes) + console.log("attributesName",this.attributesName(this.dicoAttributes)); + this.product=this.concreteCardCreation(arrayOfAttributes); + console.log("allCards",this.product); + } /** * * @param {*} arrayOfIdxAttributes index of attributes in ATTRIBUTES * @returns array of all attributes */ - funArrayOfAttributes(arrayOfIdxAttributes){ + funArrayOfAttributes(arrayOfIdxAttributes){//working✅ let attr=[]; let l=arrayOfIdxAttributes.length; arrayOfIdxAttributes.forEach(e => { @@ -26,7 +29,7 @@ class Factory{ * @param {*} arrayOfAllAttributes array of all attributes * @returns dictionnary with key : attribute and value : array of the possibilities of attributes */ - attributesDictionnary(arrayOfIdxAttributes,arrayOfAllAttributes){ + attributesDictionnary(arrayOfIdxAttributes,arrayOfAllAttributes){//working✅ let l=arrayOfIdxAttributes.length; let dico={}; for (let i=0;i Date: Mon, 6 Mar 2023 15:58:28 +0100 Subject: [PATCH 06/11] card, factory working, remain deck --- src/Console/main.js | 1 + src/Model/Factory.js | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index 40cfa0e..ff491bf 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -21,6 +21,7 @@ console.groupEnd(); console.group('Factory'); +console.log('Passed') let fact3=new Factory([0,1,2]); let fact4=new Factory([0,1,2,3]); let fact5=new Factory([0,1,2,3,4]); diff --git a/src/Model/Factory.js b/src/Model/Factory.js index 3519386..2c147f8 100644 --- a/src/Model/Factory.js +++ b/src/Model/Factory.js @@ -1,11 +1,11 @@ class Factory{ constructor(arrayOfAttributes){ this.dicoAttributes=this.attributesDictionnary(arrayOfAttributes,this.funArrayOfAttributes(arrayOfAttributes)); - console.log("arrayOfAttributes",this.funArrayOfAttributes(arrayOfAttributes)); - console.log("attributesDictionnary",this.dicoAttributes) - console.log("attributesName",this.attributesName(this.dicoAttributes)); this.product=this.concreteCardCreation(arrayOfAttributes); - console.log("allCards",this.product); + //console.log("arrayOfAttributes",this.funArrayOfAttributes(arrayOfAttributes)); + //console.log("attributesDictionnary",this.dicoAttributes) + //console.log("attributesName",this.attributesName(this.dicoAttributes)); + //console.log("allCards",this.product); } /** From 18a3c1281f71d20dbec3d474720aa10bfc2cffd2 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Mon, 6 Mar 2023 20:00:17 +0100 Subject: [PATCH 07/11] pb on deck, on creation of the deck --- src/Console/main.js | 34 +++++++++++------- src/Model/Deck.js | 63 +++++++++++++++++--------------- src/Model/Factory.js | 85 ++++++++------------------------------------ src/algo.js | 6 ++-- 4 files changed, 74 insertions(+), 114 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index ff491bf..650495b 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -1,7 +1,3 @@ -// import { Card5 } from "../Model/Card5"; -// import('../Model/Card5'); -//import {Card} from '../Model/Card'; - console.log("~#Test#~"); console.group('Card');//DONE @@ -18,17 +14,33 @@ console.log(card1.equals(card3));//FALSE console.log(card1.equals(card4));//FALSE */ console.groupEnd(); - - console.group('Factory'); console.log('Passed') -let fact3=new Factory([0,1,2]); -let fact4=new Factory([0,1,2,3]); -let fact5=new Factory([0,1,2,3,4]); +// let fact3=new Factory([0,1,2]); +let fact4=new Factory([0,1,2,3],3); +//console.log(fact4.attributesDictionnary); +// let fact5=new Factory([0,1,2,3,4]); console.groupEnd(); -// CREATE DECK console.group('Deck'); +let deck = new Deck([0,1,2,3],3); +console.log("allCards",deck.allCards); +console.log("allCards.length",deck.allCards.length); +console.log("remainingCards.length",deck.remainingCards.length); +console.log("outputCards",deck.outputCards); +console.group("checkSet"); + +console.log("outputCards 0",deck.outputCards[0]); +console.log("outputCards",deck.outputCards); + +console.log("allCards",deck.allCards[0]); +console.log("remainingCards",deck.remainingCards[0]); + +console.log(deck.checkSet([deck.outputCards[0],deck.outputCards[1],deck.outputCards[2]])); +console.log("remainingCards.length",deck.remainingCards.length); +console.log("outputCards",deck.outputCards); +console.groupEnd(); + /* console.log("~~BEGINNING~~"); let deck = new Deck([0,1,2,3],3); @@ -87,8 +99,6 @@ console.groupEnd(); //console.log(`Remaining cards ${deck.remainingCards}`); //console.log(`random : ${deck.getRandCard()}`); -console.groupEnd(); - // CHECK SET // console.log("~~CHECKING ALL SET~~") diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 8b0c280..f3df37c 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -5,22 +5,35 @@ class Deck{ * @author Bastien Jacquelin */ constructor(attributes,nbCards){ - //console.log(attributes); + this.nbCards=nbCards;// number of card to do a set this.allCards=this.createCards(attributes);// All the cards in the game - this.remainingCards=[] - this.nbCards=nbCards; - this.remainingCards=this.remainingCards.concat(this.allCards);// cards in the stack + this.remainingCards=[];//init tab null + this.remainingCards=this.remainingCards.concat(this.allCards);// cards in the stack, init = all before creation of deck -> remove this.outputCards=[];// 12 cards lay on the table this.setMade=[];// array of array with all the set already mades (array of set) this.createDeck(12); + console.log("nbCards",this.nbCards); + // console.log("allCards after deck",this.allCards); + console.log("remainingCards after deck",this.remainingCards); + console.log("outputCards",this.outputCards); + console.log("setMade",this.setMade); + } + /** + * + * @param attributes : index of the attributes used + * @returns all cards: 81 in case of 4 attributes and 1024 if 5 attributes + * @author Bastien Jacquelin + */ + createCards(attributes){//working✅ + let factory = new Factory(attributes,this.nbCards); + return factory.product; } - /** - * @brief creation of the deck : 12 cards lay in front of the player + * @brief creation of the deck : 12 random cards lay in front of the player * @author Bastien Jacquelin */ - createDeck(nbCards){ - if(this.remainingCards.length==0){ + createDeck(nbCards){//toTest⌛ + if(this.remainingCards.length { for(let i=0; i { for (let i=0;i Date: Mon, 6 Mar 2023 20:29:19 +0100 Subject: [PATCH 08/11] factory create good cards, good index on dico --- src/Model/Deck.js | 1 - src/Model/Factory.js | 39 ++++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Model/Deck.js b/src/Model/Deck.js index f3df37c..ce0cf47 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -12,7 +12,6 @@ class Deck{ this.outputCards=[];// 12 cards lay on the table this.setMade=[];// array of array with all the set already mades (array of set) this.createDeck(12); - console.log("nbCards",this.nbCards); // console.log("allCards after deck",this.allCards); console.log("remainingCards after deck",this.remainingCards); console.log("outputCards",this.outputCards); diff --git a/src/Model/Factory.js b/src/Model/Factory.js index 04eb768..2bb9061 100644 --- a/src/Model/Factory.js +++ b/src/Model/Factory.js @@ -2,11 +2,11 @@ class Factory{ constructor(arrayOfAttributes, nbAttributes){ this.nbAttr=nbAttributes; this.dicoAttributes=this.attributesDictionnary(arrayOfAttributes,this.funArrayOfAttributes(arrayOfAttributes)); - this.product=this.concreteCardCreation(arrayOfAttributes); + this.product=this.concreteCardCreation(arrayOfAttributes); // console.log("arrayOfAttributes",this.funArrayOfAttributes(arrayOfAttributes)); - // console.log("attributesDictionnary",this.dicoAttributes) - // console.log("attributesName",this.attributesName(this.dicoAttributes)); - // console.log("allCards",this.product); + console.log("attributesDictionnary",this.dicoAttributes) + console.log("attributesName",this.attributesName(this.dicoAttributes)); + console.log("allCards",this.product); } /** @@ -84,10 +84,10 @@ class Factory{ for (let c=0; c Date: Mon, 6 Mar 2023 23:01:56 +0100 Subject: [PATCH 09/11] line 677 in deck to edit, all functional --- src/Console/main.js | 110 +++++++------------------------------------- 1 file changed, 17 insertions(+), 93 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index 650495b..157b6ac 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -17,104 +17,28 @@ console.groupEnd(); console.group('Factory'); console.log('Passed') // let fact3=new Factory([0,1,2]); -let fact4=new Factory([0,1,2,3],3); +// let fact4=new Factory([0,1,2,3],3); //console.log(fact4.attributesDictionnary); // let fact5=new Factory([0,1,2,3,4]); console.groupEnd(); console.group('Deck'); let deck = new Deck([0,1,2,3],3); -console.log("allCards",deck.allCards); -console.log("allCards.length",deck.allCards.length); -console.log("remainingCards.length",deck.remainingCards.length); -console.log("outputCards",deck.outputCards); -console.group("checkSet"); - -console.log("outputCards 0",deck.outputCards[0]); -console.log("outputCards",deck.outputCards); - -console.log("allCards",deck.allCards[0]); -console.log("remainingCards",deck.remainingCards[0]); - -console.log(deck.checkSet([deck.outputCards[0],deck.outputCards[1],deck.outputCards[2]])); -console.log("remainingCards.length",deck.remainingCards.length); -console.log("outputCards",deck.outputCards); -console.groupEnd(); - -/* -console.log("~~BEGINNING~~"); -let deck = new Deck([0,1,2,3],3); -console.log(`All cards : ${deck.allCards.length}`); -//Display all cards -console.log(`All cards display`); -// deck.allCards.forEach(e => { -// console.log(e.color,e.number,e.shape,e.filling);//no outline -// console.log(e.color,e.number,e.filling,e.outline);//no shape -// console.log(e.color,e.number,e.shape,e.outline);//no filling -// }); -console.log(`remaining cards : ${deck.remainingCards.length}`) -console.log(`size output ${deck.outputCards.length}`); -console.group('Output cards'); -deck.outputCards.forEach(e => { - console.log(e.getAttributes()); -}); +console.log("deck.outputCards",deck.outputCards) +console.log("deck.outputCards length",deck.outputCards.length) +console.log("deck.remainingCards",deck.remainingCards) +console.log("deck.remainingCards length",deck.remainingCards.length) +console.log("check set"); +deck.checkSet([deck.outputCards[0],deck.outputCards[1],deck.outputCards[2]]) +console.log("deck.outputCards",deck.outputCards) +console.log("deck.outputCards length",deck.outputCards.length) + +console.log("deck.remainingCards",deck.remainingCards) +console.log("deck.remainingCards length",deck.remainingCards.length) console.groupEnd(); -console.log(`set already made :${deck.setMade}`); -deck.setMade.forEach(e => { - console.log(e.color,e.number,e.shape,e.filling); - }); - - -// CHECK SET -console.log("~~CHECKING SET~~") - -console.log("Card to remove: ") -console.log(deck.outputCards[0].getAttributes(),deck.outputCards[1].getAttributes(),deck.outputCards[2].getAttributes()) -let customCard=[deck.outputCards[0],deck.outputCards[1],deck.outputCards[2]]; -deck.checkSet(customCard); -console.log(`remaining cards : ${deck.remainingCards.length}`) -console.log(`All cards : ${deck.allCards.length}`) -console.log(`size output ${deck.outputCards.length}`); -console.group('Output cards'); -deck.outputCards.forEach(e => { - console.log(e.getAttributes()); -}); -console.groupEnd(); - -console.log("~~SET MADE~~"); -console.log(`set already made : ${deck.setMade.length}`); -deck.setMade.forEach(e => {//tab of tab of cards of set made - e.forEach(a=>{ - console.log(a.color,a.number,a.shape,a.filling); - }) - }); -// console.log(deck.setMade) -*/ -console.groupEnd(); -//let deck5 = new Deck([0,1,2,3,4]); -//console.log(`All cards with 5 attributes size ${deck5.allCards.length}`); -// deck5.allCards.forEach(e => { -// console.log(e.color,e.number,e.shape,e.filling,e.outline); -// }); -//console.log(`Remaining cards ${deck.remainingCards}`); -//console.log(`random : ${deck.getRandCard()}`); - - -// CHECK SET -// console.log("~~CHECKING ALL SET~~") -// for (let i=0; i<26;i++){ -// console.log(`-----${i}emme itérations-----`) -// console.log("Card to remove: ") -// console.log(deck.outputCards[0].getAttributes(),deck.outputCards[1].getAttributes(),deck.outputCards[2].getAttributes()) -// customCard=[deck.outputCards[0],deck.outputCards[1],deck.outputCards[2]]; -// deck.checkSet(customCard); -// console.log(`remaining cards : ${deck.remainingCards.length}`) -// console.log(`All cards : ${deck.allCards.length}`) -// console.log(`size output ${deck.outputCards.length}`); -// console.group('Output cards'); -// deck.outputCards.forEach(e => { -// console.log(e.getAttributes()); -// }); -// } -// deck.checkSet(customCard); \ No newline at end of file +let tab=[] +tab.push("yeyee") +console.log(tab) +tab.push("gngngn") +console.log(tab) From 8b1a51cb4064951a93eab1eef9b7206c9868d2c5 Mon Sep 17 00:00:00 2001 From: bajacqueli Date: Mon, 6 Mar 2023 23:02:50 +0100 Subject: [PATCH 10/11] deck and factory work together, resolve pbs --- src/Model/Deck.js | 9 +++------ src/Model/Factory.js | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Model/Deck.js b/src/Model/Deck.js index ce0cf47..3bef3cf 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -12,10 +12,6 @@ class Deck{ this.outputCards=[];// 12 cards lay on the table this.setMade=[];// array of array with all the set already mades (array of set) this.createDeck(12); - // console.log("allCards after deck",this.allCards); - console.log("remainingCards after deck",this.remainingCards); - console.log("outputCards",this.outputCards); - console.log("setMade",this.setMade); } /** * @@ -28,7 +24,7 @@ class Deck{ return factory.product; } /** - * @brief creation of the deck : 12 random cards lay in front of the player + * @brief creation of the deck : 12 random cards lay in front of the playe and remove card from the remainingCard array * @author Bastien Jacquelin */ createDeck(nbCards){//toTest⌛ @@ -44,6 +40,8 @@ class Deck{ } let nbSets=setsCounter(this.outputCards,this.nbCards); console.log("nbSets",nbSets); + console.log("outputCards.length",this.outputCards.length); + console.log("remainingCards.length",this.remainingCards.length); if(nbSets==0){ this.createDeck(this.nbCards) } @@ -103,7 +101,6 @@ class Deck{ throw new UnFoundCardException(selectedCards); } else{ - console.log("set",set); this.setMade.push(set); this.createDeck(this.nbCards) } diff --git a/src/Model/Factory.js b/src/Model/Factory.js index 2bb9061..d75e7ef 100644 --- a/src/Model/Factory.js +++ b/src/Model/Factory.js @@ -4,9 +4,9 @@ class Factory{ this.dicoAttributes=this.attributesDictionnary(arrayOfAttributes,this.funArrayOfAttributes(arrayOfAttributes)); this.product=this.concreteCardCreation(arrayOfAttributes); // console.log("arrayOfAttributes",this.funArrayOfAttributes(arrayOfAttributes)); - console.log("attributesDictionnary",this.dicoAttributes) - console.log("attributesName",this.attributesName(this.dicoAttributes)); - console.log("allCards",this.product); + // console.log("attributesDictionnary",this.dicoAttributes) + // console.log("attributesName",this.attributesName(this.dicoAttributes)); + // console.log("allCards",this.product); } /** From 68fbfc3ab0041f70dcc31605a740d1274467abf3 Mon Sep 17 00:00:00 2001 From: Bastien JACQUELIN Date: Mon, 6 Mar 2023 23:08:56 +0100 Subject: [PATCH 11/11] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'src/Console/?= =?UTF-8?q?main.js'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Console/main.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Console/main.js b/src/Console/main.js index 157b6ac..cb2a25e 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -42,3 +42,28 @@ tab.push("yeyee") console.log(tab) tab.push("gngngn") console.log(tab) +// 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