|
|
@ -66,6 +66,7 @@
|
|
|
|
tabTotal=[];
|
|
|
|
tabTotal=[];
|
|
|
|
tabObjCmp=[];
|
|
|
|
tabObjCmp=[];
|
|
|
|
mousePos=[];
|
|
|
|
mousePos=[];
|
|
|
|
|
|
|
|
colorsAvailable=["red","yellow","green","purple"];
|
|
|
|
colors=["red","yellow","green","purple"];
|
|
|
|
colors=["red","yellow","green","purple"];
|
|
|
|
|
|
|
|
|
|
|
|
width=120; // 6 lignes de 50px
|
|
|
|
width=120; // 6 lignes de 50px
|
|
|
@ -111,7 +112,6 @@
|
|
|
|
img.src="ress/"+color+".png";
|
|
|
|
img.src="ress/"+color+".png";
|
|
|
|
|
|
|
|
|
|
|
|
img.onload = function(){
|
|
|
|
img.onload = function(){
|
|
|
|
console.log("x:"+x+" y:"+y+" col:"+color);
|
|
|
|
|
|
|
|
lectx.drawImage(img,nx,ny,width/6,height/6);
|
|
|
|
lectx.drawImage(img,nx,ny,width/6,height/6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -137,16 +137,19 @@
|
|
|
|
element[0]=-tmp;
|
|
|
|
element[0]=-tmp;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
|
|
else { // ce bout de code fout le merde yee
|
|
|
|
letab[sselem].forEach(element => {
|
|
|
|
letab[sselem].forEach(element => {
|
|
|
|
tmp=element[1];
|
|
|
|
tmp=element[1];
|
|
|
|
element[1]=element[0];
|
|
|
|
element[1]=element[0];
|
|
|
|
element[0]=-tmp;
|
|
|
|
element[0]=-tmp;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
toutDessiner(letab,lecanvas,lectx);
|
|
|
|
//console.log("pre-empiler :"+tabTotal);
|
|
|
|
|
|
|
|
empiler(sselem!=null);
|
|
|
|
|
|
|
|
//console.log("post-empiler :"+tabTotal);
|
|
|
|
if(sselem==null)
|
|
|
|
if(sselem==null)
|
|
|
|
empiler();
|
|
|
|
toutDessiner(letab,lecanvas,lectx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function toutDessiner(pts,lecanvas,lectx)
|
|
|
|
function toutDessiner(pts,lecanvas,lectx)
|
|
|
@ -154,8 +157,8 @@
|
|
|
|
lectx.clearRect(0, 0, lecanvas.width, lecanvas.height);
|
|
|
|
lectx.clearRect(0, 0, lecanvas.width, lecanvas.height);
|
|
|
|
if(pts[0])
|
|
|
|
if(pts[0])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var i=1*(typeof pts[0]==="boolean");
|
|
|
|
for(i=1;i<pts.length;i++)
|
|
|
|
for(i;i<pts.length;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(Array.isArray(pts[i]))
|
|
|
|
if(Array.isArray(pts[i]))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -170,7 +173,7 @@
|
|
|
|
function empiler(obj=false)
|
|
|
|
function empiler(obj=false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const unique = (val) => val.toString() != test.toString();
|
|
|
|
const unique = (val) => val.toString() != test.toString();
|
|
|
|
exists=false;
|
|
|
|
var exists=false;
|
|
|
|
|
|
|
|
|
|
|
|
if(!obj)
|
|
|
|
if(!obj)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -179,12 +182,17 @@
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
tab1.forEach(element => {
|
|
|
|
tab1.forEach(element => {
|
|
|
|
|
|
|
|
if(Array.isArray(element))
|
|
|
|
|
|
|
|
{
|
|
|
|
tabTotal.push(element);
|
|
|
|
tabTotal.push(element);
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(tab2[0]){
|
|
|
|
if(tab2[0]){
|
|
|
|
|
|
|
|
|
|
|
|
tab2.forEach(element => {
|
|
|
|
tab2.forEach(element => {
|
|
|
|
|
|
|
|
if(Array.isArray(element))
|
|
|
|
|
|
|
|
{
|
|
|
|
colors.forEach(col => {
|
|
|
|
colors.forEach(col => {
|
|
|
|
test=[element[0],element[1],col];
|
|
|
|
test=[element[0],element[1],col];
|
|
|
|
if(!exists)
|
|
|
|
if(!exists)
|
|
|
@ -193,12 +201,14 @@
|
|
|
|
if(!exists)
|
|
|
|
if(!exists)
|
|
|
|
tabTotal.push(element);
|
|
|
|
tabTotal.push(element);
|
|
|
|
exists=false;
|
|
|
|
exists=false;
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(tab3[0])
|
|
|
|
if(tab3[0])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
tab3.forEach(element => {
|
|
|
|
tab3.forEach(element => {
|
|
|
|
|
|
|
|
if(Array.isArray(element)){
|
|
|
|
colors.forEach(col => {
|
|
|
|
colors.forEach(col => {
|
|
|
|
test=[element[0],element[1],col];
|
|
|
|
test=[element[0],element[1],col];
|
|
|
|
if(!exists)
|
|
|
|
if(!exists)
|
|
|
@ -207,11 +217,14 @@
|
|
|
|
if(!exists)
|
|
|
|
if(!exists)
|
|
|
|
tabTotal.push(element);
|
|
|
|
tabTotal.push(element);
|
|
|
|
exists=false;
|
|
|
|
exists=false;
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(tab4[0]){
|
|
|
|
if(tab4[0]){
|
|
|
|
|
|
|
|
|
|
|
|
tab4.forEach(element => {
|
|
|
|
tab4.forEach(element => {
|
|
|
|
|
|
|
|
if(Array.isArray(element))
|
|
|
|
|
|
|
|
{
|
|
|
|
colors.forEach(col => {
|
|
|
|
colors.forEach(col => {
|
|
|
|
test=[element[0],element[1],col];
|
|
|
|
test=[element[0],element[1],col];
|
|
|
|
if(!exists)
|
|
|
|
if(!exists)
|
|
|
@ -220,17 +233,23 @@
|
|
|
|
if(!exists)
|
|
|
|
if(!exists)
|
|
|
|
tabTotal.push(element);
|
|
|
|
tabTotal.push(element);
|
|
|
|
exists=false;
|
|
|
|
exists=false;
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkAllOK();
|
|
|
|
checkAllOK();
|
|
|
|
toutDessiner(tabTotal,canvasT,ctxT);
|
|
|
|
toutDessiner(tabTotal,canvasT,ctxT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
tabObj[0].forEach(element => {
|
|
|
|
tabObjCmp=[];
|
|
|
|
tabObjCmp.push(element);
|
|
|
|
for(count=1;count<tabObj[0].length;count++)
|
|
|
|
})
|
|
|
|
{
|
|
|
|
|
|
|
|
tabObjCmp.push(tabObj[0][count]);
|
|
|
|
tabObj[1].forEach(element => {
|
|
|
|
}
|
|
|
|
|
|
|
|
for(tabCount=1;tabCount<tabObj.length;tabCount++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(elmCount=1;elmCount<tabObj[tabCount].length;elmCount++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
element=tabObj[tabCount][elmCount];
|
|
|
|
colors.forEach(col => {
|
|
|
|
colors.forEach(col => {
|
|
|
|
test=[element[0],element[1],col];
|
|
|
|
test=[element[0],element[1],col];
|
|
|
|
if(!exists)
|
|
|
|
if(!exists)
|
|
|
@ -239,7 +258,8 @@
|
|
|
|
if(!exists)
|
|
|
|
if(!exists)
|
|
|
|
tabObjCmp.push(element);
|
|
|
|
tabObjCmp.push(element);
|
|
|
|
exists=false;
|
|
|
|
exists=false;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -263,10 +283,20 @@
|
|
|
|
return Math.floor(Math.random() * Math.floor(max))+1;
|
|
|
|
return Math.floor(Math.random() * Math.floor(max))+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function copyMDArray(array) //permet la copie d'arrays sans copier les références
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var newArray = [];
|
|
|
|
|
|
|
|
array.forEach(element => {
|
|
|
|
|
|
|
|
newArray.push(Array.from(element))
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return newArray
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function generateEasy(){
|
|
|
|
function generateEasy(){
|
|
|
|
tabObj=[Array.from(tab1),Array.from(tab2),Array.from(tab3),Array.from(tab4)];
|
|
|
|
console.log(copyMDArray(tab1))
|
|
|
|
|
|
|
|
tabObj=[copyMDArray(tab1),copyMDArray(tab2),copyMDArray(tab3),copyMDArray(tab4)];
|
|
|
|
tabObjCmp=[];
|
|
|
|
tabObjCmp=[];
|
|
|
|
actions=getRandomInt(8);
|
|
|
|
actions=getRandomInt(8)+1;
|
|
|
|
|
|
|
|
|
|
|
|
while(actions>0){
|
|
|
|
while(actions>0){
|
|
|
|
tourneD(tabObj,canvasO,ctxO,getRandomInt(4)-1);
|
|
|
|
tourneD(tabObj,canvasO,ctxO,getRandomInt(4)-1);
|
|
|
@ -346,18 +376,22 @@
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if((mousePos[1]=="N" && dir == "O") || (mousePos[1]=="S" && dir == "E") || (mousePos[1]=="O" && dir == "S") || (mousePos[1]=="E" && dir == "N"))
|
|
|
|
if((mousePos[1]=="N" && dir == "O") || (mousePos[1]=="S" && dir == "E") || (mousePos[1]=="O" && dir == "S") || (mousePos[1]=="E" && dir == "N"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
console.log("G");
|
|
|
|
tourneG(letab,lecanvas,lectx);
|
|
|
|
tourneG(letab,lecanvas,lectx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if((mousePos[1] == "N" && dir == "E") || (mousePos[1] == "S" && dir == "O") || (mousePos[1] == "E" && dir == "S") || (mousePos[1] == "O" && dir == "N"))
|
|
|
|
else if((mousePos[1] == "N" && dir == "E") || (mousePos[1] == "S" && dir == "O") || (mousePos[1] == "E" && dir == "S") || (mousePos[1] == "O" && dir == "N"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
console.log("D");
|
|
|
|
tourneD(letab,lecanvas,lectx);
|
|
|
|
tourneD(letab,lecanvas,lectx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((mousePos[1] == "E" && dir == "O") || (mousePos[1] == "O" && dir == "E"))
|
|
|
|
else if ((mousePos[1] == "E" && dir == "O") || (mousePos[1] == "O" && dir == "E"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
console.log("V");
|
|
|
|
swap(letab,lecanvas,lectx,"V");
|
|
|
|
swap(letab,lecanvas,lectx,"V");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((mousePos[1] == "N" && dir == "S") || (mousePos[1] == "S" && dir == "N"))
|
|
|
|
else if ((mousePos[1] == "N" && dir == "S") || (mousePos[1] == "S" && dir == "N"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
console.log("H");
|
|
|
|
swap(letab,lecanvas,lectx,"H");
|
|
|
|
swap(letab,lecanvas,lectx,"H");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -373,18 +407,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
function checkAllOK(){
|
|
|
|
function checkAllOK(){
|
|
|
|
//const condition = (val) => val.toString() == element.toString();
|
|
|
|
//const condition = (val) => val.toString() == element.toString();
|
|
|
|
exists=true;
|
|
|
|
var exists=true;
|
|
|
|
//exists=!tabObjCmp.every(unique);
|
|
|
|
//exists=!tabObjCmp.every(unique);
|
|
|
|
|
|
|
|
console.log("---------------------------------");
|
|
|
|
if(tabTotal.length==tabObjCmp.length)
|
|
|
|
if(tabTotal.length==tabObjCmp.length)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for(i=0;i>tabTotal.length;i++)
|
|
|
|
console.log("bon nombre, tab total.l="+tabTotal.length);
|
|
|
|
|
|
|
|
var verifTab=[];
|
|
|
|
|
|
|
|
verifTab=copyMDArray(tabTotal);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(i=0;i<tabTotal.length;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
exists*tabTotal[i].toString()==tabObjCmp[i].toString();
|
|
|
|
const result = verifTab.filter(point => point.toString()==tabObjCmp[i].toString());
|
|
|
|
|
|
|
|
exists*=result.length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("long : "+ result.length + "ling : "+verifTab.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
console.log("mauvais nombre");
|
|
|
|
exists=false;
|
|
|
|
exists=false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(exists)
|
|
|
|
if(exists)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -409,8 +454,8 @@
|
|
|
|
//[fromTab,toTab]=[toTab,fromTab];
|
|
|
|
//[fromTab,toTab]=[toTab,fromTab];
|
|
|
|
toutDessiner(fromTab,eval("canvas"+from),eval("ctx"+from));
|
|
|
|
toutDessiner(fromTab,eval("canvas"+from),eval("ctx"+from));
|
|
|
|
toutDessiner(toTab,eval("canvas"+to),eval("ctx"+to));
|
|
|
|
toutDessiner(toTab,eval("canvas"+to),eval("ctx"+to));
|
|
|
|
toutDessiner(tabTotal,canvasT,ctxT);
|
|
|
|
|
|
|
|
empiler();
|
|
|
|
empiler();
|
|
|
|
|
|
|
|
toutDessiner(tabTotal,canvasT,ctxT);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|