resolve conflicts
continuous-integration/drone/push Build is passing Details

pull/59/head
remrem 2 years ago
commit 577375fae9

@ -15,12 +15,6 @@
<script src="../Model/Exceptions.js"></script>
<script src="../Model/Card.js"></script>
<script src="../algo.js"></script>
<script src="../Model/Card4WithoutColor.js"></script>
<script src="../Model/Card4WithoutFilling.js"></script>
<script src="../Model/Card4WithoutNumber.js"></script>
<script src="../Model/Card4WithoutOutline.js"></script>
<script src="../Model/Card4WithoutShape.js"></script>
<script src="../Model/Card5.js"></script>
<script src="../Model/Const.js"></script>
<script src="../Model/Factory.js"></script>
<script src="../Model/Deck.js"></script>

@ -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
console.log(checkList(list3)); // Retourne 2

@ -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}
equals(card){//working✅
let bool=true;
Object.entries(this.attributes).forEach(function([key, value]) {
if(card.attributes[key]!=value){
bool=false;
}
});
return bool;
}
}

@ -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 ;
}
}

@ -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 ;
}
}

@ -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 ;
}
}

@ -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;
}
}

@ -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 ;
}
}

@ -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};

@ -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: {}
};

@ -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<nbCards; i++){
const rand = this.getRandCard();
this.outputCards.push(this.remainingCards[rand]);
this.remainingCards.splice(rand,1);
}
if(setsCounter(this.outputCards,this.nbCards)==0){
this.createDeck(this.nbCards)
}
}
else {
for (let i = 0; i < nbCards; i++) {
const rand = this.getRandCard();
this.outputCards.push(this.remainingCards[rand]);
this.remainingCards.splice(rand, 1);
}
let nbSets = setsCounter(this.outputCards, this.nbCards);
console.log("nbSets", nbSets);
console.log("outputCards.length", this.outputCards.length);
console.log("remainingCards.length", this.remainingCards.length);
if (nbSets == 0) {
this.createDeck(this.nbCards)
}
}
}
/**
*
* @returns random number in range of the array size
* @author Bastien Jacquelin
*/
getRandCard(){
const random = Math.floor(Math.random() * this.remainingCards.length);
return random;
}
/**
*
* @returns random number in range of the array size
* @author Bastien Jacquelin
*/
getRandCard() {//working✅
const random = Math.floor(Math.random() * this.remainingCards.length);
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, call removeFromoutputCards when set is confirmed
* @param {*} selectedCards array of cards : set
* @author Bastien Jacquelin
*/
checkSet(selectedCards) {//toTest⌛
if (true) {//isSet(selectedCards)){// is a set
if (this.outputCards.length == 0) {
console.log("C'est win")
return 2;
}
else {
this.removeFromoutputCards(selectedCards);
return 1;
}
}
/**
* @brief verification of the validity of the set selected
* @param {*} selectedCards array of cards : set
* @author Bastien Jacquelin
*/
checkSet(selectedCards){
if(true){//isSet(selectedCards)){
if(this.outputCards.length==0){
console.log("C'est win")
return;
}
else{
this.removeFromoutputCards(selectedCards);
}
}
else if(this.remainingCards.length==0){
console.log("C'est win")
return;
}
else if (this.remainingCards.length < this.nbCards) {
console.log("C'est win")
return 2;
}
/**
* @brief when a set is made, need to remove the card from the array remainingCards
* @param {*} selectedCards cards which need to be removed from the outputcards
* @author Bastien Jacquelin
*/
removeFromoutputCards(selectedCards){//better check of card type more opti
let set=[];
selectedCards.forEach(element => {
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);
}
}
});
return 0;
}
if(set.length<1){
throw new UnFoundCardException(selectedCards);
}
else{
this.setMade.push(set);
this.createDeck(this.nbCards)
/**
* @brief when a set is made, need to remove the card from the array remainingCards
* @param {*} selectedCards cards which need to be removed from the outputcards
* @author Bastien Jacquelin
*/
removeFromoutputCards(selectedCards) {//working✅
let set = [];
selectedCards.forEach(element => {
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)
}
}
}
}

@ -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<l;i++){
attr.push(ATTRIBUTES[e][i]);
}
});
return attr;
}
/**
*
* @param {*} arrayOfIdxAttributes index of attributes in ATTRIBUTES
* @param {*} arrayOfAllAttributes array of all attributes
* @returns dictionnary with key : attribute and value : array of the possibilities of attributes
*/
attributesDictionnary(arrayOfIdxAttributes,arrayOfAllAttributes){//working✅
let l=arrayOfIdxAttributes.length;
let dico={};
for (let i=0;i<l;i++){
let tmp=[]
for(let j=0;j<this.nbAttr;j++){
tmp.push(arrayOfAllAttributes[(i*this.nbAttr)+j]);
}
dico[IDX_ATTRIBUTES[arrayOfIdxAttributes[i]]]=tmp;
}
return dico;
}
/**
* @brief check if i in arrayOfAttributes
@ -9,7 +48,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]){
@ -17,77 +56,70 @@ class Factory{
}
}
return finded
}
}
/**
* @brief create a matrix with the attributes of the cards : if attributes not defined : value 0
* @param {*} arrayOfAttributes
* @param {*} length
* @returns matrix of attributes
*
* @param {*} dico dictionnary of attributes
* @returns array of the key : name of the attributes
*/
attributesRequiredFun(arrayOfAttributes){
let attributesRequiredTmp=[];
let nullArray=[0,0,0,0,0];
for(let i=0;i<5;i++){
if(!this.inArray(i,arrayOfAttributes)){
attributesRequiredTmp.push(nullArray);
}
else{
attributesRequiredTmp.push(ATTRIBUTES[i]);
}
}
return attributesRequiredTmp;
attributesName(dico){//working✅
let attributes=[]
Object.entries(dico).forEach(function([key, value]) {
attributes.push(key);
});
return attributes
}
/**
* @biref create the right cards : 3,4,5 attributes
* @brief create the right cards : 3,4,5 attributes
* @param {*} arrayOfAttributes
* @param {*} length
* @returns array of all cards
*/
concreteCardCreation(arrayOfAttributes, length){
concreteCardCreation(){//working✅
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]));
let dicoAttributes=this.dicoAttributes
let attributes=this.attributesName(dicoAttributes);
let nbAttributes=this.nbAttr;
if(attributes.length==3){
for (let c=0; c<nbAttributes; c++){
for (let n=0; n<nbAttributes; n++){
for (let s=0; s<nbAttributes; s++){
attribDic[attributes[0]]=dicoAttributes[attributes[0]][a]
attribDic[attributes[1]]=dicoAttributes[attributes[1]][b]
attribDic[attributes[2]]=dicoAttributes[attributes[2]][c]
tabOfAllCards.push(new Card(attribDic))
}
}
}
}
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(attributes.length==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 attribDic = {};
attribDic[attributes[0]]=dicoAttributes[attributes[0]][a]
attribDic[attributes[1]]=dicoAttributes[attributes[1]][b]
attribDic[attributes[2]]=dicoAttributes[attributes[2]][c]
attribDic[attributes[3]]=dicoAttributes[attributes[3]][d]
tabOfAllCards.push(new Card(attribDic))
}
}
}
}
}
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 if(attributes.length==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++){
attribDic[attributes[0]]=dicoAttributes[attributes[0]][a]
attribDic[attributes[1]]=dicoAttributes[attributes[1]][b]
attribDic[attributes[2]]=dicoAttributes[attributes[2]][c]
attribDic[attributes[3]]=dicoAttributes[attributes[3]][d]
attribDic[attributes[4]]=dicoAttributes[attributes[4]][e]
tabOfAllCards.push(new Card(attribDic))
}
}
}

@ -67,7 +67,7 @@ function numberOfSets3(deck){
for(j=i+1;j<deck.length-1;j++){
for(k=j+1;k<deck.length;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
}
}
@ -83,7 +83,7 @@ function numberOfSets4(deck){
for(k = j+1 ; k < deck.length - 1 ; k++){
for(l = k + 1 ; l < deck.length;l++){
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
}
}
@ -101,7 +101,7 @@ function numberOfSets5(deck){
for(l = k + 1 ; l < deck.length - 1;l++){
for(m = l + 1; m <deck.length;m++){
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
}
}
@ -243,4 +243,4 @@ function isHyperset(cardsLeft, cardsRight) {
}
}
return true;
}
}

@ -0,0 +1,45 @@
console.log("TEST FOR ISSET")
let card1 = new Card5("bleu","1","rond","remplis","plein")
let card2 = new Card5("bleu","2","rond","remplis","plein")
let card3 = new Card5("bleu","3","rond","remplis","plein")
let card4 = new Card5("bleu","4","rond","remplis","plein")
let card5 = new Card5("bleu","5","rond","remplis","plein")
let card6 = new Card5("vert","6","carre","vide","tapis")
let realSet = [card1,card2,card3,card4,card5]
let unRealSet = [card2,card3,card4,card5,card6]
console.group("FOR SET OF 5")
console.log("Number of Sets -> 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()
Loading…
Cancel
Save