Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

8 AUTRES DAMES SUR UN ÉCHIQUIERS


Information sur la source

Description

Placer huit dames sur un échiquier. Mais en plus du programme précédent, montrer toutes les réflexions. Le programme est beaucoup plus long à cause notamment de l'affichage
 

Source

  • <html><head><title>Dames</title><style>td{width:20px;height:20px;font-family:Verdana,Arial,Helvetica;font-size:12px;text-align:center;color:white}</style></head>
  • <body bgcolor="silver"><hr /><script language="Javascript"><!--
  • var n=8,b=0,p=new Array(),a=new Array();
  • function abm(a,b){return a<b?b-a:a-b;}
  • function conflit(i,j,x,y){return (i==x)||(j==y)||(abm(i,x)==abm(j,y));}
  • function compat(i,j){for(var k=0;k<i;k++)if(conflit(i,j,k,p[k]))return false;return true;}
  • function reines(i){if(i>=n)return affiche();for(var j=0;j<n;j++)if(compat(i,j)){p[i]=j;reines(i+1);}}
  • function vide(){var x;for(x=0;x<n*n;x++)a[x]="";}
  • function aff()
  • {
  • with(document)
  • {
  • write("<td><table border='1px' width='"+20*n+"px' height='"+20*n+"px' cellpadding='0' cellspacing='0'>");
  • var x,y;
  • for(y=0;y<n;y++)
  • {
  • write("<tr>");
  • for(x=0;x<n;x++)
  • {
  • if((x+y)%2)write("<td bgcolor='black'>"+a[n*y+x]+"</td>");
  • else write("<td bgcolor='white'><font color='black'>"+a[n*y+x]+"</font></td>");
  • }
  • write("</tr>");
  • }
  • write("</table></td>");
  • vide();
  • }
  • }
  • function affiche()
  • {
  • with(document)
  • {
  • var x,c="®",z=n-1;
  • vide();
  • write("<table><tr>");
  • for(x=0;x<n;x++)a[p[x]+n*x]=c;aff();
  • for(x=0;x<n;x++)a[z-p[x]+n*x]=c;aff();
  • for(x=0;x<n;x++)a[x+n*p[x]]=c;aff();
  • for(x=0;x<n;x++)a[x+n*p[z-x]]=c;aff();
  • write("</tr><tr>");
  • for(x=0;x<n;x++)a[p[z-x]+n*x]=c;aff();
  • for(x=0;x<n;x++)a[z-p[z-x]+n*x]=c;aff();
  • for(x=0;x<n;x++)a[x+n*(z-p[x])]=c;aff();
  • for(x=0;x<n;x++)a[x+n*(z-p[z-x])]=c;aff();
  • write("</tr></table>"+(++b)+"<hr>");
  • }
  • }
  • reines(0);
  • //--></script></body></html>
<html><head><title>Dames</title><style>td{width:20px;height:20px;font-family:Verdana,Arial,Helvetica;font-size:12px;text-align:center;color:white}</style></head>
<body bgcolor="silver"><hr /><script language="Javascript"><!--
var n=8,b=0,p=new Array(),a=new Array();
function abm(a,b){return a<b?b-a:a-b;}
function conflit(i,j,x,y){return (i==x)||(j==y)||(abm(i,x)==abm(j,y));}
function compat(i,j){for(var k=0;k<i;k++)if(conflit(i,j,k,p[k]))return false;return true;}
function reines(i){if(i>=n)return affiche();for(var j=0;j<n;j++)if(compat(i,j)){p[i]=j;reines(i+1);}}
function vide(){var x;for(x=0;x<n*n;x++)a[x]="";}
function aff()
{
 with(document)
 {
  write("<td><table border='1px' width='"+20*n+"px' height='"+20*n+"px' cellpadding='0' cellspacing='0'>");
  var x,y;
  for(y=0;y<n;y++)
  {
   write("<tr>");
   for(x=0;x<n;x++)
   {
    if((x+y)%2)write("<td bgcolor='black'>"+a[n*y+x]+"</td>");
    else write("<td bgcolor='white'><font color='black'>"+a[n*y+x]+"</font></td>");
   }
   write("</tr>");
  }
  write("</table></td>");
  vide();
 }
}
function affiche()
{
 with(document)
 {
  var x,c="®",z=n-1;
  vide();
  write("<table><tr>");
  for(x=0;x<n;x++)a[p[x]+n*x]=c;aff();
  for(x=0;x<n;x++)a[z-p[x]+n*x]=c;aff();
  for(x=0;x<n;x++)a[x+n*p[x]]=c;aff();
  for(x=0;x<n;x++)a[x+n*p[z-x]]=c;aff();
  write("</tr><tr>");
  for(x=0;x<n;x++)a[p[z-x]+n*x]=c;aff();
  for(x=0;x<n;x++)a[z-p[z-x]+n*x]=c;aff();
  for(x=0;x<n;x++)a[x+n*(z-p[x])]=c;aff();
  for(x=0;x<n;x++)a[x+n*(z-p[z-x])]=c;aff();
  write("</tr></table>"+(++b)+"<hr>");
 }
}
reines(0);
//--></script></body></html>

Commentaires et avis

Aucun commentaire pour le moment.

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Novembre 2008
LMMJVSD
     12
3456789
10111213141516
17181920212223
24252627282930

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,359 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.