From e0eba7cd43d916e962c3e9a6e88b3a2641fd6c72 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Thu, 23 Feb 2023 13:42:49 +0100 Subject: [PATCH 1/2] win of a game detected, fix little bug on card creation and algos --- src/Console/Console.html | 4 +- src/Console/main.js | 46 +++++++++++++------ src/Model/Deck.js | 21 ++++++++- ...{unfoundCardException.js => Exceptions.js} | 7 ++- src/Model/Factory.js | 2 +- src/Model/emptyParameterException.js | 5 -- 6 files changed, 60 insertions(+), 25 deletions(-) rename src/Model/{unfoundCardException.js => Exceptions.js} (59%) delete mode 100644 src/Model/emptyParameterException.js diff --git a/src/Console/Console.html b/src/Console/Console.html index 9ba88b8..23876d4 100644 --- a/src/Console/Console.html +++ b/src/Console/Console.html @@ -13,9 +13,9 @@
- - + + diff --git a/src/Console/main.js b/src/Console/main.js index 0d00811..6646e7b 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -33,33 +33,31 @@ 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}`); //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(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.group('Output cards'); deck.outputCards.forEach(e => { console.log(e.getAttributes()); }); console.groupEnd(); -console.log(`set already made ${deck.setMade}`); +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("~~CHECKING SET~~") console.log("Card to remove: ") console.log(deck.outputCards[0].getAttributes(),deck.outputCards[1].getAttributes(),deck.outputCards[2].getAttributes()) @@ -67,9 +65,6 @@ 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}`) -// deck.remainingCards.forEach(e => { -// console.log(e.getAttributes()); -// }); console.log(`size output ${deck.outputCards.length}`); console.group('Output cards'); deck.outputCards.forEach(e => { @@ -77,12 +72,15 @@ deck.outputCards.forEach(e => { }); console.groupEnd(); -console.group('set made'); +console.log("~~SET MADE~~"); console.log(`set already made : ${deck.setMade.length}`); -deck.setMade.forEach(e => { - console.log(e.color,e.number,e.shape,e.filling); +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.groupEnd(); +// 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}`); @@ -93,3 +91,23 @@ deck.setMade.forEach(e => { //console.log(`random : ${deck.getRandCard()}`); console.groupEnd(); + + +// 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 diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 03fe67f..877ae93 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -11,7 +11,7 @@ class Deck{ this.nbCards=nbCards; 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.setMade=[];// array of array with all the set already mades (array of set) this.createDeck(12); } /** @@ -20,10 +20,17 @@ class Deck{ */ createDeck(nbCards){ for (let i=0; i Date: Thu, 23 Feb 2023 13:55:37 +0100 Subject: [PATCH 2/2] check if no set in deck and auto add 3 others. Finish, just need to uncomment line 66 in Deck.js to activate set verification --- src/Model/Deck.js | 27 +++++++++++++++++---------- src/algo.js | 11 ++++++++--- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 877ae93..c4c7b41 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -14,24 +14,28 @@ class Deck{ this.setMade=[];// array of array with all the set already mades (array of set) this.createDeck(12); } + /** * @brief creation of the deck : 12 cards lay in front of the player * @author Bastien Jacquelin */ createDeck(nbCards){ - for (let i=0; i