Merge branch 'master' of https://codefirst.iut.uca.fr/git/HyperSet/hyper-set into home-page(rem)
commit
d4f683bfb2
@ -1,14 +1,19 @@
|
||||
# HyperSet
|
||||
|
||||
## Description of the project
|
||||
|
||||
2nd Year Project of IT BUT in Aubière
|
||||
## Notes
|
||||
|
||||
## Subject
|
||||
- [Project subject](https://codefirst.iut.uca.fr/git/cedric.bouhours/Projets_SAE_S4/src/branch/master/Projets/Projet_11.md)
|
||||
- [Original project website](https://sancy.iut.uca.fr/~lafourcade/hyper-set-reda/HyperSet/)
|
||||
|
||||
## Description of the project
|
||||
|
||||
[link of the initial project](https://codefirst.iut.uca.fr/git/cedric.bouhours/Projets_SAE_S4/src/branch/master/Projets/Projet_11.md)
|
||||
null
|
||||
|
||||
## Created by :
|
||||
## Project Convention
|
||||
|
||||
LACOTE Raphaël JAULT Aurian ARNAL Rémi JACQUELIN Bastien
|
||||
- Functions names must be explicit, complete and follow **camelCase** naming
|
||||
- Variable follow **camelCase** naming convention
|
||||
- Opening brace must be at end of line
|
||||
- Directories names my_directory
|
||||
- Files names -> my_file.js
|
||||
- No useless comments
|
@ -1,33 +1,15 @@
|
||||
class Card{
|
||||
constructor(color, number, shape, filling){
|
||||
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;
|
||||
}
|
||||
constructor(){}
|
||||
/**
|
||||
* @returns array of all attributes :
|
||||
idx 1 : color
|
||||
idx 2 : number
|
||||
idx 3 : shape
|
||||
idx 4 : filling
|
||||
idx 5 : null
|
||||
* @author Bastien Jacquelin
|
||||
*
|
||||
* @returns all attributes of a card
|
||||
*/
|
||||
getAttributes(){
|
||||
return [this.color,this.number,this.shape,this.filling];
|
||||
}
|
||||
getAttributes(){}
|
||||
/**
|
||||
*
|
||||
* @param {*} card card to be compared with the current obj
|
||||
* @returns boolean
|
||||
*/
|
||||
equals(card){}
|
||||
|
||||
}//export {Card}
|
@ -0,0 +1,27 @@
|
||||
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 ;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
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 ;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
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 ;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
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 ;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
const tabColor = ['red','purple','green','blue','orange'];
|
||||
const tabNumber = [1,2,3,4,5];
|
||||
const tabShape = ['diamond','oval','wave','star','triangle'];
|
||||
const tabFilling = ['empty','stripped','full','pointed','squared'];
|
||||
const tabOutline = ['full','dotted ','hyphen','cloudy','sharpy'];
|
||||
const ATTRIBUTES=[tabColor,tabNumber,tabShape,tabFilling,tabOutline]
|
@ -1,19 +1,70 @@
|
||||
class Deck{
|
||||
constructor(){
|
||||
this.outputCards=this.createDeck();
|
||||
this.setMade=[];
|
||||
this.allCards=this.createCards();
|
||||
this.remainingCards=this.allCards;
|
||||
/**
|
||||
*
|
||||
* @param {*} attributes : array with the attributes index for the cards
|
||||
*/
|
||||
constructor(attributes){
|
||||
//console.log(attributes);
|
||||
this.allCards=this.createCards(attributes);// All the cards in the game
|
||||
this.remainingCards=[]
|
||||
this.remainingCards=this.remainingCards.concat(this.allCards);// cards in the stack
|
||||
this.outputCards=[];// 12 cards lay on the table
|
||||
this.setMade=[];// array with all the set already mades (array of set)
|
||||
this.createDeck();
|
||||
}
|
||||
/**
|
||||
* @brief creation of the deck : call factory to create the good cards
|
||||
*/
|
||||
createDeck(){
|
||||
for (let i=0; i<12; i++){
|
||||
|
||||
const rand = this.getRandCard();
|
||||
this.outputCards.push(this.remainingCards[rand]);
|
||||
this.remainingCards.splice(rand,1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @returns random number in range of the array size
|
||||
*/
|
||||
getRandCard(){
|
||||
Math.floor(Math.random() * remainingCards.length);
|
||||
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
|
||||
*/
|
||||
createCards(attributes){
|
||||
let factory = new Factory(attributes)
|
||||
return factory.product
|
||||
}
|
||||
checkSet(selectedCards){
|
||||
if(true){//isSet(selectedCards)){
|
||||
selectedCards.forEach(e => {
|
||||
this.removeFromoutputCards(e);
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {*} selectedCards wehn a set is made, need to remove the card from the array remainingCards
|
||||
*/
|
||||
removeFromoutputCards(selectedCards){//better check of card type more opti
|
||||
let set=[];
|
||||
for(let i=0; i<this.outputCards.length;i++){
|
||||
let e = this.outputCards[i]
|
||||
if(e.equals(selectedCards)){
|
||||
set.push(e);
|
||||
this.outputCards.splice(i,1);
|
||||
console.log("card remove : "+e.color,e.number,e.filling,e.shape);
|
||||
}
|
||||
}
|
||||
if(set.length!=1){
|
||||
throw new UnFoundCardException(selectedCards);
|
||||
}
|
||||
else{
|
||||
this.setMade.push(set);
|
||||
}
|
||||
createCards(){
|
||||
return 456;
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
class Factory{
|
||||
constructor(arrayOfAttributes){
|
||||
let length=arrayOfAttributes.length
|
||||
this.product=this.concreteCardCreation(arrayOfAttributes,length);
|
||||
}
|
||||
inArray(i,arrayOfAttributes){
|
||||
let finded=false;
|
||||
for (let j=0;j<arrayOfAttributes.length;j++){
|
||||
if(i==arrayOfAttributes[j]){
|
||||
finded=true;
|
||||
}
|
||||
}
|
||||
return finded
|
||||
}
|
||||
attributesRequiredFun(arrayOfAttributes,length){
|
||||
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;
|
||||
}
|
||||
concreteCardCreation(arrayOfAttributes, length){
|
||||
let tabOfAllCards=[];
|
||||
let attributes=this.attributesRequiredFun(arrayOfAttributes,length);
|
||||
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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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(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{
|
||||
//ERROR
|
||||
}
|
||||
return tabOfAllCards
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
class UnFoundCardException extends Error{
|
||||
constructor(card){
|
||||
super(`Card ${card.color +" "+ card.shape+ " " + card.number +" "+ card.filling} is missing`);
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
// Pseudo code
|
||||
//
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
let attributesMatrix = [];
|
||||
|
||||
cards.forEach(element => {
|
||||
attributesMatrix.push(element.getAttributes());
|
||||
});
|
||||
// Idéalement check si toute les listes d'attributs sont de même taille
|
||||
for(let i = 0; i < attributesMatrix[0].length; i++) {
|
||||
let listAttributes = []
|
||||
for(let j = 0; j < attributesMatrix.length; j++) {
|
||||
listAttributes.push(attributesMatrix[j][i]);
|
||||
}
|
||||
if(!checkAttributes(listAttributes)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function checkAttributes(attributes){
|
||||
let orderingMethod = "null"; // Can only take ["null", "same", "different"]
|
||||
let boolLoop = true;
|
||||
attributes.forEach((value, index) => {
|
||||
if(index !== attributes.length)
|
||||
{
|
||||
for (let i = index+1; i < attributes.length; i++)
|
||||
{
|
||||
if(attributes[i] === value)
|
||||
{
|
||||
if(orderingMethod === "null" || orderingMethod === "same")
|
||||
{
|
||||
orderingMethod = "same";
|
||||
}
|
||||
else
|
||||
{
|
||||
boolLoop = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(orderingMethod === "null" || orderingMethod === "different")
|
||||
{
|
||||
orderingMethod = "different"
|
||||
}
|
||||
else
|
||||
{
|
||||
boolLoop = false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
return boolLoop === true;
|
||||
}
|
Loading…
Reference in new issue