[Backup] HTML Testesasdasas

Ver o tópico anterior Ver o tópico seguinte Ir em baixo

[Backup] HTML Testesasdasas

Mensagem por DropLeet em Qui Dez 22, 2011 1:43 pm

Código:
<!--  This program (c) Stefan Knutsson 2003,2006  -->
<!--                                              -->
<!--  Email-  stefan.knutsson                    -->
<!--  address  @sverige.nu                        -->
<!--                                              -->
<!--  Photos of two goats (c) Stefan Knutsson    -->
<!--  Photo of Saab 9-3 (c) Saab Automobile      -->
 
<html><head>
<title>The Monty Hall problem</title>
<script language="JavaScript">
<!--
window.resizeTo(725,590);
window.moveTo(Math.floor((screen.width-725)/2),Math.floor((screen.height-590)/2));
CarPos=0; Goat1Pos=1; Goat2Pos=2;
Mode=FirstChoice=GuessesKeep=KeepWin=KeepLose=GuessesChange=ChangeWin=ChangeLose=TheRandom=RunAutoCycles=0;
Cheating=false;
 
if(!document.all){alert("Sorry, this program will probably not work with your web-browser. Please try again with MS Internet Explorer version 4 or later.");}
 
// ====================================================================================
 
function ClearCounters(){
   GuessesKeep=KeepWin=KeepLose=GuessesChange=ChangeWin=ChangeLose=0;
   document.all.WithKeep.innerText="0 times";
   document.all.KeepWin.innerText=0;
   document.all.KeepLose.innerText=0;
   document.all.WithChange.innerText="0 times";
   document.all.ChangeWin.innerText=0;
   document.all.ChangeLose.innerText=0;
   document.all.Line2.innerText="cars";
   document.all.Line3.innerText="(0%)";
   document.all.Line4.innerText="goats";
   document.all.Line5.innerText="(0%)";
   document.all.Line6.innerText="cars";
   document.all.Line7.innerText="(0%)";
   document.all.Line8.innerText="goats";
   document.all.Line9.innerText="(0%)";
   return true;
}
 
// --- --- --- --- --- --- --- --- --- ---
 
function Mclick(pos){
   if(Mode==1){Answer=Mode1Act(pos);}
   if(Mode==0){Answer=Mode0Act(pos);}
   return Answer;
}
 
// --- --- --- --- --- --- --- --- --- ---
 
function Mode0Act(pos){
   Mode=9;
   document.all["qm"+pos].innerText="!";
   PosToShow=(pos=="G1" || (pos=="C" && RandomNumber(2)==0)?"G2":"G1");
   document.all["photo"+PosToShow].style.visibility='visible';
   document.all["qm"+PosToShow].style.visibility='hidden';
   FirstChoice=pos;
   WriteMode1Text();
   Mode=1;
   return PosToShow;
}
 
// --- --- --- --- --- --- --- --- --- ---
 
function Mode1Act(pos){
   Mode=9;
   document.all.qmC.style.visibility='hidden';
   document.all.qmG1.style.visibility='hidden';
   document.all.qmG2.style.visibility='hidden';
   document.all.photoC.style.visibility='visible';
   document.all.photoG1.style.visibility='visible';
   document.all.photoG2.style.visibility='visible';
   document.all.Line1.innerHTML=(pos==FirstChoice?"You kept your choice":"You changed your choice")+", "+(pos=="C"?"You win the car !":"You lose");
 
   if(pos==FirstChoice) { // Keep choice
      GuessesKeep++;
      document.all.WithKeep.innerText=GuessesKeep+(GuessesKeep==1?" time":" times");
      if(pos=="C"){ // Car
         KeepWin++;
         document.all.KeepWin.innerText=KeepWin;
         if(KeepWin==1){ document.all.Line2.innerText="car"; }
         if(KeepWin==2){ document.all.Line2.innerText="cars"; }
      } else { // Goat
         KeepLose++;
         document.all.KeepLose.innerText=KeepLose;
         if(KeepLose==1){ document.all.Line4.innerText="goat"; }
         if(KeepLose==2){ document.all.Line4.innerText="goats"; }
      }
      document.all.Line3.innerText="(" + Math.floor(100*KeepWin/GuessesKeep)+"%)";
      document.all.Line5.innerText="(" + (100-Math.floor(100*KeepWin/GuessesKeep))+"%)";
 
   } else { // Change choice
      GuessesChange++;
      document.all.WithChange.innerText=GuessesChange+(GuessesChange==1?" time":" times");
      if(pos=="C"){ // Car
         ChangeWin++;
         document.all.ChangeWin.innerText=ChangeWin;
         if(ChangeWin==1){ document.all.Line6.innerText="car"; }
         if(ChangeWin==2){ document.all.Line6.innerText="cars"; }
      } else { // Goat
         ChangeLose++;
         document.all.ChangeLose.innerText=ChangeLose;
         if(ChangeLose==1){ document.all.Line8.innerText="goat"; }
         if(ChangeLose==2){ document.all.Line8.innerText="goats"; }
      }
      document.all.Line7.innerText="(" + Math.floor(100*ChangeWin/GuessesChange)+"%)";
      document.all.Line9.innerText="(" + (100-Math.floor(100*ChangeWin/GuessesChange))+"%)";
   }
   Mode=2;
   return true;
}
 
// --- --- --- --- --- --- --- --- --- ---
 
function Mode2Act(){ // Perform moving
   Mode=9;
   if(document.all.photoC.style.visibility=="visible"){
      Cpos=document.all.photoC.style.pixelLeft;
      G1pos=document.all.photoG1.style.pixelLeft;
      G2pos=document.all.photoG2.style.pixelLeft;
      if(Cpos<250){ document.all.photoC.style.pixelLeft=Cpos+5; }
      if(Cpos>250){ document.all.photoC.style.pixelLeft=Cpos-5; }
      if(G1pos<250){ document.all.photoG1.style.pixelLeft=G1pos+5; }
      if(G1pos>250){ document.all.photoG1.style.pixelLeft=G1pos-5; }
      if(G2pos<250){ document.all.photoG2.style.pixelLeft=G2pos+5; }
      if(G2pos>250){ document.all.photoG2.style.pixelLeft=G2pos-5; }
      if(G1pos==G2pos){ // Has reached mid pos
         document.all.qmC.style.pixelLeft=250;
         document.all.qmG1.style.pixelLeft=250;
         document.all.qmG2.style.pixelLeft=250;
         document.all.qmC.innerText="?";
         document.all.qmG1.innerText="?";
         document.all.qmG2.innerText="?";
         document.all.qmC.style.visibility='visible';
         document.all.qmG1.style.visibility='visible';
         document.all.qmG2.style.visibility='visible';
         document.all.photoC.style.visibility='hidden';
         document.all.photoG1.style.visibility='hidden';
         document.all.photoG2.style.visibility='hidden';
         document.all.qmC.style.color='#000000';
         document.all.qmG1.style.color='#000000';
         document.all.qmG2.style.color='#000000';
         document.all.Line1.innerText="";
         setTimeout('Mode2Act();', 222);
      } else {
         setTimeout('Mode2Act();', 1);
      }
   } else {
      G1pos=document.all.qmG1.style.pixelLeft-5;
      document.all.qmG1.style.pixelLeft=G1pos;
      document.all.qmG2.style.pixelLeft=document.all.qmG2.style.pixelLeft+5;
      if(G1pos>25){
         setTimeout('Mode2Act();', 1);
      } else {
         document.all.qmC.style.color='#ffffff';
         document.all.qmG1.style.color='#ffffff';
         document.all.qmG2.style.color='#ffffff';
         setTimeout('PrepareNewRound();', 2);
      }
   }
   return true;
}
 
// --- --- --- --- --- --- --- --- --- ---
 
function PrepareNewRound(){
   ScramblePositions();
   document.all.qmC.innerText="?";
   document.all.qmG1.innerText="?";
   document.all.qmG2.innerText="?";
   document.all.qmC.style.visibility='visible';
   document.all.photoC.style.visibility='hidden';
   document.all.qmG1.style.visibility='visible';
   document.all.photoG1.style.visibility='hidden';
   document.all.qmG2.style.visibility='visible';
   document.all.photoG2.style.visibility='hidden';
   document.all.Line1.innerHTML="Select one of the three boxes above";
   Mode=0;
   if(Cheating){SelectCheating();}
   return true;
}
 
// --- --- --- --- --- --- --- --- --- ---
 
function RandomNumber(SpanWidth){ // This function returns a random number
   if(TheRandom<=SpanWidth){
      Now=new Date();
      TheRandom=SpanWidth+Math.floor(Math.pow(Math.floor(Now.getTime())%131071,Math.PI));
   }
   ReturnValue=TheRandom%SpanWidth;
   TheRandom=Math.ceil(TheRandom/SpanWidth);
   return ReturnValue;
}
 
// --- --- --- --- --- --- --- --- --- ---
 
function RunAuto(HowToChoose){
   Mode=9;
   PrepareNewRound();
   FirstChoice=RandomNumber(3);
   FirstChoice=(FirstChoice>0?"G"+FirstChoice:"C");
   Mode=0;
   RevealedGoat=Mclick(FirstChoice);
   Mode=9;
   SecondChoice=(HowToChoose==1?(FirstChoice=="C"?"G"+(2-eval(RevealedGoat.charAt(1))):"C"):FirstChoice);
   Mode=1;
   RevealedGoat=Mclick(SecondChoice);
   Mode=9;
   RunAutoCycles--;
   if(RunAutoCycles>0){
      setTimeout("RunAuto("+HowToChoose+");",1);
   } else {
      PrepareNewRound(); // Scramble
      document.forms.AutoRun.Start.value="Start";
   }
   return true;
}
 
// --- --- --- --- --- --- --- --- --- ---
 
function RunButton(CyclesToRun,HowToChoose){
   if(RunAutoCycles>0){
      RunAutoCycles=0;
      document.forms.AutoRun.Start.value="Start";
   } else {
      document.forms.AutoRun.Start.value="Stop";
      RunAutoCycles=CyclesToRun;
      RunAuto(HowToChoose);
   }
   return true;
}
 
// --- --- --- --- --- --- --- --- --- ---
 
function ScramblePositions(){
   CarPos=RandomNumber(3);
   if(RandomNumber(2)==0){
      Goat1Pos=CarPos+1; Goat2Pos=CarPos+2;
   } else {
      Goat1Pos=CarPos+2; Goat2Pos=CarPos+1;
   }
   if(Goat1Pos>2){Goat1Pos-=3;}
   if(Goat2Pos>2){Goat2Pos-=3;}
   document.all.qmC.style.pixelLeft=25+225*CarPos;
   document.all.photoC.style.pixelLeft=25+225*CarPos;
   document.all.qmG1.style.pixelLeft=25+225*Goat1Pos;
   document.all.photoG1.style.pixelLeft=25+225*Goat1Pos;
   document.all.qmG2.style.pixelLeft=25+225*Goat2Pos;
   document.all.photoG2.style.pixelLeft=25+225*Goat2Pos;
   document.all.photoC.style.zIndex=(CarPos==1?4:3);
   document.all.photoG1.style.zIndex=(Goat1Pos==1?4:3);
   document.all.photoG2.style.zIndex=(Goat2Pos==1?4:3);
   return true;
}
 
// --- --- --- --- --- --- --- --- --- ---
 
function SelectCheating(){
   document.all.qmC.innerText=Cheating?"C":"?";
   document.all.qmG1.innerText=Cheating?"G":"?";
   document.all.qmG2.innerText=Cheating?"G":"?";
   if(Mode>0){
      document.all["qm"+FirstChoice].innerText="!";
      if(Mode==1){ WriteMode1Text(); }
   }
   return true;
}
 
// --- --- --- --- --- --- --- --- --- ---
 
function WriteMode1Text(){
   document.all.Line1.innerHTML="Click '!' to keep your first choice or '" + (Cheating?(FirstChoice=="C"?"G":"C"):"?") + "' to change it";
   return true;
}
 
 
//-->
</script>
<style>
<!--
body, table, select, input {font-family:Arial, Helvetica, sans-serif; color: #666666;}
-->
</style>
</head>
 
<body bgcolor="#dccbae" onLoad="PrepareNewRound(); document.all.div8.style.visibility='visible'; document.all.div10.style.visibility='visible'; document.all.div9.style.visibility='visible'; return true;">
<noscript><h1>Sorry, this program require Javascript, it will not work for you</h1></noscript>
 <div id="qmC" style="position:absolute; left:25px; top:25px; width:200px; height:200px; visibility: hidden; font-weight: bold; color: #ffffff; background-color:#666666; font-size: 120pt; text-align:center;" onMouseOver="this.style.color='#000000'; return true;" onMouseOut="this.style.color='#ffffff'; return true;" onClick="Mclick('C'); return true;">?</div> <div id="qmG1" style="position:absolute; left:250px; top:25px; width:200px; height:200px; visibility: hidden; font-weight: bold; color: #ffffff; background-color:#666666; font-size: 120pt; text-align:center;" onMouseOver="this.style.color='#000000'; return true;" onMouseOut="this.style.color='#ffffff'; return true;" onClick="Mclick('G1'); return true;">?</div> <div id="qmG2" style="position:absolute; left:475px; top:25px; width:200px; height:200px; visibility: hidden; font-weight: bold; color: #ffffff; background-color:#666666; font-size: 120pt; text-align:center;" onMouseOver="this.style.color='#000000'; return true;" onMouseOut="this.style.color='#ffffff'; return true;" onClick="Mclick('G2'); return true;">?</div>
 <div id="photoC" style="position:absolute; left:25px; top:25px; width:200px; height:200px; visibility: hidden;" onMouseOut="if(Mode==2){Mode2Act();} return true;" onClick="if(Mode==2){Mode2Act();} return true;"><img src="car.jpg" width=200 height=200 border=0></div> <div id="photoG1" style="position:absolute; left:250px; top:25px; width:200px; height:200px; visibility: hidden;" onMouseOut="if(Mode==2){Mode2Act();} return true;" onClick="if(Mode==2){Mode2Act();} return true;"><img src="goat1.jpg" width=200 height=200 border=0></div> <div id="photoG2" style="position:absolute; left:475px; top:25px; width:200px; height:200px; visibility: hidden;" onMouseOut="if(Mode==2){Mode2Act();} return true;" onClick="if(Mode==2){Mode2Act();} return true;"><img src="goat2.jpg" width=200 height=200 border=0></div>
 <div id="Line1" style="position:absolute; left:25px; top:250px; width:650px; height:30px; visibility: visible; font-weight: bold; color: #000000; font-size: 18pt; text-align:center;">Loading, Please wait...</div>
 <div id="div8" style="position:absolute; left:25px; top:310px; width:300px; height:65px; visibility: hidden; font-weight: bold; color: #666666; font-size: 12pt;  text-align:center; z-index:2;">
Keep choice: <span id="WithKeep">0 times</span>
<table><tr><td>Wins:</td><td id="KeepWin" align=right>0</td><td id="Line2">cars</td><td id="Line3">(0%)</td></tr>
<tr><td>Losses:</td><td id="KeepLose" align=right>0</td><td id="Line4">goats</td><td id="Line5">(0%)</td></tr></table>
</div>
 <div id="div9" style="position:absolute; left:375px; top:310px; width:300px; height:65px; visibility: hidden; font-weight: bold; color: #666666; font-size: 12pt;  text-align:center; z-index:2;">
Change choice: <span id="WithChange">0 times</span>
<table><tr><td>Wins:</td><td id="ChangeWin" align=right>0</td><td id="Line6">cars</td><td id="Line7">(0%)</td></tr>
<tr><td>Losses:</td><td id="ChangeLose" align=right>0</td><td id="Line8">goats</td><td id="Line9">(0%)</td></tr></table>
</div>
 <div id="div10" style="position:absolute; left:25px; top:385px; width:650px; height:30px; visibility: hidden; color: #666666; font-size: 8pt; text-align:center; z-index:2;">
<form name="AutoRun"><table border=0 style="color: #666666; font-size: 10pt;"><tr><td>Run </td>
<td><select name="Cycles" size=1><option value=10>10<option value=100 selected>100<option value=1000>1000</select></td>
<td> times and </td>
<td><select name="Decision"><option value=0>keep<option value=1>change</select></td>
<td id="Line10">the choice:</td>
<td width=50><input type=button value="Start" name="Start" title="Start/stop automatic run" onClick="RunButton(this.form.Cycles.value,this.form.Decision.value); return true;"></td>
<td style="font-weight: bold;">       </td>
<td><input type="checkbox" name="Cheat" onClick="Cheating=this.checked; SelectCheating(); return true;" title="Cheating on/off">Cheat</td><td style="color: font-weight: bold;">       </td><td><input type=button value="Clear result" title="Clear the counters above" onClick="return ClearCounters();">     &nbsp; </td><td><input type=button value="Help" onClick="document.all.div10.style.visibility='hidden'; document.all.helptext.style.visibility='visible'; return true;"></td></tr></table></form></div>
 <div id="div11" style="position:absolute; left:25px; top:308px; width:650px; height:110px; visibility: visible; background-color:#ffffff; z-index:1;"><img src="simbg_top.gif" width=650 height=18 border=0 alt="">
</div>
 <div id="helptext" style="position:absolute; left:25px; top:25px; width:650px; height:390px; visibility: hidden; background-color:#ffffff; z-index:3;"><img src="simbg_top.gif" width=650 height=18 border=0 alt="">
<table width=555 align=center style="font-size: 75%;"><tr><td><br>
This program is a simulator for the Monty Hall Problem, as described on the <a href=http://www.grand-illusions.com/articles/monty_hall/ target="_blank" style="text-decoration: none; color: #666666; font-weight: bold;}">Grand-illusion website</a>.<br><br>
The simulator randomly positions the car and the goats in the three black boxes. To start a run, click on one of the question marks. The simulator will then open a box with a goat in it. If you have chosen the car, the simulator will randomly select one of the two boxes with a goat. Click again when you have decided if you want to keep or change your first choice.<br><br>
When you have done your second choice the simulator will reveal the content of all boxes and update the statistics to show the results for changing and keeping respectively. A new run will be prepared when you move the cursor out from the photo or if you click again.<br><br>
You can let the computer run 10, 100 or 1000 runs after each other. Select the number of runs and if choice shall be kept or changed each time and start with the Start button. The simulator will randomly select a box and keep/change the choice after your wish. You can stop the run with the stop-button. <br><br>
By checking Cheat the boxes will be marked with C and G to show where the Car and the Goats are. <br><br>
The clear button will reset the statistics to zero.<br><br>
</td></tr></table>
<center>
<form name="CloseHelp"><input type=button value=" Ok " onClick="         document.all.helptext.style.visibility='hidden'; document.all.div10.style.visibility='visible';return true;"></form></center>
</div>
 
</body></html>

Sign:
Equipe GARRA em colaboração com a Myrmydons.
avatar
DropLeet


2° Sargento - Mestre


Mensagens : 430
Idade : 26 Masculino

Ficha do Personagem
Classe: Mago
Nv: 9x
Cultivo: Evil¹

Voltar ao Topo Ir em baixo

Ver o tópico anterior Ver o tópico seguinte Voltar ao Topo

- Tópicos similares

 
Permissão deste fórum:
Você não pode responder aos tópicos neste fórum