any of you ever heard of 15 puzzle?

Discussion in 'OT Technology' started by D1G1T4L, May 6, 2005.

  1. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    Does anyone have an algorithm for it? Or even 8 puzzle? i cant find it anywhere on the net except in basic? Anyone got the algorithm in c++ or java? or at least pseudo code or something?
     
  2. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
  3. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    does that actually solve it for you? (you have to register to download)
    or just lets you play it?
     
  4. (^_^)

    (^_^) (^_^)

    Joined:
    May 4, 2001
    Messages:
    480
    Likes Received:
    0
    Location:
    Texas
    This was one of my first programs of the semester

    Code:
    <html>
      <head>
        <title>Game of 15</title>
          <script language="Javascript" type="text/javascript">
          <!--
    	// size of square
    	var square=4;
    
    	// initial placement of empty box
    	var blank=16;	
    
    	// keep track of the number of moves made
    	var moves=0;
    
    	// function to swap boxes		
    	function swap(id)
    	{
    		// if value is 0, then no move is made.  if value is 1, then swap is done.
    		var bool=0;
    
    		// get id value, chop off the "id" text, and change to integer
    		var txt=document.getElementById(id);
    		id=parseInt(id.substr(2));		
    
    		// check too see if it is a valid move to swap
    		if (((id + 1)==blank) || ((id - 1)==blank) || ((id + square)==blank) || ((id - square)==blank))		
    			bool=1;
    		// check for the odd case for numbers in the last column
    		if ((((((id - 1) % square)==0) && ((blank % square)==0)) || (((id % square)==0) && (((blank - 1) % square)==0))))
    			bool=0; 
    		
    		// swap
    		if (bool != 0)
    		{
    			var num=blank.toString();
    			document.getElementById("id" + num).value=txt.value;
    			txt.value=" ";
    			blank=id;
    			moves++;
    		}
    		// notify user that the swap was not possible
    		else
    			alert("Invalid move! Stop trying to cheat!");
    
    		// check to see if user has won
    		if ((document.fifteen.name1.value=="1") && (document.fifteen.name2.value=="2") && 
    		    (document.fifteen.name3.value=="3") && (document.fifteen.name4.value=="4") &&
    		    (document.fifteen.name5.value=="5") && (document.fifteen.name6.value=="6") && 
                        (document.fifteen.name7.value=="7") && (document.fifteen.name8.value=="8") &&
    		    (document.fifteen.name9.value=="9") && (document.fifteen.name10.value=="10") && 
                        (document.fifteen.name11.value=="11") && (document.fifteen.name12.value=="12") &&
    		    (document.fifteen.name13.value=="13") && (document.fifteen.name14.value=="14") && 
                        (document.fifteen.name15.value=="15") && (document.fifteen.name16.value==" "))
    		{
    			alert("Congratulations, you won in only " + moves + " moves! You're awesome!");
    			moves=0;
    			bool=0;
    		}
    	}
          //-->
          </script>
      </head>
    	
      <body>
        <form name="fifteen" method="post">
          <table width="100%" height="100%"><tr><td align="center" valign="middle">
            <table align="center" border="1" summary="Play the Puzzle Sliding Game of 15">
              <caption>Game of Fifteen</caption>
              <tr>
    	    <td><input name="name1" type="text" readonly size="1" value="1" id="id1" onClick="swap(this.id)"></td> 
    	    <td><input name="name2" type="text" readonly size="1" value="2" id="id2" onClick="swap(this.id)"></td> 
    	    <td><input name="name3" type="text" readonly size="1" value="3" id="id3" onClick="swap(this.id)"></td> 
    	    <td><input name="name4" type="text" readonly size="1" value="4" id="id4" onClick="swap(this.id)"></td> 
           	  </tr>
    	  <tr>
    	    <td><input name="name5" type="text" readonly size="1" value="5" id="id5" onClick="swap(this.id)"></td> 
    	    <td><input name="name6" type="text" readonly size="1" value="6" id="id6" onClick="swap(this.id)"></td> 
    	    <td><input name="name7" type="text" readonly size="1" value="7" id="id7" onClick="swap(this.id)"></td> 
    	    <td><input name="name8" type="text" readonly size="1" value="8" id="id8" onClick="swap(this.id)"></td> 
    	  </tr>
    	  <tr>
    	    <td><input name="name9" type="text" readonly size="1" value="9" id="id9" onClick="swap(this.id)"></td> 
    	    <td><input name="name10" type="text" readonly size="1" value="10" id="id10" onClick="swap(this.id)"></td> 
    	    <td><input name="name11" type="text" readonly size="1" value="15" id="id11" onClick="swap(this.id)"></td> 
    	    <td><input name="name12" type="text" readonly size="1" value="11" id="id12" onClick="swap(this.id)"></td> 
    	  </tr>
    	  <tr>
    	    <td><input name="name13" type="text" readonly size="1" value="13" id="id13" onClick="swap(this.id)"></td> 
    	    <td><input name="name14" type="text" readonly size="1" value="14" id="id14" onClick="swap(this.id)"></td> 
    	    <td><input name="name15" type="text" readonly size="1" value="12" id="id15" onClick="swap(this.id)"></td> 
    	    <td><input name="name16" type="text" readonly size="1" value=" " id="id16" onClick="swap(this.id)"></td> 
    	  </tr>
            </table>
          </td></tr></table>	
        </form>	
      </body>
    </html>
    
     
  5. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    It's not too hard to write on your own.
     
  6. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area

    nice! but i am looking for actual algorithm, i want to write a program that actually has a "solve' button and when u click it it solves it for you
     
  7. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area

    Not when the program solves the puzzle itself
     
  8. Wolf68k

    Wolf68k OT Supporter

    Joined:
    Dec 18, 2003
    Messages:
    4,861
    Likes Received:
    2
    Location:
    Houston, Texas
    I've seen a DOS program that can do that a few years ago
     
  9. MrMan

    MrMan New Member

    Joined:
    Jul 13, 2004
    Messages:
    308
    Likes Received:
    0
    My friend wrote a program like that and it does solve it, will ask.
     
  10. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    Yeah it is.
     
  11. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    so anyone have the actual algorithm to solving it? Not just the game itself but the actual solving part!
     
  12. MrMan

    MrMan New Member

    Joined:
    Jul 13, 2004
    Messages:
    308
    Likes Received:
    0
    sorry, friend don't have it anymore. it was in his laptop when it got stolen. I'm sure it has to be online somewhere.
     

Share This Page