resolve conflicts
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
commit
577375fae9
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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…
Reference in new issue