|
|
|
@ -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<l;i++){
|
|
|
|
@ -44,7 +47,7 @@ class Factory{
|
|
|
|
|
* @param {*} arrayOfAttributes array
|
|
|
|
|
* @returns boolean
|
|
|
|
|
*/
|
|
|
|
|
inArray(i,arrayOfAttributes){
|
|
|
|
|
inArray(i,arrayOfAttributes){//toTest⌛
|
|
|
|
|
let finded=false;
|
|
|
|
|
for (let j=0;j<arrayOfAttributes.length;j++){
|
|
|
|
|
if(i==arrayOfAttributes[j]){
|
|
|
|
@ -54,12 +57,81 @@ class Factory{
|
|
|
|
|
return finded
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @biref create the right cards : 3,4,5 attributes
|
|
|
|
|
*
|
|
|
|
|
* @param {*} dico dictionnary of attributes
|
|
|
|
|
* @returns array of the key : name of the attributes
|
|
|
|
|
*/
|
|
|
|
|
attributesName(dico){//working✅
|
|
|
|
|
let attributes=[]
|
|
|
|
|
Object.entries(dico).forEach(function([key, value]) {
|
|
|
|
|
attributes.push(key);
|
|
|
|
|
});
|
|
|
|
|
return attributes
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @brief create the right cards : 3,4,5 attributes
|
|
|
|
|
* @param {*} arrayOfAttributes
|
|
|
|
|
* @param {*} length
|
|
|
|
|
* @returns array of all cards
|
|
|
|
|
*/
|
|
|
|
|
concreteCardCreation(attributesDico){
|
|
|
|
|
concreteCardCreation(){//working✅
|
|
|
|
|
let tabOfAllCards=[];
|
|
|
|
|
let dicoAttributes=this.dicoAttributes
|
|
|
|
|
let attributes=this.attributesName(dicoAttributes);
|
|
|
|
|
let nbAttributes=attributes.length;
|
|
|
|
|
console.log('nbAttributes',nbAttributes)
|
|
|
|
|
if(nbAttributes==3){
|
|
|
|
|
for (let c=0; c<nbAttributes; c++){
|
|
|
|
|
for (let n=0; n<nbAttributes; n++){
|
|
|
|
|
for (let s=0; s<nbAttributes; s++){
|
|
|
|
|
let attr1=attributes[0];
|
|
|
|
|
let attr2=attributes[1];
|
|
|
|
|
let attr3=attributes[2];
|
|
|
|
|
tabOfAllCards.push(new Card({attr1:dicoAttributes[attr1][c],attr2:dicoAttributes[attr2][n],attr3:dicoAttributes[attr3][s]}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(nbAttributes==4){
|
|
|
|
|
for (let a=0; a<nbAttributes; a++){
|
|
|
|
|
for (let b=0; b<nbAttributes; b++){
|
|
|
|
|
for (let c=0; c<nbAttributes; c++){
|
|
|
|
|
for (let d=0; d<nbAttributes; d++){
|
|
|
|
|
let attr1=attributes[0];
|
|
|
|
|
let attr2=attributes[1];
|
|
|
|
|
let attr3=attributes[2];
|
|
|
|
|
let attr4=attributes[3];
|
|
|
|
|
tabOfAllCards.push(new Card({attr1:dicoAttributes[attr1][a],attr2:dicoAttributes[attr2][b],attr3:dicoAttributes[attr3][c],attr4:dicoAttributes[attr4][d]}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(nbAttributes==5){
|
|
|
|
|
for (let a=0; a<nbAttributes; a++){
|
|
|
|
|
for (let b=0; b<nbAttributes; b++){
|
|
|
|
|
for (let c=0; c<nbAttributes; c++){
|
|
|
|
|
for (let d=0; d<nbAttributes; d++){
|
|
|
|
|
for (let e=0; e<nbAttributes; e++){
|
|
|
|
|
let attr1=attributes[0];
|
|
|
|
|
let attr2=attributes[1];
|
|
|
|
|
let attr3=attributes[2];
|
|
|
|
|
let attr4=attributes[3];
|
|
|
|
|
let attr5=attributes[4];
|
|
|
|
|
tabOfAllCards.push(new Card({attr1:dicoAttributes[attr1][a],attr2:dicoAttributes[attr2][b],attr3:dicoAttributes[attr3][c],attr4:dicoAttributes[attr4][d],attr5:dicoAttributes[attr5][e]}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
throw new EmptyParamaterException("ilegal number of attributes");
|
|
|
|
|
}
|
|
|
|
|
return tabOfAllCards
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
concreteCardCreation(attributesDico){//progress
|
|
|
|
|
let tabOfAllCards=[];
|
|
|
|
|
let attributes=this.attributesRequiredFun(arrayOfAttributes);
|
|
|
|
|
let nbAttributes=length
|
|
|
|
@ -114,5 +186,5 @@ class Factory{
|
|
|
|
|
throw new EmptyParamaterException("ilegal number of attributes");
|
|
|
|
|
}
|
|
|
|
|
return tabOfAllCards
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
}
|