From 83fe43ce67d44ddda957d7e5b529be488444cbc3 Mon Sep 17 00:00:00 2001 From: readhame Date: Fri, 24 Jul 2020 19:41:35 +0200 Subject: [PATCH] 4x4 V2 compteur --- HyperSet/.idea/workspace.xml | 7 +- HyperSet/vues/js/set.js | 437 +++++++++++++++++++++++++++++++++-- 2 files changed, 422 insertions(+), 22 deletions(-) diff --git a/HyperSet/.idea/workspace.xml b/HyperSet/.idea/workspace.xml index 2ff0e7e..9d78035 100644 --- a/HyperSet/.idea/workspace.xml +++ b/HyperSet/.idea/workspace.xml @@ -138,6 +138,9 @@ + + + @@ -181,10 +184,10 @@ - + - + diff --git a/HyperSet/vues/js/set.js b/HyperSet/vues/js/set.js index 9e5ac23..1179d38 100644 --- a/HyperSet/vues/js/set.js +++ b/HyperSet/vues/js/set.js @@ -344,7 +344,7 @@ var Game = { dataType: 'json', success: function (data) { self.cardsHS2 = data; - self.existingHyperSet2(); + // self.existingHyperSet2(); self.displayCardsHS2.call(self); self.setCardListenersHS2(); } @@ -1306,8 +1306,8 @@ var Game = { if (shapes1[3] !== undefined && colors1[3] !== undefined && fills1[3] !== undefined && borders1[3] !== undefined && numbers1[3] !== undefined) { if (shapes1[3] === shapesall[a] && colors1[3] === colorsall[a] && fills1[3] === fillsall[a] && borders1[3] === bordersall[a] && numbers1[3] === numbersall[a]) { if (this.isSet4(shapes1) && this.isSet4(colors1) && this.isSet4(fills1) && this.isSet4(borders1) && this.isSet4(numbers1)) { - //console.log('Set 4x5 : '); - //console.log(shapes1, colors1, fills1, borders1, numbers1); + console.log('Set 4x5 : '); + console.log(shapes1, colors1, fills1, borders1, numbers1); self.set3 = self.set3 + 1; } @@ -1417,8 +1417,8 @@ var Game = { if (shapes1[3] !== undefined && colors1[3] !== undefined && fills1[3] !== undefined && borders1[3] !== undefined && numbers1[3] !== undefined) { if (shapes1[3] === shapesall[a] && colors1[3] === colorsall[a] && fills1[3] === fillsall[a] && borders1[3] === bordersall[a] && numbers1[3] === numbersall[a]) { if (this.isSet5(shapes1) && this.isSet5(colors1) && this.isSet5(fills1) && this.isSet5(borders1) && this.isSet5(numbers1)) { - //console.log('Set 5x5 : '); - //console.log(shapes1, colors1, fills1, borders1, numbers1); + console.log('Set 5x5 : '); + console.log(shapes1, colors1, fills1, borders1, numbers1); self.set4 = self.set4 + 1; } @@ -2699,6 +2699,357 @@ var Game = { this.$nbSetsHS2.html(self.setHS2); },*/ + + testGeneration16Cartes: function(arr){ + var unique = []; + $.each(arr, function(i, el){ + if($.inArray(el, unique) === -1) unique.push(el); + }); + return unique.length; + + }, + + generer16Cartes: function(colors, shapes, fills, numbers, allCards){ + var possibleCards = []; + var colors1 = []; + var shapes1 =[]; + var fills1= []; + var numbers1= []; + var colors2 = []; + var shapes2 =[]; + var fills2= []; + var numbers2= []; + + var card1 = []; + var card2 = []; + var card3 = []; + var card4 = []; + var card5 = []; + var card6 = []; + var card7 = []; + var card8 = []; + var card9 = []; + var card10 = []; + var card11 = []; + var card12 = []; + var card13 = []; + var card14 = []; + var card15 = []; + var card16 = []; + + var colorsall= $.map(allCards, function(el) { return el.color;}); + var shapesall = $.map(allCards, function(el) { return el.shape; }); + var fillsall= $.map(allCards,function(el) { return el.fill; }); + var numbersall = $.map(allCards, function(el) { return el.number;}); + + var colorsSet = new Set(colors); + var shapesSet = new Set(shapes); + var fillsSet = new Set(fills); + var numbersSet = new Set(numbers); + + if( colors[0] === colors[1]){ + colors1.push(colors[1]); + }else { + if(colorsSet.has('green') && colorsSet.has('red') ){ + colors1.push('purple'); + colors2.push('lightblue'); + } + if(colorsSet.has('green') && colorsSet.has('purple')){ + colors1.push('red'); + colors2.push('lightblue'); + } + if(colorsSet.has('green') && colorsSet.has('lightblue')){ + colors1.push('red'); + colors2.push('purple'); + } + if(colorsSet.has('red') && colorsSet.has('purple')){ + colors1.push('green'); + colors2.push('lightblue'); + } + if(colorsSet.has('red') && colorsSet.has('lightblue')){ + colors1.push('green'); + colors2.push('purple'); + } + if(colorsSet.has('purple') && colorsSet.has('lightblue')){ + colors1.push('green'); + colors2.push('red'); + } + } + if( shapes[0] === shapes[1]){ + shapes1.push(shapes[1]); + }else { + if(shapesSet.has('oval') && shapesSet.has('diamond') ){ + shapes1.push('rectangle'); + shapes2.push('wave'); + } + if(shapesSet.has('oval') && shapesSet.has('rectangle')){ + shapes1.push('diamond'); + shapes2.push('wave'); + } + if(shapesSet.has('oval') && shapesSet.has('wave')){ + shapes1.push('diamond'); + shapes2.push('rectangle'); + } + if(shapesSet.has('diamond') && shapesSet.has('rectangle')){ + shapes1.push('oval'); + shapes2.push('wave'); + } + if(shapesSet.has('diamond') && shapesSet.has('wave')){ + shapes1.push('oval'); + shapes2.push('rectangle'); + } + if(shapesSet.has('rectangle') && shapesSet.has('wave')){ + shapes1.push('diamond'); + shapes2.push('oval'); + } + } + + if( fills[0] === fills[1]){ + fills1.push(fills[1]); + }else { + if(fillsSet.has('solid') && fillsSet.has('open') ){ + fills1.push('quadrillage'); + fills2.push('stripped'); + } + if(fillsSet.has('solid') && fillsSet.has('quadrillage')){ + fills1.push('open'); + fills2.push('stripped'); + } + if(fillsSet.has('solid') && fillsSet.has('stripped')){ + fills1.push('quadrillage'); + fills2.push('stripped'); + } + if(fillsSet.has('open') && fillsSet.has('quadrillage')){ + fills1.push('solid'); + fills2.push('wave'); + } + if(fillsSet.has('open') && fillsSet.has('stripped')){ + fills1.push('solid'); + fills2.push('quadrillage'); + } + if(fillsSet.has('stripped') && fillsSet.has('quadrillage')){ + fills1.push('solid'); + fills2.push('open'); + } + } + + if( numbers[0] === numbers[1]){ + numbers1.push(numbers[1]); + }else { + if(numbersSet.has(1) && numbersSet.has(2) ){ + numbers1.push(3); + numbers2.push(4); + } + if(numbersSet.has(1) && numbersSet.has(3)){ + numbers1.push(2); + numbers2.push(4); + } + if(numbersSet.has(1) && numbersSet.has(4)){ + numbers1.push(2); + numbers2.push(3); + } + if(numbersSet.has(2) && numbersSet.has(3)){ + numbers1.push(1); + numbers2.push(4); + } + if(numbersSet.has(2) && numbersSet.has(4)){ + numbers1.push(1); + numbers2.push(3); + } + if(numbersSet.has(3) && numbersSet.has(4)){ + numbers1.push(1); + numbers2.push(2); + } + } + + for (var a = 0 ; a < allCards.length; a++) { + if (shapes1[0] === shapesall[a] && colors1[0] === colorsall[a] && fills1[0] === fillsall[a] && numbers1[0] === numbersall[a]) { + card1.push({ + color : colors1[0], + shape : shapes1[0], + fill : fills1[0], + number: numbers1[0] + }); + possibleCards.push(card1); + } + if (shapes1[0] === shapesall[a] && colors2[0] === colorsall[a] && fills1[0] === fillsall[a] && numbers1[0] === numbersall[a]) { + if(colors2[0] !== undefined) { + card2.push({ + color: colors2[0], + shape: shapes1[0], + fill: fills1[0], + number: numbers1[0] + }); + possibleCards.push(card2); + } + } + if (shapes2[0] === shapesall[a] && colors1[0] === colorsall[a] && fills1[0] === fillsall[a] && numbers1[0] === numbersall[a]) { + if(shapes2[0] !== undefined) { + card3.push({ + color: colors1[0], + shape: shapes2[0], + fill: fills1[0], + number: numbers1[0] + }); + possibleCards.push(card3); + } + } + if (shapes1[0] === shapesall[a] && colors1[0] === colorsall[a] && fills2[0] === fillsall[a] && numbers1[0] === numbersall[a]) { + if(fills2[0] !== undefined) { + card4.push({ + color: colors1[0], + shape: shapes1[0], + fill: fills2[0], + number: numbers1[0] + }); + possibleCards.push(card4); + } + } + if (shapes1[0] === shapesall[a] && colors1[0] === colorsall[a] && fills1[0] === fillsall[a] && numbers2[0] === numbersall[a]) { + if (numbers2[0] !== undefined) { + card5.push({ + color: colors1[0], + shape: shapes1[0], + fill: fills1[0], + number: numbers2[0] + }); + possibleCards.push(card5); + } + } + + + + + + + if (shapes1[0] === shapesall[a] && colors1[0] === colorsall[a] && fills2[0] === fillsall[a] && numbers2[0] === numbersall[a]) { + if(fills2[0] !== undefined && numbers2[0] !== undefined) { + card6.push({ + color: colors1[0], + shape: shapes1[0], + fill: fills2[0], + number: numbers2[0] + }); + possibleCards.push(card6); + } + } + if (shapes2[0] === shapesall[a] && colors1[0] === colorsall[a] && fills1[0] === fillsall[a] && numbers2[0] === numbersall[a]) { + if(shapes2[0] !== undefined && numbers2[0] !== undefined) { + card7.push({ + color: colors1[0], + shape: shapes2[0], + fill: fills1[0], + number: numbers2[0] + }); + possibleCards.push(card7); + } + } + if (shapes2[0] === shapesall[a] && colors1[0] === colorsall[a] && fills2[0] === fillsall[a] && numbers1[0] === numbersall[a]) { + if(fills2[0] !== undefined && shapes2[0] !== undefined ) { + card8.push({ + color: colors1[0], + shape: shapes2[0], + fill: fills2[0], + number: numbers1[0] + }); + possibleCards.push(card8); + } + } + if (shapes1[0] === shapesall[a] && colors2[0] === colorsall[a] && fills2[0] === fillsall[a] && numbers1[0] === numbersall[a]) { + if (colors2[0] !== undefined && fills2[0] !== undefined) { + card9.push({ + color: colors2[0], + shape: shapes1[0], + fill: fills2[0], + number: numbers1[0] + }); + possibleCards.push(card9); + } + } + if (shapes1[0] === shapesall[a] && colors2[0] === colorsall[a] && fills1[0] === fillsall[a] && numbers2[0] === numbersall[a]) { + if (colors2[0] !== undefined && numbers2[0] !== undefined) { + card10.push({ + color: colors2[0], + shape: shapes1[0], + fill: fills1[0], + number: numbers2[0] + }); + possibleCards.push(card10); + } + } + if (shapes2[0] === shapesall[a] && colors2[0] === colorsall[a] && fills1[0] === fillsall[a] && numbers1[0] === numbersall[a]) { + if (colors2[0] !== undefined && shapes2[0] !== undefined) { + card11.push({ + color: colors2[0], + shape: shapes2[0], + fill: fills1[0], + number: numbers1[0] + }); + possibleCards.push(card11); + } + } + + + if (shapes2[0] === shapesall[a] && colors2[0] === colorsall[a] && fills2[0] === fillsall[a] && numbers2[0] === numbersall[a]) { + if (colors2[0] !== undefined && shapes2[0] !== undefined && fills2[0] !== undefined && numbers2[0] !== undefined ) { + card12.push({ + color: colors2[0], + shape: shapes2[0], + fill: fills2[0], + number: numbers2[0] + }); + possibleCards.push(card12); + } + } + if (shapes2[0] === shapesall[a] && colors2[0] === colorsall[a] && fills2[0] === fillsall[a] && numbers1[0] === numbersall[a]) { + if(colors2[0] !== undefined && shapes2[0] !== undefined && fills2[0] !== undefined) { + card13.push({ + color: colors2[0], + shape: shapes2[0], + fill: fills2[0], + number: numbers1[0] + }); + possibleCards.push(card13); + } + } + if (shapes2[0] === shapesall[a] && colors2[0] === colorsall[a] && fills1[0] === fillsall[a] && numbers2[0] === numbersall[a]) { + if(colors2[0] !== undefined && shapes2[0] !== undefined && numbers2[0] !== undefined ) { + card14.push({ + color: colors2[0], + shape: shapes2[0], + fill: fills1[0], + number: numbers2[0] + }); + possibleCards.push(card14); + } + } + if (shapes1[0] === shapesall[a] && colors2[0] === colorsall[a] && fills2[0] === fillsall[a] && numbers2[0] === numbersall[a]) { + if(colors2[0] !== undefined && fills2[0] !== undefined && numbers2[0] !== undefined ) { + card15.push({ + color: colors2[0], + shape: shapes1[0], + fill: fills2[0], + number: numbers2[0] + }); + possibleCards.push(card15); + } + } + if (shapes2[0] === shapesall[a] && colors1[0] === colorsall[a] && fills2[0] === fillsall[a] && numbers2[0] === numbersall[a]) { + if (shapes2[0] !== undefined && fills2[0] !== undefined && numbers2[0] !== undefined) { + card16.push({ + color: colors1[0], + shape: shapes2[0], + fill: fills2[0], + number: numbers2[0] + }); + possibleCards.push(card16); + } + } + + } + return possibleCards; + }, + existingHyperSet2: function() { var colors1 = []; var shapes1 =[]; @@ -2744,7 +3095,7 @@ var Game = { var cartes4 = cartes; - var carte1, carte3, carte4, carte5; + var carte1, carte3, carte4, carte5, carte6 =[]; var carte2; var card6ABC = []; var card6ABD = []; @@ -2775,7 +3126,12 @@ var Game = { - var i, j, a,l, m, k; + var tCardsDGE = []; + var pCards = []; + var pCards2 = []; + + + var i, j, a,l, m, k ,z; var colorsall= $.map(this.cardsHS2, function(el) { return el.color;}); var shapesall = $.map(this.cardsHS2, function(el) { return el.shape; }); @@ -2786,20 +3142,62 @@ var Game = { for(i=0; i < cartes.length-4; i++) { for (j = i + 1; j < cartes1.length - 3; j++) { for (k = j + 1; k < cartes2.length-2; k++) { - for (l = k + 1; l < cartes3.length-1; l++) { - for (m = l + 1; m < cartes4.length; m++) { - carte1 = cartes[i]; carte2 = cartes1[j]; - carte3 = cartes2[k]; - carte4 = cartes3[l]; - carte5 = cartes4[m]; + carte4 = cartes2[k]; - tCardsABC[0] = carte1; - tCardsABC[1] = carte2; - tCardsABC[2] = carte3; + colors1.splice(0, 1, carte1.color); + colors1.splice(1, 1, carte2.color); + + shapes1.splice(0, 1, carte1.shape); + shapes1.splice(1, 1, carte2.shape); + + fills1.splice(0, 1, carte1.fill); + fills1.splice(1, 1, carte2.fill); + + numbers1.splice(0, 1, carte1.number); + numbers1.splice(1, 1, carte2.number); + + + pCards = self.generer16Cartes(colors1,shapes1, fills1, numbers1, this.cardsHS2); + + for (z=0; z