Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Perl plays Pong!

by cfreak (Chaplain)
on Jan 24, 2004 at 07:23 UTC ( #323798=obfuscated: print w/ replies, xml ) Need Help??

Okay so I'm a geek and I spend my Friday night writing a Perl obfu rather than going out. But hey my wife thought it was cool (which probably just means she's a geek too :) ).

This could be more obscure but I think its at least non-obvious the way it is. Will work on a standard size terminal window. *Should* work on Windows but I don't have a box in which to test that theory. Needs Time::HiRes. I did it at first without but it just wasn't as cool. Anyway, here it is:

#!/usr/bin/perl use Time::HiRes qw(usleep); $@='Just Another Perl Hacker';$@=length($@); $|=abs(2-$@);goto f;z:if(int(rand(10))>5){($- ,$.)=($",$;);}else{($-,$.)=($",$;);}@b =();$b [0] = $-;if($- ==$;){$b[1]=1;}else{$b[1]=7 + 50 + 10 + (5 * 2);}$,='l';$,='r'if$-==$";$vd ='u';$vd='d'if int(rand(10))<5;while($|){my $s="";foreach $%(0 .. 22){foreach$=(0 .. 78) {if($===39){$s.="|";}if($%==$;&& $===0){$s.= "]";}elsif($===$b[1]&& $%==$b[0]){$s.= "*";} elsif($===78&& $%==$"){$s.="[\n";}elsif($=== 78){$s.=" \n";}else{$s.=" ";}}}print $s;#### $b[1]==1 and$,='r';$b[1]==77 and$,='l';$b[0] == 23 and$vd='u';$b[0]==0 and$vd='d';if($,eq 'r'){$b[1]++;$mp=\$";}if($, eq'l'){$b[1]--;# $mp=\$;;}if($vd eq'u'){$b[0]--;$$mp-- unless $$mp==0;}if($vd eq'd'){$b[0]++;$$mp++ unless $$mp == 22;}usleep(50_000);system($^);}f:$^= 'clear';$"=int(rand(22));$;=int(rand(22));$^ ='cls'if$^O=~m|win|i;goto z;################

Suggestions welcome!

Update: Took out the need for Time::HiRes as suggested by BrowserUk

#!/usr/bin/perl $@='Just Another Perl Hacker';$@=length($@); $|=abs(2-$@);goto f;z:if(int(rand(10))>5){($- ,$.)=($",$;);}else{($-,$.)=($",$;);}@b =();$b [0] = $-;if($- ==$;){$b[1]=1;}else{$b[1]=7 + 50 + 10 + (5 * 2);}$,='l';$,='r'if$-==$";$vd ='u';$vd='d'if int(rand(10))<5;while($|){my $s="";foreach $%(0 .. 22){foreach$=(0 .. 78) {if($===39){$s.="|";}if($%==$;&& $===0){$s.= "]";}elsif($===$b[1]&& $%==$b[0]){$s.= "*";} elsif($===78&& $%==$"){$s.="[\n";}elsif($=== 78){$s.=" \n";}else{$s.=" ";}}}print $s;#### $b[1]==1 and$,='r';$b[1]==77 and$,='l';$b[0] == 23 and$vd='u';$b[0]==0 and$vd='d';if($,eq 'r'){$b[1]++;$mp=\$";}if($, eq'l'){$b[1]--;# $mp=\$;;}if($vd eq'u'){$b[0]--;$$mp-- unless $$mp==0;}if($vd eq'd'){$b[0]++;$$mp++ unless $$mp == 22;}select $`,$`,$`,.05;system($^);} f:$^='clear';$"=int(rand(22));$;=int(rand(22 ));$^='cls'if$^O=~m|win|i;goto z;###########

Comment on Perl plays Pong!
Select or Download Code
Re: Perl plays Pong!
by duff (Vicar) on Jan 24, 2004 at 08:07 UTC

    Cool. Yep it works on windows, but I had to resize my window for it to make sense.

Re: Perl plays Pong!
by BrowserUk (Pope) on Jan 24, 2004 at 09:43 UTC
Re: Perl plays Pong!
by CountZero (Bishop) on Jan 24, 2004 at 22:33 UTC
    Wonderful!

    But the players never miss.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Perl plays Pong!
by jbware (Chaplain) on Jan 25, 2004 at 01:20 UTC
    Very Cool++ And I didn't know there was something better to do on a Friday night :)

    - jbWare
Re: Perl plays Pong!
by ysth (Canon) on Jan 25, 2004 at 06:30 UTC
    Can't exec "cls": No such file or directory at pong.pl line 18.
    $ perl -we'print $^O' cygwin

      This should fix it (untested)

      #!/usr/bin/perl $@='Just Another Perl Hacker';$@=length($@); $|=abs(2-$@);goto f;z:if(int(rand(10))>5){($- ,$.)=($",$;);}else{($-,$.)=($",$;);}@b =();$b [0] = $-;if($- ==$;){$b[1]=1;}else{$b[1]=7 + 50 + 10 + (5 * 2);}$,='l';$,='r'if$-==$";$vd ='u';$vd='d'if int(rand(10))<5;while($|){my $s="";foreach $%(0 .. 22){foreach$=(0 .. 78) {if($===39){$s.="|";}if($%==$;&& $===0){$s.= "]";}elsif($===$b[1]&& $%==$b[0]){$s.= "*";} elsif($===78&& $%==$"){$s.="[\n";}elsif($=== 78){$s.=" \n";}else{$s.=" ";}}}print $s;#### $b[1]==1 and$,='r';$b[1]==77 and$,='l';$b[0] == 23 and$vd='u';$b[0]==0 and$vd='d';if($,eq 'r'){$b[1]++;$mp=\$";}if($, eq'l'){$b[1]--;# $mp=\$;;}if($vd eq'u'){$b[0]--;$$mp-- unless $$mp==0;}if($vd eq'd'){$b[0]++;$$mp++ unless $$mp == 22;}select $`,$`,$`,.05;system($^);} f:$^='clear';$"=int(rand(22));$;=int(rand(22 ));$^='cls'if$^O=~m|(?!cyg)win|i;goto z;####
      Lobster Aliens Are attacking the world!
        You need (?<!cyg)win. What you have matches three characters that are "win" and aren't "cyg" :)
        One would usually just search for Win32.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-12-27 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls