From 8a953d63ef59a4b30325da190174ebef09a5e32d Mon Sep 17 00:00:00 2001 From: "aurian.jault" Date: Tue, 31 Jan 2023 17:23:50 +0100 Subject: [PATCH 01/12] pseudo code du 1er algo --- src/algo.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/algo.js diff --git a/src/algo.js b/src/algo.js new file mode 100644 index 0000000..db0090e --- /dev/null +++ b/src/algo.js @@ -0,0 +1,18 @@ +// Pseudo code +// +/* + * function checkReslt(array ) + * { + * new array> matrice = vide + * + * forEach(array: value) + * { + * matrice.add(value.getAttrib) + * } + * Check all length of matrice + * for(i = 0; i Date: Thu, 2 Feb 2023 11:06:14 +0100 Subject: [PATCH 02/12] Algo de verification --- src/algo.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/algo.js b/src/algo.js index db0090e..07b58fc 100644 --- a/src/algo.js +++ b/src/algo.js @@ -11,8 +11,80 @@ * } * Check all length of matrice * for(i = 0; i tab + * for (j=0; j { + matrice.push(element.getAttribute()); + }); + // Idéalement check si toute les listes d'attributs sont de même taille + for (let i = 0; i < matrice[0]; i++) { + let listAttrib = [] + for (let j = 0; j < matrice[i]; j++) { + listAttrib.push(j); + } + if(!checkattrib(j)){ + return false; + } + return true; + } +} + + +function checkattrib(attribs){ + let orderingMethod = "null"; // Can only take ["null", "same", "different"] + attribs.forEach(function callback(value, index) + { + if(!index === attribs.length) + { + for (let i = index+1; i < array.length; i++) + { + if(attribs[i] === value) + { + if(orderingMethod === "null" || orderingMethod === "same") + { + orderingMethod = "same"; + } + else + { + return false; + } + } + else + { + if(orderingMethod === "null" || orderingMethod === "different") + { + orderingMethod = "different" + } + else + { + return false + } + } + + } + } + }); + return true; +} From 7450bb88776b10708d8096b017c3930667ccb481 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Thu, 2 Feb 2023 12:09:13 +0100 Subject: [PATCH 03/12] create cards and deck --- src/Console/main.js | 36 +++++++++++++++++++++++++----------- src/Model/Deck.js | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index 108635f..930cf2c 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -27,19 +27,33 @@ try { } console.groupEnd(); console.group('Deck'); -let deck = new Deck(); -console.log(`Output cards ${deck.outputCards}`); +let deck = new Deck(4); + +console.log(`All cards with 4 attributes size ${deck.allCards.length}`); +console.log(`size ${deck.outputCards.length}`); + +// deck.allCards.forEach(e => { +// console.log(e.color,e.number,e.shape,e.filling); +// }); +console.log(`Output cards`); +deck.outputCards.forEach(e => { + console.log(e.color,e.number,e.shape,e.filling); +}); console.log(`set already made ${deck.setMade}`); -console.log(`All cards ${deck.allCards}`); -console.log(`Remaining cards ${deck.remainingCards}`); -console.groupEnd(); -console.group('Maths'); -let list=[]; -list.push(1); -list.push(2); -let gngn=Math.floor(Math.random() * list.length) -console.log(gngn); + + + +let deck5 = new Deck(5) +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()}`); + + + console.groupEnd(); diff --git a/src/Model/Deck.js b/src/Model/Deck.js index b38bd49..55d34bd 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -1,19 +1,45 @@ class Deck{ - constructor(){ - this.outputCards=this.createDeck(); - this.setMade=[]; - this.allCards=this.createCards(); - this.remainingCards=this.allCards; + constructor(nbAttributes){ + this.allCards=this.createCards(nbAttributes);// All the cards in the game + this.remainingCards=this.allCards;// cards in the stack + this.outputCards=[];// 12 cards lay on the table + this.setMade=[];// array with all the set already mades (array of set) + this.createDeck(); } createDeck(){ for (let i=0; i<12; i++){ - + const rand = this.getRandCard(); + this.outputCards.push(this.remainingCards[rand]); + this.remainingCards.splice(rand,1); } } getRandCard(){ - Math.floor(Math.random() * remainingCards.length); + const random = Math.floor(Math.random() * this.remainingCards.length); + return random; } - createCards(){ - return 456; + createCards(nbAttributes){ + const tabColor = ['red','purple','green','blue','orange']; + const tabShape = ['diamond','oval','wave','star','circle'] + const tabFilling = ['empty','stripped','full','pointed','squared']; + const tabNumber = [1,2,3,4,5]; + const tabOutline = ['full','dotted ','aa','bb','cc']; + let tabOfAllCards=[]; + for (let c=0; c Date: Thu, 2 Feb 2023 14:19:54 +0100 Subject: [PATCH 04/12] add unfoundCardException, add the set verificatio operations --- src/Console/Console.html | 1 + src/Model/Deck.js | 29 ++++++++++++++++++++++++++++- src/Model/unfoundCardException.js | 5 +++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/Model/unfoundCardException.js diff --git a/src/Console/Console.html b/src/Console/Console.html index bc47ce5..1f6b5c3 100644 --- a/src/Console/Console.html +++ b/src/Console/Console.html @@ -14,6 +14,7 @@ + diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 55d34bd..81ee4e8 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -1,5 +1,5 @@ class Deck{ - constructor(nbAttributes){ + constructor(nbAttributes=4){ this.allCards=this.createCards(nbAttributes);// All the cards in the game this.remainingCards=this.allCards;// cards in the stack this.outputCards=[];// 12 cards lay on the table @@ -17,6 +17,11 @@ class Deck{ const random = Math.floor(Math.random() * this.remainingCards.length); return random; } + /** + * + * @param {*} nbAttributes : attributes of the card, by default = 4 + * @returns all cards: 81 in case of 4 attributes and 1224 + */ createCards(nbAttributes){ const tabColor = ['red','purple','green','blue','orange']; const tabShape = ['diamond','oval','wave','star','circle'] @@ -42,4 +47,26 @@ class Deck{ } return tabOfAllCards; } + checkSet(selectedCards){ + if(true){//isSet(selectedCards)){ + selectedCards.forEach(e => { + this.removeFromRemainingCards(e); + }); + } + } + removeFromRemainingCards(selectedCards){ + let set=[]; + if (selectedCards instanceof Card) { + for(let i=0; i Date: Thu, 2 Feb 2023 14:29:59 +0100 Subject: [PATCH 05/12] update README.md --- README.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ede5d5c..246a05b 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,19 @@ # HyperSet -## Description of the project - -2nd Year Project of IT BUT in Aubière +## Notes -## Subject +- [Project subject](https://codefirst.iut.uca.fr/git/cedric.bouhours/Projets_SAE_S4/src/branch/master/Projets/Projet_11.md) +- [Original project website](https://sancy.iut.uca.fr/~lafourcade/hyper-set-reda/HyperSet/) +## Description of the project -[link of the initial project](https://codefirst.iut.uca.fr/git/cedric.bouhours/Projets_SAE_S4/src/branch/master/Projets/Projet_11.md) +null -## Created by : +## Project Convention -LACOTE Raphaël JAULT Aurian ARNAL Rémi JACQUELIN Bastien \ No newline at end of file +- Functions names must be explicit and complete +- Variable follow **camelCase** naming convention +- Opening brace must be at end of line +- Directories names my_directory +- Files names -> my_file.js +- No useless comments \ No newline at end of file From 1dfdae926e8103f47855a44031a5d5d699e1f4f9 Mon Sep 17 00:00:00 2001 From: RemRem Date: Thu, 2 Feb 2023 14:32:17 +0100 Subject: [PATCH 06/12] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 246a05b..5624f99 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ null ## Project Convention -- Functions names must be explicit and complete +- Functions names must be explicit, complete and follow **camelCase** naming - Variable follow **camelCase** naming convention - Opening brace must be at end of line - Directories names my_directory From 0add9526fe5fc2450a2dbcd5e4cb95bd82db2d02 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Thu, 2 Feb 2023 15:16:23 +0100 Subject: [PATCH 07/12] remove from deck set cards --- src/Console/main.js | 19 +++++++++++++++---- src/Model/Card.js | 3 +++ src/Model/Card5.js | 3 +++ src/Model/Deck.js | 30 ++++++++++++++++-------------- src/Model/unfoundCardException.js | 4 ++-- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index 930cf2c..a349a7b 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -41,10 +41,19 @@ deck.outputCards.forEach(e => { }); console.log(`set already made ${deck.setMade}`); - - - - +deck.allCards.forEach(e => { + console.log(e.color,e.number,e.shape,e.filling); + }); +let customCard=[new Card('red',1,'diamond','stripped')]; +deck.checkSet(customCard); +console.log(`deck size :${deck.allCards.length}`); +deck.allCards.forEach(e => { + console.log(e.color,e.number,e.shape,e.filling); +}); +console.log(`remaining cars:`); +deck.setMade.forEach(e => { + console.log(e.color,e.number,e.shape,e.filling); + }); let deck5 = new Deck(5) console.log(`All cards with 5 attributes size ${deck5.allCards.length}`); @@ -56,4 +65,6 @@ console.log(`All cards with 5 attributes size ${deck5.allCards.length}`); + + console.groupEnd(); diff --git a/src/Model/Card.js b/src/Model/Card.js index d7da58b..0b8997b 100644 --- a/src/Model/Card.js +++ b/src/Model/Card.js @@ -29,5 +29,8 @@ class Card{ getAttributes(){ return [this.color,this.number,this.shape,this.filling]; } + equals(card){ + return this.color===card.color && this.number===card.number && this.shape===card.shape && this.filling===card.filling; + } }//export {Card} \ No newline at end of file diff --git a/src/Model/Card5.js b/src/Model/Card5.js index b9d7894..bead780 100644 --- a/src/Model/Card5.js +++ b/src/Model/Card5.js @@ -21,5 +21,8 @@ class Card5 extends Card { // return [this.color,this.number,this.shape,this.filling,this.outline]; return super.getAttributes().concat(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 diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 81ee4e8..5be6949 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -4,7 +4,7 @@ class Deck{ this.remainingCards=this.allCards;// cards in the stack this.outputCards=[];// 12 cards lay on the table this.setMade=[];// array with all the set already mades (array of set) - this.createDeck(); + //this.createDeck(); } createDeck(){ for (let i=0; i<12; i++){ @@ -24,9 +24,9 @@ class Deck{ */ createCards(nbAttributes){ const tabColor = ['red','purple','green','blue','orange']; - const tabShape = ['diamond','oval','wave','star','circle'] - const tabFilling = ['empty','stripped','full','pointed','squared']; const tabNumber = [1,2,3,4,5]; + const tabShape = ['diamond','oval','wave','star','circle']; + const tabFilling = ['empty','stripped','full','pointed','squared']; const tabOutline = ['full','dotted ','aa','bb','cc']; let tabOfAllCards=[]; for (let c=0; c Date: Fri, 3 Feb 2023 13:29:48 +0100 Subject: [PATCH 08/12] Fin algo de verification des set --- src/algo.js | 62 ++++++++++++++++++++++++++++++++++---------------- src/index.html | 20 ++++++++++++++++ 2 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 src/index.html diff --git a/src/algo.js b/src/algo.js index 07b58fc..c4e8740 100644 --- a/src/algo.js +++ b/src/algo.js @@ -23,44 +23,66 @@ * } * * - * */ + * */ + + function main() { // "Stub de test" + let card1 = new Card("Purple","1","Triangle","Full"); + let card2 = new Card("Purple","2","Triangle","Full"); + let card3 = new Card("Purple","3","Triangle","Full"); + let card8 = new Card("Purple","4","Triangle","Full"); + let card9 = new Card("Purple","5","Triangle","Full"); + let card0 = new Card("Purple","6","Triangle","Full"); + let card10 = new Card("Purple","7","Triangle","Full"); + let card4 = new Card("Purple","1","Triangle","Full"); + let card5 = new Card("Purple","2","Triangle","Full"); + let card6 = new Card("Purple","1","Triangle","Full"); + console.group("TEST TRUE") + if(isSet([card1,card2,card3,card8,card9,card0,card10])) + { + console.log("TRUE") + } + else + { + console.log("FALSE") + } + console.groupEnd() } -function isSet(card) +function isSet(cards) { - let matrice = []; + let attributesMatrix = []; - card.forEach(element => { - matrice.push(element.getAttribute()); + cards.forEach(element => { + attributesMatrix.push(element.getAttributes()); }); // Idéalement check si toute les listes d'attributs sont de même taille - for (let i = 0; i < matrice[0]; i++) { - let listAttrib = [] - for (let j = 0; j < matrice[i]; j++) { - listAttrib.push(j); + for(let i = 0; i < attributesMatrix[0].length; i++) { + let listAttributes = [] + for(let j = 0; j < attributesMatrix.length; j++) { + listAttributes.push(attributesMatrix[j][i]); } - if(!checkattrib(j)){ + if(!checkAttributes(listAttributes)){ return false; } - return true; } + return true; } -function checkattrib(attribs){ +function checkAttributes(attributes){ let orderingMethod = "null"; // Can only take ["null", "same", "different"] - attribs.forEach(function callback(value, index) - { - if(!index === attribs.length) + let boolLoop = true; + attributes.forEach((value, index) => { + if(index !== attributes.length) { - for (let i = index+1; i < array.length; i++) + for (let i = index+1; i < attributes.length; i++) { - if(attribs[i] === value) + if(attributes[i] === value) { if(orderingMethod === "null" || orderingMethod === "same") { @@ -68,7 +90,7 @@ function checkattrib(attribs){ } else { - return false; + boolLoop = false; } } else @@ -79,12 +101,12 @@ function checkattrib(attribs){ } else { - return false + boolLoop = false } } } } }); - return true; + return boolLoop === true; } diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..b32303c --- /dev/null +++ b/src/index.html @@ -0,0 +1,20 @@ + + + + + + My awesome blog + + + +

My awesome blog

+ + + + + + + + \ No newline at end of file From 2b6dcc5666d3331873897d2587ec10d90ff5e457 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Fri, 3 Feb 2023 14:37:04 +0100 Subject: [PATCH 09/12] edit to make possible the choice of the attributes --- src/Console/Console.html | 1 + src/Console/main.js | 24 +++++---------- src/Model/Card.js | 18 +++++++----- src/Model/Const.js | 6 ++++ src/Model/Deck.js | 63 +++++++++++++++++++++++++++------------- 5 files changed, 69 insertions(+), 43 deletions(-) create mode 100644 src/Model/Const.js diff --git a/src/Console/Console.html b/src/Console/Console.html index 1f6b5c3..f639d2a 100644 --- a/src/Console/Console.html +++ b/src/Console/Console.html @@ -17,6 +17,7 @@ + diff --git a/src/Console/main.js b/src/Console/main.js index a349a7b..b0652e6 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -27,11 +27,11 @@ try { } console.groupEnd(); console.group('Deck'); -let deck = new Deck(4); +let deck = new Deck([0,1,2,3],4); console.log(`All cards with 4 attributes size ${deck.allCards.length}`); -console.log(`size ${deck.outputCards.length}`); - +console.log(`size output ${deck.outputCards.length}`); +// Display all cards // deck.allCards.forEach(e => { // console.log(e.color,e.number,e.shape,e.filling); // }); @@ -41,30 +41,22 @@ deck.outputCards.forEach(e => { }); console.log(`set already made ${deck.setMade}`); -deck.allCards.forEach(e => { - console.log(e.color,e.number,e.shape,e.filling); - }); + let customCard=[new Card('red',1,'diamond','stripped')]; -deck.checkSet(customCard); +//deck.checkSet(customCard); console.log(`deck size :${deck.allCards.length}`); -deck.allCards.forEach(e => { - console.log(e.color,e.number,e.shape,e.filling); -}); + console.log(`remaining cars:`); deck.setMade.forEach(e => { console.log(e.color,e.number,e.shape,e.filling); }); -let deck5 = new Deck(5) -console.log(`All cards with 5 attributes size ${deck5.allCards.length}`); +//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()}`); - - - - console.groupEnd(); diff --git a/src/Model/Card.js b/src/Model/Card.js index 0b8997b..3ee1a44 100644 --- a/src/Model/Card.js +++ b/src/Model/Card.js @@ -1,21 +1,25 @@ class Card{ - constructor(color, number, shape, filling){ - if(!color){ + constructor(color, number, shape, filling, outline){ + if(color=''){ throw new EmptyParamaterException('Color'); } - if(!number){ + if(number=''){ throw new EmptyParamaterException('Number'); } - if(!shape){ + if(shape==''){ throw new EmptyParamaterException('Shape'); } - if(!filling){ + 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 : @@ -27,10 +31,10 @@ class Card{ * @author Bastien Jacquelin */ getAttributes(){ - return [this.color,this.number,this.shape,this.filling]; + 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; + return this.color===card.color && this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ; } }//export {Card} \ No newline at end of file diff --git a/src/Model/Const.js b/src/Model/Const.js new file mode 100644 index 0000000..201e43e --- /dev/null +++ b/src/Model/Const.js @@ -0,0 +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 diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 5be6949..40c365c 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -1,11 +1,40 @@ class Deck{ - constructor(nbAttributes=4){ - this.allCards=this.createCards(nbAttributes);// All the cards in the game + /** + * + * @param {*} attributes : array with the attributes index for the cards + */ + constructor(attributes,nbAttributes){ + let attributesRequired=this.attributesRequiredFun(attributes); + attributesRequired.forEach(e=>{ + for(let i=0;i { From 99ed8b123307f587a7d356c4367cae42747a0205 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Mon, 6 Feb 2023 17:30:44 +0100 Subject: [PATCH 10/12] add all class of 4 attributes cards, edit facotry --- src/Console/Console.html | 6 +++ src/Console/main.js | 23 +++++---- src/Model/Card.js | 45 ++++-------------- 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 | 23 +++++++-- src/Model/Deck.js | 68 ++++++++------------------ src/Model/Factory.js | 82 ++++++++++++++++++++++++++++++++ src/index.html | 20 -------- 12 files changed, 286 insertions(+), 116 deletions(-) create mode 100644 src/Model/Card4WithoutColor.js create mode 100644 src/Model/Card4WithoutFilling.js create mode 100644 src/Model/Card4WithoutNumber.js create mode 100644 src/Model/Card4WithoutOutline.js create mode 100644 src/Model/Card4WithoutShape.js create mode 100644 src/Model/Factory.js delete mode 100644 src/index.html diff --git a/src/Console/Console.html b/src/Console/Console.html index f639d2a..9ba88b8 100644 --- a/src/Console/Console.html +++ b/src/Console/Console.html @@ -16,8 +16,14 @@ + + + + + + diff --git a/src/Console/main.js b/src/Console/main.js index b0652e6..2374db8 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -3,12 +3,14 @@ //import {Card} from '../Model/Card'; console.log("~#Test#~"); -let card4 = new Card('red','2','losange','full'); +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]}`); @@ -26,19 +28,22 @@ try { } } console.groupEnd(); -console.group('Deck'); -let deck = new Deck([0,1,2,3],4); + +console.group('Deck'); +let deck = new Deck([0,1,2,3]); console.log(`All cards with 4 attributes size ${deck.allCards.length}`); console.log(`size output ${deck.outputCards.length}`); -// Display all cards -// deck.allCards.forEach(e => { -// console.log(e.color,e.number,e.shape,e.filling); -// }); -console.log(`Output cards`); -deck.outputCards.forEach(e => { +//Display all cards +console.log(`All cards`); +console.log(deck.allCards) +deck.allCards.forEach(e => { console.log(e.color,e.number,e.shape,e.filling); }); +console.log(`Output cards`); +// deck.outputCards.forEach(e => { +// console.log(e.getAttributes()); +// }); console.log(`set already made ${deck.setMade}`); diff --git a/src/Model/Card.js b/src/Model/Card.js index 3ee1a44..45c5972 100644 --- a/src/Model/Card.js +++ b/src/Model/Card.js @@ -1,40 +1,15 @@ class Card{ - constructor(color, number, shape, filling, outline){ - 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; - } + constructor(){} /** - * @returns array of all attributes : - idx 1 : color - idx 2 : number - idx 3 : shape - idx 4 : filling - idx 5 : null - * @author Bastien Jacquelin + * + * @returns all attributes of a card */ - 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 ; - } + getAttributes(){} + /** + * + * @param {*} card card to be compared with the current obj + * @returns boolean + */ + equals(card){} }//export {Card} \ No newline at end of file diff --git a/src/Model/Card4WithoutColor.js b/src/Model/Card4WithoutColor.js new file mode 100644 index 0000000..cbad689 --- /dev/null +++ b/src/Model/Card4WithoutColor.js @@ -0,0 +1,27 @@ +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 new file mode 100644 index 0000000..b895c07 --- /dev/null +++ b/src/Model/Card4WithoutFilling.js @@ -0,0 +1,27 @@ +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 new file mode 100644 index 0000000..95abc61 --- /dev/null +++ b/src/Model/Card4WithoutNumber.js @@ -0,0 +1,27 @@ +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 new file mode 100644 index 0000000..c52c2f1 --- /dev/null +++ b/src/Model/Card4WithoutOutline.js @@ -0,0 +1,27 @@ +class Card4WithoutOutline extends Card{ + constructor(color, number, shape, filling){ + super(); + if(number==''){ + throw new EmptyParamaterException('Number'); + } + if(shape==''){ + throw new EmptyParamaterException('Shape'); + } + if(filling==''){ + throw new EmptyParamaterException('Filling'); + } + if(color==''){ + throw new EmptyParamaterException('Color'); + } + this.number=number; + this.shape=shape; + this.filling=filling; + this.color=color; + } + getAttributes(){ + return [this.number,this.shape,this.filling,this.color]; + } + 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 new file mode 100644 index 0000000..bf0d36c --- /dev/null +++ b/src/Model/Card4WithoutShape.js @@ -0,0 +1,27 @@ +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 index bead780..a22e47a 100644 --- a/src/Model/Card5.js +++ b/src/Model/Card5.js @@ -2,10 +2,26 @@ class Card5 extends Card { constructor(color, number, shape, filling, outline){ - super(color,number,shape,filling); - if(!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; } /** @@ -18,8 +34,7 @@ class Card5 extends Card { * @author Bastien Jacquelin */ getAttributes(){ - // return [this.color,this.number,this.shape,this.filling,this.outline]; - return super.getAttributes().concat(this.outline); + 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 ; diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 40c365c..1c13a92 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -3,38 +3,17 @@ class Deck{ * * @param {*} attributes : array with the attributes index for the cards */ - constructor(attributes,nbAttributes){ - let attributesRequired=this.attributesRequiredFun(attributes); - attributesRequired.forEach(e=>{ - for(let i=0;i - - - - - My awesome blog - - - -

My awesome blog

- - - - - - - - \ No newline at end of file From 77665d925457858e24dfb7d258d184a3be7c2023 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Mon, 6 Feb 2023 18:42:22 +0100 Subject: [PATCH 11/12] fix factory, bug in attributesRequiredFun in facory --- src/Console/main.js | 17 ++++++++--------- src/Model/Deck.js | 2 +- src/Model/Factory.js | 10 +++++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index 2374db8..2b9de4d 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -31,30 +31,29 @@ console.groupEnd(); console.group('Deck'); -let deck = new Deck([0,1,2,3]); +let deck = new Deck([0,1,3,4]); console.log(`All cards with 4 attributes size ${deck.allCards.length}`); console.log(`size output ${deck.outputCards.length}`); //Display all cards console.log(`All cards`); -console.log(deck.allCards) deck.allCards.forEach(e => { - console.log(e.color,e.number,e.shape,e.filling); + //console.log(e.color,e.number,e.shape,e.filling); + console.log(e.color,e.number,e.filling,e.outline); + //console.log(e.color,e.number,e.shape,e.outline); }); console.log(`Output cards`); // deck.outputCards.forEach(e => { // console.log(e.getAttributes()); // }); console.log(`set already made ${deck.setMade}`); - +console.log(`remaining cards:`); +deck.setMade.forEach(e => { + console.log(e.color,e.number,e.shape,e.filling); + }); let customCard=[new Card('red',1,'diamond','stripped')]; //deck.checkSet(customCard); -console.log(`deck size :${deck.allCards.length}`); -console.log(`remaining cars:`); -deck.setMade.forEach(e => { - console.log(e.color,e.number,e.shape,e.filling); - }); //let deck5 = new Deck([0,1,2,3,4]); //console.log(`All cards with 5 attributes size ${deck5.allCards.length}`); diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 1c13a92..94df7a6 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -36,7 +36,7 @@ class Deck{ */ createCards(attributes){ let factory = new Factory(attributes) - return factory.concreteCardCreation(); + return factory.product } checkSet(selectedCards){ if(true){//isSet(selectedCards)){ diff --git a/src/Model/Factory.js b/src/Model/Factory.js index e85a853..7e57f18 100644 --- a/src/Model/Factory.js +++ b/src/Model/Factory.js @@ -4,6 +4,8 @@ class Factory{ this.product=this.concreteCardCreation(arrayOfAttributes,length); } attributesRequiredFun(arrayOfAttributes,length){ + console.log("arr attr") + console.log(arrayOfAttributes) let attributesRequiredTmp=[]; let nullArray=[0,0,0,0,0]; for(let i=0;i<5;i++){ @@ -18,6 +20,10 @@ class Factory{ attributesRequiredTmp.push(nullArray); } } + attributesRequiredTmp.forEach(e=>{ + console.log("tab index") + console.log(e); + }); return attributesRequiredTmp; } concreteCardCreation(arrayOfAttributes, length){ @@ -45,15 +51,13 @@ class Factory{ tabOfAllCards.push(new Card4WithoutNumber(attributes[0][n],attributes[2][s],attributes[3][f],attributes[4][o])); } else if(attributes[2][0]===0){ + console.log("jrentre la frro") tabOfAllCards.push(new Card4WithoutShape(attributes[0][n],attributes[1][s],attributes[3][f],attributes[4][o])); } else if(attributes[3][0]===0){ - console.log(attributes[0][n],attributes[1][s],attributes[2][f],attributes[4][o]); tabOfAllCards.push(new Card4WithoutFilling(attributes[0][n],attributes[1][s],attributes[2][f],attributes[4][o])); } else if(attributes[4][0]===0){ - console.log('rentre la'); - console.log(attributes[0][n],attributes[1][s],attributes[2][f],attributes[3][o]); tabOfAllCards.push(new Card4WithoutOutline(attributes[0][n],attributes[1][s],attributes[2][f],attributes[3][o])); } } From 889c843aa7c40dba8b611477e924947c81438093 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Tue, 7 Feb 2023 10:46:18 +0100 Subject: [PATCH 12/12] deck create, remove the cards from the last one --- src/Console/main.js | 54 +++++++++++++++++++++----------- src/Model/Card4WithoutOutline.js | 10 +++--- src/Model/Deck.js | 15 ++++----- src/Model/Factory.js | 28 ++++++++--------- 4 files changed, 62 insertions(+), 45 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index 2b9de4d..2668f88 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -31,28 +31,46 @@ console.groupEnd(); console.group('Deck'); -let deck = new Deck([0,1,3,4]); -console.log(`All cards with 4 attributes size ${deck.allCards.length}`); -console.log(`size output ${deck.outputCards.length}`); +let deck = new Deck([0,1,2,3]); +console.log(`All cards : ${deck.allCards.length}`); //Display all cards -console.log(`All cards`); -deck.allCards.forEach(e => { - //console.log(e.color,e.number,e.shape,e.filling); - console.log(e.color,e.number,e.filling,e.outline); - //console.log(e.color,e.number,e.shape,e.outline); -}); -console.log(`Output cards`); -// deck.outputCards.forEach(e => { -// console.log(e.getAttributes()); +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}`) +// deck.remainingCards.forEach(e => { +// console.log(e.getAttributes()); +// }); +console.log(`size output ${deck.outputCards.length}`); +console.log(`Output cards`); +deck.outputCards.forEach(e => { + console.log(e.getAttributes()); +}); console.log(`set already made ${deck.setMade}`); -console.log(`remaining cards:`); -deck.setMade.forEach(e => { - console.log(e.color,e.number,e.shape,e.filling); - }); +// deck.setMade.forEach(e => { +// console.log(e.color,e.number,e.shape,e.filling); +// }); -let customCard=[new Card('red',1,'diamond','stripped')]; -//deck.checkSet(customCard); +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(`remaining cards : ${deck.remainingCards.length}`) +// deck.remainingCards.forEach(e => { +// console.log(e.getAttributes()); +// }); + +console.log(`size output ${deck.outputCards.length}`); +console.log(`Output cards`); +deck.outputCards.forEach(e => { + console.log(e.getAttributes()); +}); //let deck5 = new Deck([0,1,2,3,4]); diff --git a/src/Model/Card4WithoutOutline.js b/src/Model/Card4WithoutOutline.js index c52c2f1..b1db83c 100644 --- a/src/Model/Card4WithoutOutline.js +++ b/src/Model/Card4WithoutOutline.js @@ -1,6 +1,9 @@ class Card4WithoutOutline extends Card{ constructor(color, number, shape, filling){ super(); + if(color==''){ + throw new EmptyParamaterException('Color'); + } if(number==''){ throw new EmptyParamaterException('Number'); } @@ -10,16 +13,13 @@ class Card4WithoutOutline extends Card{ if(filling==''){ throw new EmptyParamaterException('Filling'); } - if(color==''){ - throw new EmptyParamaterException('Color'); - } + this.color=color; this.number=number; this.shape=shape; this.filling=filling; - this.color=color; } getAttributes(){ - return [this.number,this.shape,this.filling,this.color]; + 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; diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 94df7a6..57e9d23 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -4,9 +4,10 @@ class Deck{ * @param {*} attributes : array with the attributes index for the cards */ constructor(attributes){ - console.log(attributes); + //console.log(attributes); this.allCards=this.createCards(attributes);// All the cards in the game - this.remainingCards=this.allCards;// cards in the stack + this.remainingCards=[] + this.remainingCards=this.remainingCards.concat(this.allCards);// cards in the stack this.outputCards=[];// 12 cards lay on the table this.setMade=[];// array with all the set already mades (array of set) this.createDeck(); @@ -41,7 +42,7 @@ class Deck{ checkSet(selectedCards){ if(true){//isSet(selectedCards)){ selectedCards.forEach(e => { - this.removeFromRemainingCards(e); + this.removeFromoutputCards(e); }); } } @@ -49,13 +50,13 @@ class Deck{ * * @param {*} selectedCards wehn a set is made, need to remove the card from the array remainingCards */ - removeFromRemainingCards(selectedCards){//better check of card type more opti + removeFromoutputCards(selectedCards){//better check of card type more opti let set=[]; - for(let i=0; i{ - console.log("tab index") - console.log(e); - }); return attributesRequiredTmp; } concreteCardCreation(arrayOfAttributes, length){ @@ -51,7 +50,6 @@ class Factory{ tabOfAllCards.push(new Card4WithoutNumber(attributes[0][n],attributes[2][s],attributes[3][f],attributes[4][o])); } else if(attributes[2][0]===0){ - console.log("jrentre la frro") tabOfAllCards.push(new Card4WithoutShape(attributes[0][n],attributes[1][s],attributes[3][f],attributes[4][o])); } else if(attributes[3][0]===0){