Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Tic tac toe

by Jeff Connelly (Acolyte)
on Aug 17, 2000 at 10:57 UTC ( [id://28276]=obfuscated: print w/replies, xml ) Need Help??

295 characters. Can anyone come up with a shorter one?
$_="- - -\n"x3; $"=o;W:while($"=($"eq x?o:x)){$i=0;$O=$_;$O =~s/-/$i++/ge;print$O.$";$H=<>;$w=0;s/-/$w++==$H?$":$&/egs ;$B=$_;for$P(o,x){s/$P{3}/$&/;s/($P . .\n){3}/$&/; s/(. $P .\n){3}/$&/;s/(. . $P\n){3}/$&/; s/$P . .\n. $P .\n. . $P/$&/;s/. . $P\n. $P .\n$P . ./$&/; last(W)if$&=~m/o|x/}$_=$B}print

Replies are listed 'Best First'.
Re: Tic tac toe
by delirium (Chaplain) on Jun 04, 2004 at 13:57 UTC
    Can anyone come up with a shorter one?
    Only 4 years late, but yes:
    @r=(123,456,789,147,258,369,159,357);$,=$/;$p=X; sub d{print@r[0..2],$p;die$_[0]if@_} n:d;$m=<>until grep$m=~/\d/&&s/$&/$p/,@r; d"Tie"if!map/\d/,@r;d$p if map/$p{3}/,@r; $p=~tr/XO/OX/;goto n
    190 characters.
RE: Tic tac toe
by ChuckularOne (Prior) on Aug 17, 2000 at 21:46 UTC
    Way cool! The cntl-C works fine for me as an exit! I can tell when there's been a winner ;) even on the occasions the program doesn't notice.

    Your Humble Servant,
    -Chuck
RE: Tic tac toe
by BigJoe (Curate) on Aug 17, 2000 at 16:36 UTC
    Pretty slick but there is no way to exit.

    --BigJoe

    Learn patience, you must.
    Young PerlMonk, craves Not these things.
    Use the source Luke.
      It exits when one of the players wins.

      Slick piece of code BTW.

      /\/\averick

        Tried that and it didn't exit. i had 3 accross the middle just playing. Then I went and filled every one and it still didn't let me out.

        --BigJoe

        Learn patience, you must.
        Young PerlMonk, craves Not these things.
        Use the source Luke.
Re: Tic tac toe
by vek (Prior) on Jul 05, 2003 at 13:56 UTC

    Extremely late to the party but I had to comment. Very slick, nice job :-)

    -- vek --

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2025-03-24 00:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (63 votes). Check out past polls.