Merge branch 'master' of https://codefirst.iut.uca.fr/git/HyperSet/hyper-set into home-page(rem)

pull/59/head
remrem 2 years ago
commit 534d3d74ec

@ -27,5 +27,14 @@ steps:
CONTAINERNAME: hyperset CONTAINERNAME: hyperset
COMMAND: create COMMAND: create
OVERWRITE: true OVERWRITE: true
ADMINS: aurian.jault ADMINS: aurianjault,raphaellacote,bastienjacquelin,remiarnal
depends_on : [hyperset-build] depends_on : [hyperset-build]
- name: code-analysis
image: sonarsource/sonar-scanner-cli
environment:
SONAR_TOKEN:
from_secret: SONAR_TOKEN
commands:
- sonar-scanner -Dsonar.projectKey=hyperset -Dsonar.sources=. -Dsonar.host.url=https://codefirst.iut.uca.fr/sonar -Dsonar.login=$${SONAR_TOKEN}
depends_on: [ hyperset-build ]

@ -1,31 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Console</title>
</head>
<body>
<h1>Console - test </h1>
<section>
</section>
<script src="../Model/emptyParameterException.js"></script>
<script src="../Model/unfoundCardException.js"></script>
<script src="../Model/Card.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>
<script src="main.js"></script>
</body>
</html>

@ -30,8 +30,10 @@ try {
console.groupEnd(); console.groupEnd();
// CREATE DECK
console.group('Deck'); console.group('Deck');
let deck = new Deck([0,1,2,3]); let deck = new Deck([0,1,2,3],3);
console.log(`All cards : ${deck.allCards.length}`); console.log(`All cards : ${deck.allCards.length}`);
//Display all cards //Display all cards
console.log(`All cards display`); console.log(`All cards display`);
@ -45,14 +47,19 @@ console.log(`remaining cards : ${deck.remainingCards.length}`)
// console.log(e.getAttributes()); // console.log(e.getAttributes());
// }); // });
console.log(`size output ${deck.outputCards.length}`); console.log(`size output ${deck.outputCards.length}`);
console.log(`Output cards`); console.group('Output cards');
deck.outputCards.forEach(e => { deck.outputCards.forEach(e => {
console.log(e.getAttributes()); console.log(e.getAttributes());
}); });
console.groupEnd();
console.log(`set already made ${deck.setMade}`); console.log(`set already made ${deck.setMade}`);
// deck.setMade.forEach(e => { deck.setMade.forEach(e => {
// console.log(e.color,e.number,e.shape,e.filling); console.log(e.color,e.number,e.shape,e.filling);
// }); });
// CHECK SET
console.log("CHECKING SET")
console.log("Card to remove: ") console.log("Card to remove: ")
console.log(deck.outputCards[0].getAttributes(),deck.outputCards[1].getAttributes(),deck.outputCards[2].getAttributes()) console.log(deck.outputCards[0].getAttributes(),deck.outputCards[1].getAttributes(),deck.outputCards[2].getAttributes())
@ -60,18 +67,22 @@ let customCard=[deck.outputCards[0],deck.outputCards[1],deck.outputCards[2]];
deck.checkSet(customCard); deck.checkSet(customCard);
console.log(`remaining cards : ${deck.remainingCards.length}`) console.log(`remaining cards : ${deck.remainingCards.length}`)
console.log(`All cards : ${deck.allCards.length}`) console.log(`All cards : ${deck.allCards.length}`)
console.log(`remaining cards : ${deck.remainingCards.length}`)
// deck.remainingCards.forEach(e => { // deck.remainingCards.forEach(e => {
// console.log(e.getAttributes()); // console.log(e.getAttributes());
// }); // });
console.log(`size output ${deck.outputCards.length}`); console.log(`size output ${deck.outputCards.length}`);
console.log(`Output cards`); console.group('Output cards');
deck.outputCards.forEach(e => { deck.outputCards.forEach(e => {
console.log(e.getAttributes()); console.log(e.getAttributes());
}); });
console.groupEnd();
console.group('set made');
console.log(`set already made : ${deck.setMade.length}`);
deck.setMade.forEach(e => {
console.log(e.color,e.number,e.shape,e.filling);
});
console.groupEnd();
//let deck5 = new Deck([0,1,2,3,4]); //let deck5 = new Deck([0,1,2,3,4]);
//console.log(`All cards with 5 attributes size ${deck5.allCards.length}`); //console.log(`All cards with 5 attributes size ${deck5.allCards.length}`);

@ -2,21 +2,24 @@ class Deck{
/** /**
* *
* @param {*} attributes : array with the attributes index for the cards * @param {*} attributes : array with the attributes index for the cards
* @author Bastien Jacquelin
*/ */
constructor(attributes){ constructor(attributes,nbCards){
//console.log(attributes); //console.log(attributes);
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=[]
this.nbCards=nbCards;
this.remainingCards=this.remainingCards.concat(this.allCards);// cards in the stack 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 with all the set already mades (array of set) this.setMade=[];// array with all the set already mades (array of set)
this.createDeck(); this.createDeck(12);
} }
/** /**
* @brief creation of the deck : call factory to create the good cards * @brief creation of the deck : 12 cards lay in front of the player
* @author Bastien Jacquelin
*/ */
createDeck(){ createDeck(nbCards){
for (let i=0; i<12; i++){ for (let i=0; i<nbCards; i++){
const rand = this.getRandCard(); const rand = this.getRandCard();
this.outputCards.push(this.remainingCards[rand]); this.outputCards.push(this.remainingCards[rand]);
this.remainingCards.splice(rand,1); this.remainingCards.splice(rand,1);
@ -25,6 +28,7 @@ class Deck{
/** /**
* *
* @returns random number in range of the array size * @returns random number in range of the array size
* @author Bastien Jacquelin
*/ */
getRandCard(){ getRandCard(){
const random = Math.floor(Math.random() * this.remainingCards.length); const random = Math.floor(Math.random() * this.remainingCards.length);
@ -34,37 +38,45 @@ class Deck{
* *
* @param attributes : index of the attributes used * @param attributes : index of the attributes used
* @returns all cards: 81 in case of 4 attributes and 1024 if 5 attributes * @returns all cards: 81 in case of 4 attributes and 1024 if 5 attributes
* @author Bastien Jacquelin
*/ */
createCards(attributes){ createCards(attributes){
let factory = new Factory(attributes) let factory = new Factory(attributes)
return factory.product return factory.product
} }
/**
* @brief verification of the validity of the set selected
* @param {*} selectedCards array of cards : set
* @author Bastien Jacquelin
*/
checkSet(selectedCards){ checkSet(selectedCards){
if(true){//isSet(selectedCards)){ if(true){//isSet(selectedCards)){
selectedCards.forEach(e => { this.removeFromoutputCards(selectedCards);
this.removeFromoutputCards(e);
});
} }
} }
/** /**
* * @brief when a set is made, need to remove the card from the array remainingCards
* @param {*} selectedCards wehn 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 removeFromoutputCards(selectedCards){//better check of card type more opti
let set=[]; let set=[];
selectedCards.forEach(element => {
for(let i=0; i<this.outputCards.length;i++){ for(let i=0; i<this.outputCards.length;i++){
let e = this.outputCards[i] let e = this.outputCards[i]
if(e.equals(selectedCards)){ if(e.equals(element)){
set.push(e); set.push(e);
this.outputCards.splice(i,1); this.outputCards.splice(i,1);
console.log("card remove : "+e.color,e.number,e.filling,e.shape);
} }
} }
if(set.length!=1){ });
if(set.length<1){
throw new UnFoundCardException(selectedCards); throw new UnFoundCardException(selectedCards);
} }
else{ else{
this.setMade.push(set); this.setMade.push(set);
this.createDeck(this.nbCards)
} }
} }
} }

@ -3,6 +3,12 @@ class Factory{
let length=arrayOfAttributes.length let length=arrayOfAttributes.length
this.product=this.concreteCardCreation(arrayOfAttributes,length); this.product=this.concreteCardCreation(arrayOfAttributes,length);
} }
/**
* @brief check if i in arrayOfAttributes
* @param {*} i value
* @param {*} arrayOfAttributes array
* @returns boolean
*/
inArray(i,arrayOfAttributes){ inArray(i,arrayOfAttributes){
let finded=false; let finded=false;
for (let j=0;j<arrayOfAttributes.length;j++){ for (let j=0;j<arrayOfAttributes.length;j++){
@ -12,7 +18,13 @@ class Factory{
} }
return finded return finded
} }
attributesRequiredFun(arrayOfAttributes,length){ /**
* @brief create a matrix with the attributes of the cards : if attributes not defined : value 0
* @param {*} arrayOfAttributes
* @param {*} length
* @returns matrix of attributes
*/
attributesRequiredFun(arrayOfAttributes){
let attributesRequiredTmp=[]; let attributesRequiredTmp=[];
let nullArray=[0,0,0,0,0]; let nullArray=[0,0,0,0,0];
for(let i=0;i<5;i++){ for(let i=0;i<5;i++){
@ -25,9 +37,15 @@ class Factory{
} }
return attributesRequiredTmp; return attributesRequiredTmp;
} }
/**
* @biref create the right cards : 3,4,5 attributes
* @param {*} arrayOfAttributes
* @param {*} length
* @returns array of all cards
*/
concreteCardCreation(arrayOfAttributes, length){ concreteCardCreation(arrayOfAttributes, length){
let tabOfAllCards=[]; let tabOfAllCards=[];
let attributes=this.attributesRequiredFun(arrayOfAttributes,length); let attributes=this.attributesRequiredFun(arrayOfAttributes);
let nbAttributes=length let nbAttributes=length
if(nbAttributes==3){ if(nbAttributes==3){
for (let c=0; c<nbAttributes-1; c++){ for (let c=0; c<nbAttributes-1; c++){

@ -1,57 +1,5 @@
// Pseudo code import('./Model/Card.js')
//
/*
* function checkReslt(array <Cards>)
* {
* new array<array<Attrib>> matrice = vide
*
* forEach(array: value)
* {
* matrice.add(value.getAttrib)
* }
* Check all length of matrice
* for(i = 0; i<matrice[0])
* let array<attribut> tab
* for (j=0; j<len(matrice))
* tab.push matrice[j][i]
* if(!checkatrib(tab))
* {
* return false;
* }
* return true;
*
* }
*
*
* */
function main()
{
// "Stub de test"
let card1 = new Card("Purple","1","Triangle","Full");
let card2 = new Card("Purple","2","Triangle","Full");
let card3 = new Card("Purple","3","Triangle","Full");
let card8 = new Card("Purple","4","Triangle","Full");
let card9 = new Card("Purple","5","Triangle","Full");
let card0 = new Card("Purple","6","Triangle","Full");
let card10 = new Card("Purple","7","Triangle","Full");
let card4 = new Card("Purple","1","Triangle","Full");
let card5 = new Card("Purple","2","Triangle","Full");
let card6 = new Card("Purple","1","Triangle","Full");
console.group("TEST TRUE")
if(isSet([card1,card2,card3,card8,card9,card0,card10]))
{
console.log("TRUE")
}
else
{
console.log("FALSE")
}
console.groupEnd()
}
function isSet(cards) function isSet(cards)
{ {
@ -110,3 +58,72 @@ function checkAttributes(attributes){
}); });
return boolLoop === true; return boolLoop === true;
} }
// The digit refere to the number of cards required to make a set
//
function numberOfSets3(deck){
let res = 0
for(i=0;i<deck.length - 2;i++){
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])
res += 1
}
}
}
}
return res
}
function numberOfSets4(deck){
let res = 0
for(i = 0 ; i < deck.length - 3; i ++){
for(j = i+1 ; j < deck.length - 2; j++){
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])
res += 1
}
}
}
}
}
return res
}
function numberOfSets5(deck){
let res = 0
for(i = 0 ; i < deck.length - 4; i ++){
for(j = i+1 ; j < deck.length - 3; j++){
for(k = j+1 ; k < deck.length - 2 ; k++){
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])
res += 1
}
}
}
}
}
}
return res
}
function setsCounter(set, numberForSet){
if(numberForSet === 3){
return numberOfSets3(set)
}
if(numberForSet === 4){
return numberOfSets4(deck)
}
if(numberForSet === 5){
return numberOfSets5(deck)
}
console.error('The number of cards in a Set is not existing', numberForSet)
}

Loading…
Cancel
Save