commit
ababb7479c
@ -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;
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>My awesome blog</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>My awesome blog</h1>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script src="./Model/Card.js"></script>
|
||||||
|
<script src="./algo.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
main();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in new issue