vérificatoin fonctionnelle

vérification_résultat
adplantade 5 years ago
parent 078f2b6b6b
commit f0715190b9

@ -18,7 +18,7 @@
var canvas2 = document.getElementById('canvas2'); var canvas2 = document.getElementById('canvas2');
var ctx2 = canvas2.getContext('2d'); var ctx2 = canvas2.getContext('2d');
var canvas3 = document.getElementById('canvas3'); var canvas3 = document.getElementById('canvas3');
var ctx3 = canvas3.getContext('2d'); var ctx3 = canvas3.getContext('2d');
@ -36,6 +36,7 @@
tab3=[]; tab3=[];
tab4=[]; tab4=[];
tabTotal=[]; tabTotal=[];
tabObjCmp=[];
mousePos=[]; mousePos=[];
colors=["red","blue","green","brown"]; colors=["red","blue","green","brown"];
@ -114,47 +115,66 @@
}) })
} }
function empiler() function empiler(obj=false)
{ {
tabTotal=[];
const unique = (val) => val.toString() != test.toString(); const unique = (val) => val.toString() != test.toString();
exists=false; exists=false;
tab1.forEach(element => { if(!obj)
tabTotal.push(element); {
}) tabTotal=[];
tab2.forEach(element => { tab1.forEach(element => {
colors.forEach(col => {
test=[element[0],element[1],col];
if(!exists)
exists=!tabTotal.every(unique);
})
if(!exists)
tabTotal.push(element); tabTotal.push(element);
exists=false; })
}) tab2.forEach(element => {
tab3.forEach(element => { colors.forEach(col => {
colors.forEach(col => { test=[element[0],element[1],col];
test=[element[0],element[1],col]; if(!exists)
exists=!tabTotal.every(unique);
})
if(!exists) if(!exists)
tabTotal.push(element);
exists=false;
})
tab3.forEach(element => {
colors.forEach(col => {
test=[element[0],element[1],col];
if(!exists)
exists=!tabTotal.every(unique); exists=!tabTotal.every(unique);
})
if(!exists)
tabTotal.push(element);
exists=false;
}) })
if(!exists) tab4.forEach(element => {
colors.forEach(col => {
test=[element[0],element[1],col];
if(!exists)
exists=!tabTotal.every(unique);
})
if(!exists)
tabTotal.push(element); tabTotal.push(element);
exists=false; exists=false;
}) })
tab4.forEach(element => { checkAllOK();
colors.forEach(col => { toutDessiner(tabTotal,canvasT,ctxT);
test=[element[0],element[1],col]; }
else{
tabObj[0].forEach(element => {
tabObjCmp.push(element);
})
tabObj[1].forEach(element => {
colors.forEach(col => {
test=[element[0],element[1],col];
if(!exists)
exists=!tabObjCmp.every(unique);
})
if(!exists) if(!exists)
exists=!tabTotal.every(unique); tabObjCmp.push(element);
exists=false;
}) })
if(!exists) }
tabTotal.push(element);
exists=false;
})
toutDessiner(tabTotal,canvasT,ctxT);
} }
function swap(letab, lecanvas, lectx,ladir){ function swap(letab, lecanvas, lectx,ladir){
@ -181,15 +201,14 @@
tabObj=[[],[]]; tabObj=[[],[]];
tabObj[0]=Array.from(tab1); tabObj[0]=Array.from(tab1);
tabObj[1]=Array.from(tab2); tabObj[1]=Array.from(tab2);
console.log(tabObj); tabObjCmp=[];
actions=getRandomInt(5); actions=getRandomInt(5);
while(actions>0){ while(actions>0){
tourneD(tabObj,canvasO,ctxO,getRandomInt(2)-1); tourneD(tabObj,canvasO,ctxO,getRandomInt(2)-1);
console.log(tabObj);
actions--; actions--;
} }
console.log("sec",tabObj); empiler(true);
toutDessiner(tabObj,canvasO,ctxO); toutDessiner(tabObj,canvasO,ctxO);
} }
@ -247,34 +266,58 @@
} }
} }
function checkAllOK(){
//const condition = (val) => val.toString() == element.toString();
exists=true;
//exists=!tabObjCmp.every(unique);
if(tabTotal.length==tabObjCmp.length)
{
for(i=0;i>tabTotal.length;i++)
{
exists*tabTotal[i].toString()==tabObjCmp[i].toString();
}
}
else
exists=false;
if(exists)
{
console.log("OK");
generateEasy();
}
}
canvas1.addEventListener("mousedown",function(e){ canvas1.addEventListener("mousedown",function(e){
mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)]; mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)];
}) })
canvas1.addEventListener("mouseup",function(e){ canvas1.addEventListener("mouseup",function(e){
rotationManager(e); rotationManager(e);
}) })
canvas2.addEventListener("mousedown",function(e){ canvas2.addEventListener("mousedown",function(e){
mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)]; mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)];
}) })
canvas2.addEventListener("mouseup",function(e){ canvas2.addEventListener("mouseup",function(e){
rotationManager(e); rotationManager(e);
}) })
canvas3.addEventListener("mousedown",function(e){ canvas3.addEventListener("mousedown",function(e){
mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)]; mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)];
}) })
canvas3.addEventListener("mouseup",function(e){ canvas3.addEventListener("mouseup",function(e){
rotationManager(e); rotationManager(e);
}) })
canvas4.addEventListener("mousedown",function(e){ canvas4.addEventListener("mousedown",function(e){
mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)]; mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)];
}) })
canvas4.addEventListener("mouseup",function(e){ canvas4.addEventListener("mouseup",function(e){
rotationManager(e); rotationManager(e);
}) })
@ -283,7 +326,7 @@
tab2.push([-3,-3,"green"],[-3,2,"red"],[1,2,"blue"],[3,-3,"brown"]); tab2.push([-3,-3,"green"],[-3,2,"red"],[1,2,"blue"],[3,-3,"brown"]);
tab3.push([-3,-3,"green"],[-3,2,"red"],[1,2,"blue"],[3,-3,"brown"]); tab3.push([-3,-3,"green"],[-3,2,"red"],[1,2,"blue"],[3,-3,"brown"]);
tab4.push([-3,-3,"green"],[-3,2,"red"],[1,2,"blue"],[3,-3,"brown"]); tab4.push([-3,-3,"green"],[-3,2,"red"],[1,2,"blue"],[3,-3,"brown"]);
toutDessiner(tab1,canvas1,ctx); toutDessiner(tab1,canvas1,ctx);
toutDessiner(tab2,canvas2,ctx2); toutDessiner(tab2,canvas2,ctx2);
toutDessiner(tab3,canvas3,ctx3); toutDessiner(tab3,canvas3,ctx3);

Loading…
Cancel
Save