diff --git a/src/Console/Console.html b/src/Console/Console.html
index 77df2ba..991d7c0 100755
--- a/src/Console/Console.html
+++ b/src/Console/Console.html
@@ -15,12 +15,6 @@
-
-
-
-
-
-
diff --git a/src/Console/main.js b/src/Console/main.js
index d1c0bd0..cb2a25e 100755
--- a/src/Console/main.js
+++ b/src/Console/main.js
@@ -1,117 +1,47 @@
-//import { Card5 } from "../Model/Card5";
-//import('../Model/Card5');
-//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.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();
-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('Factory');
+console.log('Passed')
+// 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');
-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.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()}`);
-
+let deck = new Deck([0,1,2,3],3);
+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();
-
-// 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);
-
+let tab=[]
+tab.push("yeyee")
+console.log(tab)
+tab.push("gngngn")
+console.log(tab)
// CREATE HYPERSET
function checkList(list) {
@@ -136,4 +66,4 @@ 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
+console.log(checkList(list3)); // Retourne 2
diff --git a/src/Model/Card.js b/src/Model/Card.js
index 45c5972..864bac6 100755
--- a/src/Model/Card.js
+++ b/src/Model/Card.js
@@ -1,15 +1,34 @@
class Card{
- constructor(){}
+ /**
+ *
+ * @param {*} attributes : dictionnary of attributes : key : name of the attributes and value : value of the attributes
+ */
+ constructor(attributes){
+ this.attributes=attributes;
+ }
/**
*
* @returns all attributes of a card
*/
- getAttributes(){}
+ getAttributes(){//working✅
+ 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){//working✅
+ 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 100755
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 100755
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 100755
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 100755
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 100755
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 100755
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
diff --git a/src/Model/Const.js b/src/Model/Const.js
index b5fa204..e2a765c 100755
--- a/src/Model/Const.js
+++ b/src/Model/Const.js
@@ -1,22 +1,23 @@
-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','fullO','pointed','squared'];
-const tabOutline = ['full','dot','rect','spade','sharp'];
-const ATTRIBUTES=[tabColor,tabNumber,tabShape,tabFilling,tabOutline];
+const TAB_COLOR = ['red', 'purple', 'green', 'blue', 'orange'];
+const TAB_NUMBER = [1, 2, 3, 4, 5];
+const TAB_SHAPE = ['diamond', 'oval', 'squiggle', 'star', 'triangle'];
+const TAB_FILLING = ['empty', 'stripped', 'fullO', 'pointed', 'squared'];
+const TAB_OUTLINE = ['full', 'dot', 'rect', 'spade', 'sharp'];
+const ATTRIBUTES = [TAB_COLOR, TAB_NUMBER, TAB_SHAPE, TAB_FILLING, TAB_OUTLINE];
+const IDX_ATTRIBUTES = ["color", "number", "shape", "filling", "outline"];
const SHAPE_PATH = {
-squiggle : "m67.892902,12.746785c43.231313,-6.717223 107.352741,6.609823 121.028973,58.746408c13.676233,52.136585 -44.848649,161.467192 -45.07116,204.650732c4.566246,56.959708 83.805481,87.929227 22.329944,105.806022c-61.475536,17.876795 -126.122496,-1.855045 -143.73294,-41.933823c-17.610444,-40.07878 49.274638,-120.109409 46.14822,-188.091997c-3.126418,-67.982588 -21.873669,-70.257464 -49.613153,-80.177084c-27.739485,-9.919618 5.678801,-52.283035 48.910115,-59.000258z",
-diamond : "m98.544521,10.311863l-87.830189,189.330815l88.201143,189.644391l88.942329,-190.362741l-89.313283,-188.612465z",
-triangle : "M 185.39061,360.66757 14.609416,360.51258 100.06241,42.356689 Z",
-star : "m 153.53055,282.69958 -53.612735,-28.26169 -53.675199,28.1429 10.311217,-59.72213 -43.352051,-42.35147 59.985437,-8.6486 26.882141,-54.31757 26.76179,54.37694 59.9662,8.78146 -43.44577,42.25534 z",
-oval : "m11.49999,95.866646c0,-44.557076 37.442923,-81.999998 82.000002,-81.999998l12.000015,0c44.557076,0 81.999992,37.442923 81.999992,81.999998l0,206.133354c0,44.557098 -37.442917,82 -81.999992,82l-12.000015,0c-44.557079,0 -82.000002,-37.442902 -82.000002,-82l0,-206.133354z"
+ squiggle: "m67.892902,12.746785c43.231313,-6.717223 107.352741,6.609823 121.028973,58.746408c13.676233,52.136585 -44.848649,161.467192 -45.07116,204.650732c4.566246,56.959708 83.805481,87.929227 22.329944,105.806022c-61.475536,17.876795 -126.122496,-1.855045 -143.73294,-41.933823c-17.610444,-40.07878 49.274638,-120.109409 46.14822,-188.091997c-3.126418,-67.982588 -21.873669,-70.257464 -49.613153,-80.177084c-27.739485,-9.919618 5.678801,-52.283035 48.910115,-59.000258z",
+ diamond: "m98.544521,10.311863l-87.830189,189.330815l88.201143,189.644391l88.942329,-190.362741l-89.313283,-188.612465z",
+ triangle: "M 185.39061,360.66757 14.609416,360.51258 100.06241,42.356689 Z",
+ star: "m 153.53055,282.69958 -53.612735,-28.26169 -53.675199,28.1429 10.311217,-59.72213 -43.352051,-42.35147 59.985437,-8.6486 26.882141,-54.31757 26.76179,54.37694 59.9662,8.78146 -43.44577,42.25534 z",
+ oval: "m11.49999,95.866646c0,-44.557076 37.442923,-81.999998 82.000002,-81.999998l12.000015,0c44.557076,0 81.999992,37.442923 81.999992,81.999998l0,206.133354c0,44.557098 -37.442917,82 -81.999992,82l-12.000015,0c-44.557079,0 -82.000002,-37.442902 -82.000002,-82l0,-206.133354z"
};
const OUTLINE_SPEC = {
-full : {},
-dot : { "stroke-dasharray" : "1 20", "stroke-linecap" : "round" },
-rect : { "stroke-dasharray" : 70},
-spade : { "stroke-dasharray" : "10 15", "stroke-width" : 40},
-sharp : {}
+ full: {},
+ dot: { "stroke-dasharray": "1 20", "stroke-linecap": "round" },
+ rect: { "stroke-dasharray": 70 },
+ spade: { "stroke-dasharray": "10 15", "stroke-width": 40 },
+ sharp: {}
};
diff --git a/src/Model/Deck.js b/src/Model/Deck.js
index 2cb66a9..bde7dac 100755
--- a/src/Model/Deck.js
+++ b/src/Model/Deck.js
@@ -1,105 +1,108 @@
-class Deck{
- /**
- *
- * @param {*} attributes : array with the attributes index for the cards
- * @author Bastien Jacquelin
- */
- constructor(attributes,nbCards){
- //console.log(attributes);
- 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.outputCards=[];// 12 cards lay on the table
- this.setMade=[];// array of array with all the set already mades (array of set)
- this.createDeck(12);
+class Deck {
+ /**
+ *
+ * @param {*} attributes : array with the attributes index for the cards
+ * @author Bastien Jacquelin
+ */
+ constructor(attributes, nbCards) {
+ this.nbCards = nbCards;// number of card to do a set
+ this.allCards = this.createCards(attributes);// All the cards in the game
+ 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);
+ }
+ /**
+ *
+ * @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 random cards lay in front of the playe and remove card from the remainingCard array
+ * @author Bastien Jacquelin
+ */
+ createDeck(nbCards) {//toTest⌛
+ if (this.remainingCards.length < this.nbCards) {// no more cards
+ console.log("PLUS DE CARTES");
+ return;
}
-
- /**
- * @brief creation of the deck : 12 cards lay in front of the player
- * @author Bastien Jacquelin
- */
- createDeck(nbCards){
- if(this.remainingCards.length==0){
- console.log("PLUS DE CARTES");
- return;
- }
- else{
- for (let i=0; i {
- for(let i=0; i {
+ for (let i = 0; i < this.outputCards.length; i++) {
+ let e = this.outputCards[i]
+ if (e.equals(element)) {
+ set.push(e);
+ this.outputCards.splice(i, 1);
}
+ }
+ });
+ if (set.length < 1) {
+ throw new UnFoundCardException(selectedCards);
+ }
+ else {
+ this.setMade.push(set);
+ this.createDeck(this.nbCards)
}
-}
\ No newline at end of file
+ }
+}
diff --git a/src/Model/Factory.js b/src/Model/Factory.js
index 2ab720c..d75e7ef 100755
--- a/src/Model/Factory.js
+++ b/src/Model/Factory.js
@@ -1,7 +1,46 @@
class Factory{
- constructor(arrayOfAttributes){
- let length=arrayOfAttributes.length
- this.product=this.concreteCardCreation(arrayOfAttributes,length);
+ constructor(arrayOfAttributes, nbAttributes){
+ this.nbAttr=nbAttributes;
+ 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);
+
+ }
+ /**
+ *
+ * @param {*} arrayOfIdxAttributes index of attributes in ATTRIBUTES
+ * @returns array of all attributes
+ */
+ funArrayOfAttributes(arrayOfIdxAttributes){//working✅
+ let attr=[];
+ let l=this.nbAttr;
+ arrayOfIdxAttributes.forEach(e => {
+ for (let i=0;i 1")
+console.assert(numberOfSets5(realSet)==1)
+
+console.log("Number of Sets -> 0")
+console.assert(numberOfSets5(unRealSet)==0)
+
+console.groupEnd()
+
+
+card1 = new Card4WithoutColor("1","rond","plein","tapis")
+card2 = new Card4WithoutColor("2","rond","plein","tapis")
+card3 = new Card4WithoutColor("3","rond","plein","tapis")
+card4 = new Card4WithoutColor("4","rond","plein","tapis")
+
+card5 = new Card4WithoutColor("4","carre","vide","plein")
+
+realSet = [card1,card2,card3,card4]
+unRealSet = [card2,card3,card4,card5]
+
+
+console.group("FOR SET OF 4")
+
+console.log("Number of Sets -> 1")
+console.assert(numberOfSets4(realSet)==1)
+
+console.log("Number of Sets -> 0")
+console.assert(numberOfSets4(unRealSet)==0)
+
+console.groupEnd()