Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use GD;
  6.  
  7. require "../lib/account.pl";
  8.  
  9. my $username = "OvO";
  10. my $password = "Mammatin123";
  11.  
  12. my $image = new GD::Image(3000,3000);
  13. my $white = $image->colorAllocate(255,255,255);
  14. my $black = $image->colorAllocate(0,0,0);
  15. my $grey = $image->colorAllocate(170,170,170);
  16. my $url = 'http://www.hacker.org/challenge/misc/maze.php?steps=';
  17.  
  18.  
  19. my $browser = login($username,$password);
  20. if($browser) {
  21. no warnings 'recursion';
  22. solve_maze("D",1500,20);
  23. }
  24.  
  25. sub save_image {
  26. open IMAGE, ">maze.png";
  27. binmode IMAGE;
  28. print IMAGE $image->png;
  29. close IMAGE;
  30. }
  31.  
  32. # Backtracking für den Endsieg
  33. sub solve_maze {
  34. my ($way,$x,$y) = @_;
  35. my $response = $browser->get($url.$way);
  36. my $dir = substr($way,-1,1);
  37.  
  38. if($response->code == 503) {
  39. return solve_maze($way,$x,$y);
  40. }
  41.  
  42. if($response->content =~ /boom$/ or $response->content =~ /off the edge of the world/) {
  43. print "$way -> boom\n";
  44. if($dir eq 'D') {
  45. $image->line($x-5,$y-5,$x+5,$y-5,$black);
  46. } elsif($dir eq 'R') {
  47. $image->line($x-5,$y-5,$x-5,$y+5,$black);
  48. } elsif($dir eq 'L') {
  49. $image->line($x+5,$y-5,$x+5,$y+5,$black);
  50. } elsif($dir eq 'U') {
  51. $image->line($x-5,$y+5,$x+5,$y+5,$black);
  52. }
  53. save_image();
  54. return 1;
  55. } elsif($response->content =~ /keep moving.../) {
  56. if($dir ne 'U') {
  57. if(solve_maze($way.'D',$x,$y+10) == 0) {
  58. return 0;
  59. }
  60. }
  61.  
  62. if($dir ne 'L') {
  63. if(solve_maze($way.'R',$x+10,$y) == 0) {
  64. return 0;
  65. }
  66. }
  67.  
  68. if($dir ne 'R') {
  69. if(solve_maze($way.'L',$x-10,$y) == 0) {
  70. return 0;
  71. }
  72. }
  73.  
  74. if($dir ne 'D') {
  75. if(solve_maze($way.'U',$x,$y-10) == 0) {
  76. return 0;
  77. }
  78. }
  79. return 1;
  80. } else {
  81. print "Ende?!\n";
  82. print "Way: $way\n";
  83. print $response->content."\n";
  84. return 0;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement