pb on deck, on creation of the deck
continuous-integration/drone/push Build is passing Details

pull/59/head^2^2
Bastien JACQUELIN 2 years ago
parent 6a06222449
commit 18a3c1281f

@ -1,7 +1,3 @@
// import { Card5 } from "../Model/Card5";
// import('../Model/Card5');
//import {Card} from '../Model/Card';
console.log("~#Test#~"); console.log("~#Test#~");
console.group('Card');//DONE console.group('Card');//DONE
@ -18,17 +14,33 @@ console.log(card1.equals(card3));//FALSE
console.log(card1.equals(card4));//FALSE console.log(card1.equals(card4));//FALSE
*/ */
console.groupEnd(); console.groupEnd();
console.group('Factory'); console.group('Factory');
console.log('Passed') console.log('Passed')
let fact3=new Factory([0,1,2]); // let fact3=new Factory([0,1,2]);
let fact4=new Factory([0,1,2,3]); let fact4=new Factory([0,1,2,3],3);
let fact5=new Factory([0,1,2,3,4]); //console.log(fact4.attributesDictionnary);
// let fact5=new Factory([0,1,2,3,4]);
console.groupEnd(); console.groupEnd();
// CREATE DECK
console.group('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~~"); console.log("~~BEGINNING~~");
let deck = new Deck([0,1,2,3],3); let deck = new Deck([0,1,2,3],3);
@ -87,8 +99,6 @@ console.groupEnd();
//console.log(`Remaining cards ${deck.remainingCards}`); //console.log(`Remaining cards ${deck.remainingCards}`);
//console.log(`random : ${deck.getRandCard()}`); //console.log(`random : ${deck.getRandCard()}`);
console.groupEnd();
// CHECK SET // CHECK SET
// console.log("~~CHECKING ALL SET~~") // console.log("~~CHECKING ALL SET~~")

@ -5,22 +5,35 @@ class Deck{
* @author Bastien Jacquelin * @author Bastien Jacquelin
*/ */
constructor(attributes,nbCards){ 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.allCards=this.createCards(attributes);// All the cards in the game
this.remainingCards=[] this.remainingCards=[];//init tab null
this.nbCards=nbCards; this.remainingCards=this.remainingCards.concat(this.allCards);// cards in the stack, init = all before creation of deck -> remove
this.remainingCards=this.remainingCards.concat(this.allCards);// cards in the stack
this.outputCards=[];// 12 cards lay on the table this.outputCards=[];// 12 cards lay on the table
this.setMade=[];// array of 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); 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 * @author Bastien Jacquelin
*/ */
createDeck(nbCards){ createDeck(nbCards){//toTest⌛
if(this.remainingCards.length==0){ if(this.remainingCards.length<this.nbCards){// no more cards
console.log("PLUS DE CARTES"); console.log("PLUS DE CARTES");
return; return;
} }
@ -30,7 +43,9 @@ class Deck{
this.outputCards.push(this.remainingCards[rand]); this.outputCards.push(this.remainingCards[rand]);
this.remainingCards.splice(rand,1); this.remainingCards.splice(rand,1);
} }
if(setsCounter(this.outputCards,this.nbCards)==0){ let nbSets=setsCounter(this.outputCards,this.nbCards);
console.log("nbSets",nbSets);
if(nbSets==0){
this.createDeck(this.nbCards) this.createDeck(this.nbCards)
} }
} }
@ -41,40 +56,32 @@ class Deck{
* @returns random number in range of the array size * @returns random number in range of the array size
* @author Bastien Jacquelin * @author Bastien Jacquelin
*/ */
getRandCard(){ getRandCard(){//working✅
const random = Math.floor(Math.random() * this.remainingCards.length); const random = Math.floor(Math.random() * this.remainingCards.length);
return random; return random;
} }
/**
*
* @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){
let factory = new Factory(attributes);
return factory.product;
}
/** /**
* @brief verification of the validity of the set selected * @brief verification of the validity of the set selected, call removeFromoutputCards when set is confirmed
* @param {*} selectedCards array of cards : set * @param {*} selectedCards array of cards : set
* @author Bastien Jacquelin * @author Bastien Jacquelin
*/ */
checkSet(selectedCards){ checkSet(selectedCards){//toTest⌛
if(true){//isSet(selectedCards)){ if(true){//isSet(selectedCards)){// is a set
if(this.outputCards.length==0){ if(this.outputCards.length==0){
console.log("C'est win") console.log("C'est win")
return; return 2;
} }
else{ else{
this.removeFromoutputCards(selectedCards); this.removeFromoutputCards(selectedCards);
return 1;
} }
} }
else if(this.remainingCards.length==0){ else if(this.remainingCards.length<this.nbCards){
console.log("C'est win") console.log("C'est win")
return; return 2;
} }
return 0;
} }
/** /**
@ -82,7 +89,7 @@ class Deck{
* @param {*} selectedCards cards which need to be removed from the outputcards * @param {*} selectedCards cards which need to be removed from the outputcards
* @author Bastien Jacquelin * @author Bastien Jacquelin
*/ */
removeFromoutputCards(selectedCards){//better check of card type more opti removeFromoutputCards(selectedCards){//working✅
let set=[]; let set=[];
selectedCards.forEach(element => { selectedCards.forEach(element => {
for(let i=0; i<this.outputCards.length;i++){ for(let i=0; i<this.outputCards.length;i++){
@ -93,11 +100,11 @@ class Deck{
} }
} }
}); });
if(set.length<1){ if(set.length<1){
throw new UnFoundCardException(selectedCards); throw new UnFoundCardException(selectedCards);
} }
else{ else{
console.log("set",set);
this.setMade.push(set); this.setMade.push(set);
this.createDeck(this.nbCards) this.createDeck(this.nbCards)
} }

@ -1,11 +1,12 @@
class Factory{ class Factory{
constructor(arrayOfAttributes){ constructor(arrayOfAttributes, nbAttributes){
this.nbAttr=nbAttributes;
this.dicoAttributes=this.attributesDictionnary(arrayOfAttributes,this.funArrayOfAttributes(arrayOfAttributes)); 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("arrayOfAttributes",this.funArrayOfAttributes(arrayOfAttributes));
//console.log("attributesDictionnary",this.dicoAttributes) // console.log("attributesDictionnary",this.dicoAttributes)
//console.log("attributesName",this.attributesName(this.dicoAttributes)); // console.log("attributesName",this.attributesName(this.dicoAttributes));
//console.log("allCards",this.product); // console.log("allCards",this.product);
} }
/** /**
@ -15,7 +16,7 @@ class Factory{
*/ */
funArrayOfAttributes(arrayOfIdxAttributes){//working✅ funArrayOfAttributes(arrayOfIdxAttributes){//working✅
let attr=[]; let attr=[];
let l=arrayOfIdxAttributes.length; let l=this.nbAttr;
arrayOfIdxAttributes.forEach(e => { arrayOfIdxAttributes.forEach(e => {
for (let i=0;i<l;i++){ for (let i=0;i<l;i++){
attr.push(ATTRIBUTES[e][i]); attr.push(ATTRIBUTES[e][i]);
@ -34,8 +35,8 @@ class Factory{
let dico={}; let dico={};
for (let i=0;i<l;i++){ for (let i=0;i<l;i++){
let tmp=[] let tmp=[]
for(let j=0;j<l;j++){ for(let j=0;j<this.nbAttr;j++){
tmp.push(arrayOfAllAttributes[(i*l)+j]); tmp.push(arrayOfAllAttributes[(i*this.nbAttr)+j]);
} }
dico[IDX_ATTRIBUTES[arrayOfIdxAttributes[i]]]=tmp; dico[IDX_ATTRIBUTES[arrayOfIdxAttributes[i]]]=tmp;
} }
@ -78,9 +79,8 @@ class Factory{
let tabOfAllCards=[]; let tabOfAllCards=[];
let dicoAttributes=this.dicoAttributes let dicoAttributes=this.dicoAttributes
let attributes=this.attributesName(dicoAttributes); let attributes=this.attributesName(dicoAttributes);
let nbAttributes=attributes.length; let nbAttributes=this.nbAttr;
console.log('nbAttributes',nbAttributes) if(attributes.length==3){
if(nbAttributes==3){
for (let c=0; c<nbAttributes; c++){ for (let c=0; c<nbAttributes; c++){
for (let n=0; n<nbAttributes; n++){ for (let n=0; n<nbAttributes; n++){
for (let s=0; s<nbAttributes; s++){ for (let s=0; s<nbAttributes; s++){
@ -92,7 +92,7 @@ class Factory{
} }
} }
} }
else if(nbAttributes==4){ else if(attributes.length==4){
for (let a=0; a<nbAttributes; a++){ for (let a=0; a<nbAttributes; a++){
for (let b=0; b<nbAttributes; b++){ for (let b=0; b<nbAttributes; b++){
for (let c=0; c<nbAttributes; c++){ for (let c=0; c<nbAttributes; c++){
@ -107,7 +107,7 @@ class Factory{
} }
} }
} }
else if(nbAttributes==5){ else if(attributes.length==5){
for (let a=0; a<nbAttributes; a++){ for (let a=0; a<nbAttributes; a++){
for (let b=0; b<nbAttributes; b++){ for (let b=0; b<nbAttributes; b++){
for (let c=0; c<nbAttributes; c++){ for (let c=0; c<nbAttributes; c++){
@ -130,61 +130,4 @@ class Factory{
} }
return tabOfAllCards return tabOfAllCards
} }
/*
concreteCardCreation(attributesDico){//progress
let tabOfAllCards=[];
let attributes=this.attributesRequiredFun(arrayOfAttributes);
let nbAttributes=length
if(nbAttributes==3){
for (let c=0; c<nbAttributes-1; c++){
for (let n=0; n<nbAttributes-1; n++){
for (let s=0; s<nbAttributes-1; s++){
tabOfAllCards.push(new Card3(ATTRIBUTES[0][c],ATTRIBUTES[1][n],ATTRIBUTES[2][s]));
}
}
}
}
else if(nbAttributes==4){
for (let n=0; n<nbAttributes-1; n++){
for (let s=0; s<nbAttributes-1; s++){
for (let f=0; f<nbAttributes-1; f++){
for (let o=0; o<nbAttributes-1; o++){
if(attributes[0][0]===0){
tabOfAllCards.push(new Card4WithoutColor(attributes[1][n],attributes[2][s],attributes[3][f],attributes[4][o]));
}
else if(attributes[1][0]===0){
tabOfAllCards.push(new Card4WithoutNumber(attributes[0][n],attributes[2][s],attributes[3][f],attributes[4][o]));
}
else if(attributes[2][0]===0){
tabOfAllCards.push(new Card4WithoutShape(attributes[0][n],attributes[1][s],attributes[3][f],attributes[4][o]));
}
else if(attributes[3][0]===0){
tabOfAllCards.push(new Card4WithoutFilling(attributes[0][n],attributes[1][s],attributes[2][f],attributes[4][o]));
}
else if(attributes[4][0]===0){
tabOfAllCards.push(new Card4WithoutOutline(attributes[0][n],attributes[1][s],attributes[2][f],attributes[3][o]));
}
}
}
}
}
}
else if(nbAttributes==5){
for (let c=0; c<nbAttributes-1; c++){
for (let n=0; n<nbAttributes-1; n++){
for (let s=0; s<nbAttributes-1; s++){
for (let f=0; f<nbAttributes-1; f++){
for (let o=0; o<nbAttributes-1; o++){
tabOfAllCards.push(new Card5(attributes[0][c],attributes[1][n],attributes[2][s],attributes[3][f],attributes[4][o]));
}
}
}
}
}
}
else{
throw new EmptyParamaterException("ilegal number of attributes");
}
return tabOfAllCards
}*/
} }

@ -67,7 +67,7 @@ function numberOfSets3(deck){
for(j=i+1;j<deck.length-1;j++){ for(j=i+1;j<deck.length-1;j++){
for(k=j+1;k<deck.length;k++){ for(k=j+1;k<deck.length;k++){
if(isSet([deck[i],deck[j],deck[k]])){ if(isSet([deck[i],deck[j],deck[k]])){
console.log(deck[i],deck[j],deck[k]) //console.log(deck[i],deck[j],deck[k])
res += 1 res += 1
} }
} }
@ -83,7 +83,7 @@ function numberOfSets4(deck){
for(k = j+1 ; k < deck.length - 1 ; k++){ for(k = j+1 ; k < deck.length - 1 ; k++){
for(l = k + 1 ; l < deck.length;l++){ for(l = k + 1 ; l < deck.length;l++){
if(isSet([deck[i],deck[j],deck[k]])){ if(isSet([deck[i],deck[j],deck[k]])){
console.log(deck[i],deck[j],deck[k],deck[l]) //console.log(deck[i],deck[j],deck[k],deck[l])
res += 1 res += 1
} }
} }
@ -101,7 +101,7 @@ function numberOfSets5(deck){
for(l = k + 1 ; l < deck.length - 1;l++){ for(l = k + 1 ; l < deck.length - 1;l++){
for(m = l + 1; m <deck.length;m++){ for(m = l + 1; m <deck.length;m++){
if(isSet([deck[i],deck[j],deck[k]])){ if(isSet([deck[i],deck[j],deck[k]])){
console.log(deck[i],deck[j],deck[k],deck[l],deck[m]) //console.log(deck[i],deck[j],deck[k],deck[l],deck[m])
res += 1 res += 1
} }
} }

Loading…
Cancel
Save