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 d4de90177a

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

@ -33,33 +33,31 @@ console.groupEnd();
// CREATE DECK // CREATE DECK
console.group('Deck'); console.group('Deck');
console.log("~~BEGINNING~~");
let deck = new Deck([0,1,2,3],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`);
// deck.allCards.forEach(e => { // deck.allCards.forEach(e => {
// console.log(e.color,e.number,e.shape,e.filling);//no outline // 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.filling,e.outline);//no shape
// //console.log(e.color,e.number,e.shape,e.outline);//no filling // console.log(e.color,e.number,e.shape,e.outline);//no filling
// }); // });
console.log(`remaining cards : ${deck.remainingCards.length}`) console.log(`remaining cards : ${deck.remainingCards.length}`)
// deck.remainingCards.forEach(e => {
// console.log(e.getAttributes());
// });
console.log(`size output ${deck.outputCards.length}`); console.log(`size output ${deck.outputCards.length}`);
console.group('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.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 // CHECK SET
console.log("CHECKING 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())
@ -67,9 +65,6 @@ 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}`)
// deck.remainingCards.forEach(e => {
// console.log(e.getAttributes());
// });
console.log(`size output ${deck.outputCards.length}`); console.log(`size output ${deck.outputCards.length}`);
console.group('Output cards'); console.group('Output cards');
deck.outputCards.forEach(e => { deck.outputCards.forEach(e => {
@ -77,12 +72,15 @@ deck.outputCards.forEach(e => {
}); });
console.groupEnd(); console.groupEnd();
console.group('set made'); console.log("~~SET MADE~~");
console.log(`set already made : ${deck.setMade.length}`); console.log(`set already made : ${deck.setMade.length}`);
deck.setMade.forEach(e => { deck.setMade.forEach(e => {//tab of tab of cards of set made
console.log(e.color,e.number,e.shape,e.filling); e.forEach(a=>{
console.log(a.color,a.number,a.shape,a.filling);
})
}); });
console.groupEnd(); // console.log(deck.setMade)
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}`);
@ -93,3 +91,23 @@ deck.setMade.forEach(e => {
//console.log(`random : ${deck.getRandCard()}`); //console.log(`random : ${deck.getRandCard()}`);
console.groupEnd(); 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);

@ -11,20 +11,31 @@ class Deck{
this.nbCards=nbCards; 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 of array with all the set already mades (array of set)
this.createDeck(12); this.createDeck(12);
} }
/** /**
* @brief creation of the deck : 12 cards lay in front of the player * @brief creation of the deck : 12 cards lay in front of the player
* @author Bastien Jacquelin * @author Bastien Jacquelin
*/ */
createDeck(nbCards){ createDeck(nbCards){
for (let i=0; i<nbCards; i++){ if(this.remainingCards.length==0){
const rand = this.getRandCard(); console.log("PLUS DE CARTES");
this.outputCards.push(this.remainingCards[rand]); return;
this.remainingCards.splice(rand,1); }
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)
}
} }
} }
/** /**
* *
* @returns random number in range of the array size * @returns random number in range of the array size
@ -34,6 +45,7 @@ class Deck{
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 * @param attributes : index of the attributes used
@ -44,6 +56,7 @@ class Deck{
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 * @brief verification of the validity of the set selected
* @param {*} selectedCards array of cards : set * @param {*} selectedCards array of cards : set
@ -51,9 +64,20 @@ class Deck{
*/ */
checkSet(selectedCards){ checkSet(selectedCards){
if(true){//isSet(selectedCards)){ if(true){//isSet(selectedCards)){
this.removeFromoutputCards(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;
} }
} }
/** /**
* @brief when a set is made, need to remove the card from the array remainingCards * @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 * @param {*} selectedCards cards which need to be removed from the outputcards

@ -2,4 +2,9 @@ class UnFoundCardException extends Error{
constructor(card){ constructor(card){
super(`Card ${card.color +" "+ card.shape+ " " + card.number +" "+ card.filling} is missing`); super(`Card ${card.color +" "+ card.shape+ " " + card.number +" "+ card.filling} is missing`);
} }
} }
class EmptyParamaterException extends Error{
constructor(field){
super(`Field ${field} missing`);
}
}

@ -95,7 +95,7 @@ class Factory{
} }
} }
else{ else{
//ERROR throw new EmptyParamaterException("ilegal number of attributes");
} }
return tabOfAllCards return tabOfAllCards
} }

@ -1,5 +0,0 @@
class EmptyParamaterException extends Error{
constructor(field){
super(`Field ${field} missing`);
}
}

@ -112,10 +112,15 @@ function numberOfSets5(deck){
return res return res
} }
/**
function setsCounter(set, numberForSet){ *
* @param {*} deck
* @param {*} numberForSet
* @returns
*/
function setsCounter(deck, numberForSet){
if(numberForSet === 3){ if(numberForSet === 3){
return numberOfSets3(set) return numberOfSets3(deck)
} }
if(numberForSet === 4){ if(numberForSet === 4){
return numberOfSets4(deck) return numberOfSets4(deck)

Loading…
Cancel
Save