Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Space Invaders

by domm (Chaplain)
on May 26, 2002 at 22:12 UTC ( [id://169437]=obfuscated: print w/replies, xml ) Need Help??

An old classic, ideal to waste some time with (either playing or deobfuscating ...)

#!/usr/bin/perl use strict; use Term'ReadKey;ReadMode 'cbreak';$,=$/;$/=++$b+$b;$=='8';$b=$= x28;$*=$=x2;@!=(qw(4 _ " a 1 1 0 0 ));$![7]=`clear` ;push(@!,split shift(@!),q 7$=W8W$=8$b eq "j"8W$=8$=W8 $b eq "l"8W$=8W!8($b eq"k"&&$_!~/!/)a#W$=8#$=W8$=W#8W$=#8#!8##a\*8 $=8p$=8$=p 8$=q8q$=8p(#.{59})$=8$=$ 1q8#q(.{60 })$=8#$=$1 pap(.{60})!8$![0]++;"\*$ 1$="8q(.{6 0})!8$![0] ++;"\*$1$="8(t.*)!8$b=(l ength$1)-6 1;substr($ 1,0,$b )."!". substr($1, $b+1).$=4x "gs'"x"c"es'"c"z"gs if'.shift"z"l"just another perl hacker"l 4'SpaceInvaders'.($=x12).'domm@zsi.at j=left k=fire l=right' _'#'x58_("$*p$*"x11).$=x3_$*.("$*$*q"x11).$=_("p$*$*"x11).$= x3_($=x3).("$*$*q"x11)_1_$b.$=."W$b"_'#'x 587);j(split shift @!,pop@!);a(split shift@!,pop@!);push(@!,split shift@!,pop@! );$_=$a;map{s/\n//g}@!;map{s/v//g}@!;map{s/ //g}@!;&p;sub'j {$_=shift;$a.=m/^1/?("#$b$=$=$b#$,"x12):"#".eval( )."#$,";@_ &&j(@_)}sub'END{ReadMode 'normal' }sub'a{eval"sub'".pop().'{ eval\'s/\'.(shift).\'/\'.(shift).\'/'.pop().';@_&&'.pop().'( @_)}';@_&&a(@_)}sub'p{$b=ReadKey -1;$![1]%3==0&&x(split$=,$! [6]);z(split$=,$![4]);x(split$=,$![5]);c(split$=,$![7]);$![1 ]++;select+(@-,@-,@-,0.05);($![2]=$_)=~s/$=/ /g;/pW|Wq/&&h(' Game over');$_!~/p|q/&&h('You saved our planet. Yeah');print $![3],$![2 ];&p}sub h{print $![ 3],shift," You killed $![0] space invaders ",$,;exit}
Notes
  • If you have problems with copy&pasting the code, download it from here
  • Term::ReadKey is required, as I was to lazy to implement its functionality myself
  • There might be some problems with the refresh rate, depending on your hard/software. You could try different values, shouldn't be too hard to find in the code.
  • There are no IFs, WHILEs or FORs - as thedamian once said, control structures are for whimps!
  • In fact, most of the functions used are array manipulating stuff and regexes (and one or two (three, in fact) evals, of course)
I'll post a solution later this week...

UPDATE: Here is the solution.

--
#!/usr/bin/perl -w just another perl hacker
print+seek(DATA,$=*.3,@-)?~~<DATA>:$:__DATA__

Replies are listed 'Best First'.
Re: Space Invaders
by rob_au (Abbot) on May 27, 2002 at 00:03 UTC
    Excellent work domm++ To my mind though the shape of the code looks more like one of the ghosts from Pacman :-)

     

      To my mind though the shape of the code looks more like one of the ghosts from Pacman

      That's intentional and just another level of obfuscation:

      Code that looks like Pacman, but is in fact Space Invaders ...

      Maybe I should't have given it away in the title of the node, but then...

      --
      #!/usr/bin/perl -w just another perl hacker
      print+seek(DATA,$=*.3,@-)?~~<DATA>:$:__DATA__
      
Re: Space Invaders
by Jasper (Chaplain) on May 27, 2002 at 13:00 UTC
    # There are no IFs, WHILEs or FORs -

    Errr...? I can't spot any whiles, or fors, but...

    Or am I being stupid? (as usual)
      Damn, your right. There is one if. I'll try to remove it...
      --
      #!/usr/bin/perl -w just another perl hacker
      print+seek(DATA,$=*.3,@-)?~~<DATA>:$:__DATA__
      
Re: Space Invaders
by IndyZ (Friar) on May 29, 2002 at 01:21 UTC
    ++. Just one complaint: It doesn't end if you kill everything!

    --
    IndyZ
        Oh, it,s not that hard to get them all...
        --
        #!/usr/bin/perl -w just another perl hacker
        print+seek(DATA,$=*.3,@-)?~~<DATA>:$:__DATA__
        
      I noticed this too (after posting ..)

      Sorry for that, but it was working before I formated the code into the Pacman-Ghost-ASCII-art.

      I'll update the code soon (together with a Spoiler..)

      --
      #!/usr/bin/perl -w just another perl hacker
      print+seek(DATA,$=*.3,@-)?~~<DATA>:$:__DATA__
      
Re: Space Invaders
by Courage (Parson) on Jun 12, 2002 at 13:30 UTC
    Unfortunately it does not run on my Win2000, perl5.6.1, compiled by ActiveState
    There were chars running all over the console window, but nohing that could be seen and played...

    Fortunately enough, it *does* run on the same OS on Cygwin perl, so I had a chance to play it :)

    domm++

    Courage, the Cowardly Dog.
    PS. Something fishy is going on there, or my name is Vadim Konovalov. And it's not.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://169437]
Approved by jeffa
Front-paged by jeffa
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found