daily pastebin goal
80%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. if(!isset($_GET['Answer']))
  3. {
  4. $dim_x = 20;
  5. $dim_y = 20;
  6.  
  7. $cell_count = $dim_x*$dim_y;
  8. $moves = array();
  9.  
  10. // MAZE CREATION
  11.  
  12. for($x=0;$x<$cell_count;$x++){
  13.         $maze[$x] = "01111"; // visted, NSEW
  14. }
  15.  
  16. $pos = rand(0,$cell_count-1);
  17.  
  18. $html .= "My start position is randomly set at $pos<br>";
  19.  
  20. $Start = $pos;
  21.  
  22. $maze[$pos]{0} = 1;
  23. $visited ++;
  24.  
  25. // determine possible directions
  26.     while($visited<$cell_count){
  27.         $possible = "";
  28.         if((floor($pos/$dim_x)==floor(($pos-1)/$dim_x)) and ($maze[$pos-1]{0}==0)){
  29.             $possible .= "W";
  30.         }
  31.         if((floor($pos/$dim_x)==floor(($pos+1)/$dim_x)) and ($maze[$pos+1]{0}==0)){
  32.             $possible .= "E";
  33.         }
  34.         if((($pos+$dim_x)<$cell_count) and ($maze[$pos+$dim_x]{0}==0)){
  35.             $possible .= "S";
  36.         }
  37.         if((($pos-$dim_x)>=0) and ($maze[$pos-$dim_x]{0}==0)){
  38.             $possible .= "N";
  39.         }
  40.         if($possible){
  41.             $visited ++;
  42.             array_push($moves,$pos);
  43.             $direction = $possible{rand(0,strlen($possible)-1)};
  44.             switch($direction){
  45.                 case "N":
  46.                     $maze[$pos]{1} = 0;
  47.                     $maze[$pos-$dim_x]{2} = 0;
  48.                     $pos -= $dim_x;
  49.                     break;
  50.                 case "S":
  51.                     $maze[$pos]{2} = 0;
  52.                     $maze[$pos+$dim_x]{1} = 0;
  53.                     $pos += $dim_x;
  54.                     break;
  55.                 case "E":
  56.                     $maze[$pos]{3} = 0;
  57.                     $maze[$pos+1]{4} = 0;
  58.                     $pos ++;
  59.                     break;
  60.                 case "W":
  61.                     $maze[$pos]{4} = 0;
  62.                     $maze[$pos-1]{3} = 0;
  63.                     $pos --;
  64.                     break;
  65.             }
  66.             $maze[$pos]{0} = 1;
  67.         }
  68.         else{
  69.             $pos = array_pop($moves);
  70.         }
  71.  
  72.     }
  73.  
  74.     $html = " <table style=\"border:2px solid black;\" cellspacing=\"0\" cellpadding=\"0\">";
  75.     for($x=0;$x<$cell_count;$x++){
  76.         if($x % $dim_x == 0){
  77.             $html .= "<tr>";
  78.         }
  79.         $style = $maze[$x]{2}.$maze[$x]{3};
  80.         if($x!=$pos){
  81.             $html.= "<td class=\"c$style p$x\">.</td>";
  82.         }
  83.         else{
  84.             $html .= "<td class=\"c$style p$x\"><strong>.</strong></td>";
  85.             $Last = $x;
  86.         }
  87.         if(($x % $dim_x) == ($dim_x-1)){
  88.             $html .= "</tr>";
  89.         }
  90.     }
  91.     $html .= "</table>";
  92. }
  93. else
  94. {
  95.     $html = "<h3 style='text-align: center;'>Sorry not good enough!</h3>";
  96. }
  97. ?>
  98. <html>
  99. <head>
  100. <style>
  101. body{line-height:5px;}
  102. table { margin: 20px auto; }
  103. td{text-align:center;}
  104. .c00{width:20px;height:20px;border:0px;}
  105. .c01{width:20px;height:20px;border:0px;border-right:1px solid black;}
  106. .c10{width:20px;height:20px;border:0px;border-bottom:1px solid black;}
  107. .c11{width:20px;height:20px;border:0px;border-bottom:1px solid black;border-right:1px solid black;}
  108. strong{color:red;}
  109. <?php
  110.     echo ".p$Start";
  111. ?>
  112. {
  113.     background-color: green;
  114. }
  115. <?php
  116.     echo ".p$Last";
  117. ?>
  118. {
  119.     background-color: red;
  120. }
  121. </style>
  122. </head>
  123. <body>
  124.     <?php echo $html;?>
  125. </body>
  126. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top