fork download
  1. <?php
  2.  
  3. function scanSystem($x, $y) {
  4. echo 'You arrive at space corridor ' . $x . ', ' . $y . ".\n";
  5.  
  6. // Init the RNG based on the coordinates.
  7. // The added math is there to not have a universe mirrored at the diagonal
  8. // through sectors II/IV.
  9. srand(($x << 4) | $y);
  10.  
  11. $empty = rand(0, 100) > 20;
  12.  
  13. if ($empty) {
  14. echo 'There is nothing here.' . "\n";
  15. return;
  16. }
  17.  
  18. $type = rand(0, 20);
  19. if ($type > 9) {
  20. echo 'It\'s some kind of anomaly.' . "\t";
  21. return;
  22. }
  23.  
  24. $planets = rand(0, 10);
  25. echo 'It\'s a class ' . ($type + 1) . ' star with ' . ($planets ? $planets : 'no') . ' planets.' . "\n";
  26. echo '-- scan complete --' . "\n\n";
  27. }
  28.  
  29. // Let's do some scans
  30. scanSystem(4, 1);
  31. scanSystem(42, 12);
  32. scanSystem(12, 88);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
You arrive at space corridor 4, 1.
There is nothing here.
You arrive at space corridor 42, 12.
It's a class 1 star with 5 planets.
-- scan complete --

You arrive at space corridor 12, 88.
There is nothing here.